Making documents with makefiles
John D. Cook Consulting Blog
by John
22h ago
I learned to use the command line utility make in the context of building C programs. The program make reads an input file to tell it how to make things. To make a C program, you compile the source files into object files, then link the object files together. You can tell make what depends on what, so it will not do any unnecessary work. If you tell it that a file foo.o depends on a file foo.c, then it will rebuild foo.o if that file is older than the file foo.c that it depends on. Looking at file timestamps allows make to save time by not doing unnecessary work. It also makes it easier to dic ..read more
Visit website
Applied abstraction
John D. Cook Consulting Blog
by John
22h ago
“Good general theory does not search for the maximum generality, but for the right generality.” — Saunders Mac Lane   One of the benefits of a scripting language like Python is that it gives you generalizations for free. For example, take the function sorted. If you give it a list of integers, it will return a list of numerically sorted integers. But you could also give it a list of strings, and it will return a list of alphabetically sorted strings. In fact, you can give it more general collections of more general things. The user gets generality for free: more functionality without comp ..read more
Visit website
Fizz buzz walk
John D. Cook Consulting Blog
by John
6d ago
I ran across a graphic yesterday made by taking a sequence of steps of the same length, turning left on the nth step if n is prime, and otherwise continuing in the same direction. Here’s my recreation of the first 1000 steps: You can see that in general it makes a lot of turns at first and then turns less often as the density of primes thins out. I wondered what the analogous walk would look like for Fizz Buzz. There are several variations on Fizz Buzz, and the one that produced the most interesting visualization was to turn left when a number either is divisible by 7 or contains the digit 7 ..read more
Visit website
Closed-form solutions to nonlinear PDEs
John D. Cook Consulting Blog
by John
1w ago
The traditional approach to teaching differential equations is to present a collection of techniques for finding closed-form solutions to ordinary differential equations (ODEs). These techniques seem completely unrelated [1] and have arcane names such as integrating factors, exact equations, variation of parameters, etc. Students may reasonably come away from an introductory course with the false impression that it is common for ODEs to have closed-form solutions because it is common in the class. My education reacted against this. We were told from the beginning that differential equations ra ..read more
Visit website
Choosing a Computer Language for a Project
John D. Cook Consulting Blog
by Wayne Joubert
1w ago
Julia. Scala. Lua. TypeScript. Haskell. Go. Dart. Various computer languages new and old are sometimes proposed as better alternatives to mainstream languages. But compared to mainstream choices like Python, C, C++ and Java (cf. Tiobe Index)—are they worth using? Certainly it depends a lot on the planned use: is it a one-off small project, or a large industrial-scale software application? Yet even a one-off project can quickly grow to production-scale, with accompanying growing pains. Startups sometimes face a growth crisis when the nascent code base becomes unwieldy and must be refactored or ..read more
Visit website
On greedy algorithms and rodeo clowns
John D. Cook Consulting Blog
by John
1w ago
This weekend I ran across a blog post The Rodeo Clown Theory of Personal Development. The title comes from a hypothetical example of a goal you don’t know how to achieve: becoming a rodeo clown. Let’s say you decide you want to be a rodeo clown. And let’s say you’re me and you have no idea how to be a rodeo clown. … Can you look at the possibilities currently available to you and imagine which of them might lead to an overall increase of rodeo clowndom in your life, even infinitesimally? Each day you ask yourself what you can do that might lead you closer to your goal. This is a greedy algo ..read more
Visit website
Finding strings in binary files
John D. Cook Consulting Blog
by John
2w ago
There’s a little program called strings that searches for what appear to be strings inside binary file. I’ll refer to it as strings(1) to distinguish the program name from the common English word strings. [1] What does strings(1) consider to be a string? By default it is a sequence of four or more bytes that correspond to printable ASCII strings. There are command options to change the sequence length and the character encoding. There are 98 printable ASCII characters [2] and 256 possible values for an 8-bit byte, so the probability of a byte being a printable character is p = 98/256 = 0.38281 ..read more
Visit website
Extract text from a PDF
John D. Cook Consulting Blog
by John
2w ago
Arshad Khan left a comment on my post on the less and more utilities saying “on ubuntu if I do less on a pdf file, it shows me the text contents of the pdf.” Apparently this is an undocumented feature of GNU less. It works, but I don’t see anything about it in the man page documentation [1]. Not all versions of less do this. On my Mac, less applied to a PDF gives a warning saying “… may be a binary file. See it anyway?” If you insist, it will dump gibberish to the command line. A more portable way to extract text from a PDF would be to use something like the pypdf Python module: from pypd ..read more
Visit website
Length of a general Archimedean spiral
John D. Cook Consulting Blog
by John
2w ago
This post ties together the previous three posts. In this post, I said that an Archimedean spiral has the polar equation r = b θ1/n and applied this here to rolls of carpet. When n = 1, the length of the spiral for θ running from 0 to T is approximately ½ bT² with the approximation becoming more accurate [1] as T increases. In this post we want to look at the general case where n might not be 1. In that case the arc length is given by a hypergeometric function, and finding the asymptotic behavior for large T requires evaluating a hypergeometric function at a large argument. Here’s an example w ..read more
Visit website
How big will a carpet be when you roll or unroll it?
John D. Cook Consulting Blog
by John
2w ago
If you know the dimensions of a carpet, what will the dimensions be when you roll it up into a cylinder? If you know the dimensions of a rolled-up carpet, what will the dimensions be when you unroll it? This post answers both questions. Flexible carpet: solid cylinder The edge of a rolled-up carpet can be described as an Archimedian spiral. In polar coordinates, this spiral has the equation r = hθ / 2π where h is the thickness of the carpet. The previous post gave an exact formula for the length L of the spiral, given the maximum value of θ which we denoted T. It also gave a simple approximat ..read more
Visit website

Follow John D. Cook Consulting Blog on FeedSpot

Continue with Google
Continue with Apple
OR