Esoteric programming languages are awesome. So I decided to create one, which I call BlarbLang.

The goal of this language is to be the simplest possible systems programming language. It uses a stack for parameters, and every function must destruct its own stack frame, and push a return value, manually. The language “doesn’t care” about performance, only simplicity. It currently supports only 5 operations:

  • a b ~ Store the value of a in register b
  • a $ Push register a onto the stack
  • b a ! NANDS index a with index b and stores the result in index b
  • a ^ pop ‘a’ elements
  • a ? if index a is true (non-zero), execute the rest of the line

In one of my CS lectures (CSC258) I remembered learning that every gate can be created using NAND gates, so that is the only type of logical operation in the language! Using the above 5 operations, tons of different operations can be created, including adders, shifters, comparison operators, and more.

There are 8 registers available for users. The 0th register is the line pointer, registers 1-3 are temporary registers (for swapping and stuff), and the 4-7 registers are “long term” registers, meant to be used outside of the standard library (by the user).

Labels allow creation of functions. For instance, the following code creates a function called “nandi” which NANDs two immediate stack values:

In the future, I want to add one more operation: the system call operation. Currently, the language can only modify data within the VM. That is, on the stack and in registers. However, using system calls, users will be able to allocate heap memory and perform useful tasks such as reading from STDIN and writing to STDOUT.

GDB Basics: Stack Traces

C beginners are often very lost when their program crashes from a segmentation fault or similar issues. Most of them know about GDB but are pretty intimidated by it.

Here is a super simple example about how to find a stack trace from a program crash.

Of course, this will result in the console simply printing “Segmentation Fault” which doesn’t help very much, especially in more complex programs.

Using GDB, you just have to remember 2 commands to get a stack trace: “run” and “backtrace”.

To compile, use the “-g” flag with gcc to include debugging symbols for gdb:

To run this in gdb, run:

Now all you have to do is type “run” into the gdb console. It will show you the line where it crashed, but to show the stack trace you must run the “backtrace” command:

GDB has a lot of other great features like breakpoints and memory analysis. If you are comfortable with assembly, you can even run commands while your program is running!

How to change login shell without chsh permissions

On the University of Toronto servers and Linux lab computers, the default shell is tcsh, and we don’t have chsh access *shakes fist*.

If you are in a similar circumstance, plop this in ~/.cshrc:

If you just run exec /bin/bash (without checking for the interactive shell), it will break non-interactive shells like scp and the GNOME startup scripts. If you just use bash you can ignore the first conditional. The reason why I have bash as a backup is because the lab computers have zsh installed, but the servers only have bash.

Bai 🙂

P.S. A little known fact about the UofT computing services is that you can SSH into lab computers directly. For instance, connects to “PC #02” in DH2026.

UofT Hacks 2016

So last weekend, I spent 36 hours at UofT for their annual hackathon. If you have not been to a hackathon, I highly recommend it! There are tons of like minded individuals making awesome projects.

Check out the swag I collected:


I even got a new domain name for free: Yes, SquabbitTech is our “company” name :3

The application my team built was a super-fuzzy note searching tool called Fuzzy Wuzzy. The idea is, several years after writing down notes, it is very difficult to remember exactly what you wrote. So we built an application that guesses what you want to search for. We designed three algorithms, but only had time to implement two of them: synonym, misspelled word, and idea group matchers. For instance, searching for “small” will return notes containing the word “tiny”. We didn’t have time to create the idea group algorithm, but we had it planned out. If you search for “car”, everything that is a car will be matched (e.g. “Honda Civic”).

We built the project as an API using Flask – a micro web framework for Python. It is extremely simple in comparison to other frameworks like Symfony. It provides templating, routing, and database engines that are all super easy to get started with.

Dabbling Around with Scala

Scala is a legendary language that allows both OO and functional programming. On top of that, it is compatible with Java and compiles to JVM bytecode. Hence, in theory, it could be used anywhere Java is used *cough cough* Android *cough cough*.

For a while, I have been meaning to try out Scala – and today I bit the bullet.

Closures are awesome. Here is a simple example which multiplies a list by 2 and prints the result:

Of course, this is a very trivial example of how closures can be used, but I find the syntax pretty cool nonetheless 😀

Here are some other features that I really like about Scala:

Just for kicks, I decided to build a simple regex matching program with character matching, “multiple”, and “or” functionality.

Switching from Arch to Debian

Last night was a sad night. After 5 years of using Arch Linux, I decided to leave it for Debian. While I learnt a lot while using Arch, it was often disruptive to my work when it required maintenance. I woke up last night to work on a Physics assignment, and sure enough, my kernel panicked. I don’t blame Arch per se. If I retained a legacy kernel, it would have been fine. But that is the reason why I left – it would be nice if my computer worked out of the box with minimal maintenance.

One thing I will really miss about Arch is yaourt – a package manager which connects with the Arch User Repository. Basically any package you could think of would be contained in there. As an alternative, I installed Linuxbrew. It doesn’t seem to have as many packages, but I am really digging how the formulae are easily modifiable in ruby! (expect to see a linuxbrew-formulae repository in my Github soon…).

Segmented sleep for 5 weeks

For the next 5 weeks, I will be sleeping from 23:00-2:00 and 4:00-7:00, totaling in 6 hours of sleep per day. This is known as the segmented sleep schedule. If it goes well, I will likely continue with this schedule. For some of you 6 hours probably sounds like a lot, but I usually get 8 hours, so cutting out 2 is a significant improvement.

My motive behind doing this is that I was recently offered a research opportunity that I could not refuse (I will likely post about it later). To make time for it, I had to sacrifice something – my choice was sleep. About a year ago I was on a similar routine and it worked well, but I haven’t had the motivation to start doing it again until now.

Continue reading

Dabbling around with Haskell

So last night I went to a Haskell workshop.

One of the examples my professor gave was the factorial function:

The first line is the function signature, the second line is the base case, and the third line is the recursive step of the function. One thing I really like about Haskell so far is how clean recursive functions are.

Today I started dabbling a bit more with Haskell and created a recursive function to calculate pi using the Gregory–Leibniz formula:

I had to name it “pie” because “pi” was a reserved keyword. The “fromIntegral n” is there to allow an integer to be part of a fractional calculation. This is necessary because Haskell is über strict with types.

Here it is in action: