MySQL CLI

Typically, you would use mysql client cli as follows, You could also create a ~/.my.cnf file to set default properties, including connection info, You could even store a password but I wouldn’t recommend storing it in the clear. Also, the above approach is not useful when you have more than one MySQL database across multiple hosts, […]

FP Error Handling

I would like to handle errors in pure FP (functional programming), something more idiomatic and easier to read than nested try/catch blocks. Let’s say we have the following procedure, This is pretty straightforward. Given a list of numbers (represented as strings), compute the areas of these as circles, and then divide by a common divisor […]

How to Find a Job as a Software Engineer

Software Engineering as changed a lot since the 1990s: we’ve seen the rise of the Internet, smartphones, machine learning, and a golden age of programming languages. Yet despite the technological advances, the actual process of finding a well-paying job as a software engineer hasn’t changed much. The buzzwords have changed, the amount of money has […]

Extremely Large Numeric Bases with Unicode

Previously, we discussed using Punycode for non-ASCII domain names with internationalized URLs, e.g., https://去.cc/叼 I would like to use this approach to create a URL Shortening Service, where we can create shortened URLs that use UTF-8 characters in addition to the normal ASCII characters. Most URL shortening services use a base-62 alphanumeric key to map […]

PseudoForm, a Bot-resistant Web Form

I would like to create an HTML form that is resistant to bots. This could be a classic comment form or really any web-accessible form. In most cases, requiring authentication and an authorization service (such as OAuth) would be sufficient to protect a back-end web service. But what if you have a publicly accessible web […]

multiple git remotes

I would like to manage a project across multiple remote git repositories, specifically, a public github repository and my own private repositories. Fortunately, git supports as many remote repositories as you need. When you clone a repository, there will be a default remote called “origin”, i.e., Adding additional remotes is trivial, i.e., Now, when we […]

OOP or Procedural?

I would like to know when it is best to use object-oriented programming, and when it is best to use procedural programming. tl;dr: neither, go with functional programming By procedural programming, I mean the kind of code you’d find programming in C; imperative control flow, functions, data structures, and algorithms. For example, And by object-oriented […]

Trie or Set

Given a grid or input stream of characters, I would like to discover all words according to a given dictionary. This could be a dictionary of all English words or phrases (say, for an autocomplete service), or for any language. This is especially useful for languages where words are not clearly separated (e.g., Japanese, Chinese, […]

iter_words

I would like to iterate over a stream of words, say, from STDIN or a file (or any random input stream). Typically, this is done like this, And then one can simply, For a more concrete example, let’s say we need to keep a count of every unique word in an input stream, something like […]

Punycode

I would like a webapp that supports UTF-8 URLs. For example, https://去.cc/叼, where both the path and the server name contain non-ASCII characters. The path /叼 can be handled easily with %-encodings, e.g., Note: this is similar to the raw byte representation of the unicode string: However, the domain name, “去.cc” cannot be usefully %-encoded […]

Using getattr in Python

I would like to execute a named function on a python object by variable name. For example, let’s say I’m reading in input that looks something like this: enqueue 1 enqueue 12 enqueue 5 enqueue 9 sort reverse dequeue print Afterwards, we should see: [9,5,1] Let’s say we need to implement a data structure that […]

Graph Search

I would like to discover paths between two nodes on a graph. Let’s say we have a graph that looks something like this: The graph object contains a collection of nodes and their corresponding connections. If it’s a bi-directional graph, those connections would have to appear in the corresponding sets (e.g., 1: set([2]) and 2: […]

python unittest

I would like to setup unit tests for a python application. There are many ways to do this, including doctest and unittest, as well as 3rd-party frameworks that leverage python’s unittest, such as pytest and nose. I found the plain-old unittest framework to be the easiest to work with, although I often run into questions […]

HTML + CSS + JavaScript Lessons

I would like a very simple introduction to web development, from the basics of HTML and CSS, to the proper use of JavaScript; and all without getting bogged down in complicated textbooks. I’ve been working with HTML, CSS, and JavaScript (as well as dozens of programming languages in more environments than I can remember) for […]