Programming

Sqlite with C++

This blog post outlines how simple it is to interface with the sqlite3 database platform in a type and memory-safe way using features in modern C++. In order to complie this code, you will need a compiler that supports at least some new features of C++17. Namely: the ability for the compiler to deduce template arguments from constructors. If you want to play with C++17, I suggest grabbing a pre-release snapshot of your favourite compiler.

Parsing JSON With Perl 6

Aside from my usual meanderings about in C++ land I’ve been playing with Perl 6. I used to use Perl 5 back in the day, so I’m not totally lost when it comes to sprinkling sigils around everywhere in my code. From first impressions, however, Perl 6 really does feel like a much cleaner, more consistent language than its older sister. It’s raining tonight in Windsor, Ontario (across from Detroit, Michigan for those of you who don’t know your Canadian geography), and I thought it would be a nice evening to build a program that interfaces with the Weather Underground Developer API.

Creating New Blog Posts in Emacs

I use the Emacs thermonuclear word processor for everything in my life that has to do with editing text. It’s extensibility is unmatched by any other editor out there; if there’s a feature missing that would make your life easier, then pop open the hood and add it! While it’s not the prettiest language to work with, Emacs Lisp (or elisp) is a pretty straight forward, yet deeply powerful extension language.

Simulating Coin Flips in C++

Occasionally I have to generate random numbers in C++, and since C++11 was published the langauge now has a massively powerful, flexible library for generating quality random numbers. The only issue is that for the life of me I cannot remember the API. This would probably not be a problem if I used it more frequently, but anyways, this blog post is a reminder for me of how to generate a uniform distribution.

Batch File Renaming The Lazy Way

When I first converted my blog over to hugo from hakyll, I neglected to put the date published onto the front of the blog posts file names. This resulted in URLs that were slightly less descriptive than desired, and also made it harder to scan through the markdown files quickly. Luckily in each file is a header, and within each header is a date field. Therefore, with my rusty old bash trickery I was able to spit out the following one-liner to do the job of renaming all the files.

C++ Friends, Templates, and Friends of Templates

This post is mostly to keep my own memory fresh. It’s been a while since I’ve written any hard-core C++ code, especially code that uses the language to its fullest potential. Let’s assume for some strange reason that you have a class template within another class template. In other words, consider the following code: template <typename T> class outer { int x = 0; public: template <typename U> struct inner { void foo(outer<U> const& o) const { cout << o.

Hugo: Only Show Content Under a Given Section

One thing I initially found strange of Hugo was that it listed every piece of content on the front page - as if they were all blog posts. Luckily Hugo is flexible enough to change that behaviour without having to do any hacking. This blog post is mostly so that I remember how to do this in the future. To limit your front page to show only content from a certain sub-directory, say, “post”, edit your index.

Programming Outdoors

As a software professional, I spend a lot of time indoors. It’s really not so bad: I have a nice comfy chair, ample desk space, and the office is always nice and air conditioned :-) But the past few days have been so beautiful here in Windsor that I’ve been taking my coffee and laptop outside to read the morning news and catch up on email. It makes me remember the good old days when I was working to pay for my undergraduate.

Playing Around With Racket

Lately I’ve been playing around with the racket dialect of lisp. Racket is a language of the scheme family, and so far I’ve found it simple enough to pick up through the provided tutorials. Things I like about it are Simple syntax. It is a lisp, after all, so there are plenty of parentheses. One thing racket does, however, is treat all brackets: (, [, and {, the same. As long as they are balanced by the appropriate closing bracket, they are interchangeable.

Playing With Bootstrap

You may have noticed that the appearance of my website has changed, starting yesterday. This is because I wanted to find an excuse to mess around with bootstrap, an excellent package of javascript and css for making front-end website design easy. For the time being I’m sticking with one of the sample layouts, but I plan to play around with it in the future, so expect to see some changes!

A Basic Monte-Carlo Simulation in Common Lisp

Monte-Carlo simulations are algorithms that approximate numerical results by repeatedly sampling some space. Generally, the more samples you collect, the higher the accuracy of the result. In this blog post I am going to demonstrate how to use such a technique to approximate the value of the mathematical constant pi. The high level idea is as follows. We know the area of a circle can be found using the formula A = pi * r ^ 2, where r is the radius of the circle.

An example anaphoric macro in Common Lisp

Anaphoric macros are macros that capture symbols intentionally, only to refer to them by a different name (an apaphor is an expression referring to another.) A popular example in Common Lisp is the loop macro, which uses the symbol “it” to refer to certain things in different contexts. Here’s an example from wikipedia: (loop for element in '(nil 1 nil 2 nil nil 3 4 6) when element sum it) As another example, here we will introduce a special version of the built-in “lambda” special form, that introduces a symbol “self” that refers to the lambda being defined.

What the heck is C/C++?

I see this all the time in programming forums, websites, etc. My one question is: What the heck language is C\/C++? C and C++ are distinct languages that have a similar looking syntax (the same goes for Java, C#, JavaScript, Perl, etc.) And just like the languages I\’ve mentioned in parenthesis, C and C++ also have many syntactic differences. So if they don\’t have the same syntax, there must be another reason why people conjoin the two languages…

b