Leanpub Header

Skip to main content

Chastity's Code Cookbook

Computer Programming Recipes for Technical Math Nerds

I am a programmer who knows clever tricks

I convert integers to bases two to thirty six

By using character arrays as strings

I can show you amazing math things

While others talk about politics and sports

I read about computers of all sorts

Programming languages are all the same

When you see arithmetic as a game

I don’t write code for a job to be paid

But to understand the video games I played

To see what works and find out why

To create, use, study, share, and modify

Minimum price

$5.00

$10.00

You pay

$10.00

Author earns

$8.00
$

...Or Buy With Credits!

You can get credits with a paid monthly or annual Reader Membership, or you can buy them here.
PDF
EPUB
WEB
About

About

About the Book

This book teaches how computers actually work using small programs written in the C language, exploring numbers, overflow, primes, and algorithms through hands-on experimentation.


You would not know it by looking at me, but I have been computer programming as a hobby since I was 14 years old. My first programming language was QBASIC. It was a language and a program for interpreting that language that ran on MS-DOS. However, the usage of this language has diminished over time because it does not run without an emulator or modern BASIC language dialects meant to mimic it.


However, I moved to the C Programming Language as my main computer language. I have dabbled in Java, JavaScript, Lua, Perl, Python, and the beast known as C++. However, of all these languages, C remains my native language because of how simple it is to remember. In spite of its quirks, C is what I recommend to a beginner, not in spite of its limitations but because of them! Therefore, most of the recipes in this code cookbook will be in the form of C source code.


But this book will contain more than just the C language. There are times when other languages, such as Bash, HTML, Markdown, and maybe even Lua or Python, will just make a lot more sense in the context of what is being done.


For example, computer programming is used to create art, web pages, books, and video games. However, programming is also hard work and a lonely pursuit because almost nobody understands it except those of us who are called to this sacrificial art of communicating with a computer.


I got my start in the world of computer programming because I first loved numbers. I am the stereotype of an autistic savant who sees everything as a number. If you like numbers, my hope is that my recipes for generating number patterns will be of some use to you.


And if you don't like numbers, then you probably won't do well as a computer programmer because everything is a number in the context of a computer. The size, shape, and color of every text or picture element in the video games you play were, at one point, written into the code by one or more programmers who probably were not paid enough for the work that went into their craft!


This book is meant to be used as an introduction to programming for people who like arithmetic and numbers in general. No prior programming experience is necessary, but it certainly helps. I have included instructions on how to install a C compiler and get started writing small programs.


Other than that, this book can be used as a reference book for how to achieve things using a specific programming language. I frequently refer to it when I forget how I implemented an algorithm. For example, my "Powers of Two" program and my "Prime Finder" are programs that date back as far as my teenage years. These were my introduction to the joy of computer programming. Maybe they can be yours too!


Author

About the Author

Chastity White Rose

Chastity White Rose is an author of over twelve books and two WordPress blogs. She writes humorous and educational content about philosophical and religious topics. She also uses her writing and graphic design skills to teach people about the game of Chess. She is earning an associate’s degree in creative writing at Full Sail University. As a transgender Christian woman, she writes books and blog posts to help others like her process the seeming disconnect between religious faith and an LGBTQIA+ identity. She measures the success of her writing by its emotional impact rather than its sales. For this reason, most of her writing is available free of charge.

Contents

Table of Contents

Chastity’s Code Cookbook

Preface

Introduction

  1. How it works

Chapter 1: Integer Sequences

  1. Count 100
  2. The Powers of 2
  3. Advanced Powers of 2
  4. The Prime Numbers
  5. Conclusion

Chapter 2: Graphics

  1. SVG Checkerboard
  2. Portable Bitmap Checkerboard
  3. Converting the Image File
  4. Graphics Fundamentals
  5. SDL Square Target

Chapter 3: Back to Binary Basics

  1. Binary to Decimal Counting 4 Bits
  2. Left Shift Example
  3. Binary Age Example
  4. Why is Binary Used?
  5. The Bitwise Operations
  6. Learning More

Chapter 4: Animation with SDL

  1. Animation SDL Square Target
  2. Game: Checkerboard Explorer
  3. Animation Polygon Target

Chapter 5: Development Environment

  1. Tool 1: C Compiler
  2. Tool 2: Simple DirectMedia Layer
  3. Tool 3: A Text Editor
  4. Installing Development Tools on Linux
  5. Installing Development Tools on Windows
  6. Notes About SDL Versions
  7. Recommended Versions
  8. SDL Version 2 on Windows

Chapter 6: Bash Scripting

  1. Bash Count Script
  2. Bash Powers of 2
  3. Bash Prime Finder
  4. Using Bash to build a Website
  5. Bash References

Chapter 7: Web Development

  1. Web Page Example
  2. Reverse Colors Web Page Example
  3. Square Numbers Demo 1
  4. Square Numbers Demo 2
  5. Code in the “head” vs the “body”
  6. Chastity’s JavaScript Checkerboard

Chapter 8: Big Numbers

  1. Big Number Powers of Two
  2. The Negative Powers of Two
  3. Fibonacci Sequence
  4. Factorials

Chapter 9: Assembly Language

  1. Linux Example
  2. Windows Example
  3. DOS Example

Chapter 10: Software Licenses

  1. GNU GENERAL PUBLIC LICENSE Version 3
  2. GNU Lesser General Public License Version 3
  3. Free vs. Proprietary

Chapter 11: The Prayer of Saint Chastity

Chapter 12: Why are There so Many Programming Languages?

  1. C and C++
  2. Why Learn Assembly?
  3. Just Kidding!

Chapter 13: The War I can Win

Chapter 14: Gratis versus Libre

  1. Gratis
  2. Libre
  3. Conclusion

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub