I have been trying to learn NodeJS a bit lately. I have found a good exercise to learn new language is to re-implement UNIX utilities. I decided to try to re-implement ‘wc’, which counts the number of words, characters, and lines that are received on stdin.

The code isn’t perfect, in that it doesn’t match the exact output of wc, but I am happy with it. The main thing I wanted to do is learn about Javascript closures, which this sample helped me to do. Note that the line_processor variable actually has four callable functions, but the ‘lines’, ‘characters’, and ‘words’ variables are all inaccessible outside of the line_processor closure. This was a tricky concept for me to understand.

// Takes a stream of data and counts the number of words, lines, and characters
//
// Similar to the the UNIX program 'wc'

Apparently the last time WordPress updated itself, something changed. I noticed I was unable to login to the admin page, but the normal blog worked fine.

I tried a bunch of different fixes I found online, but the problem was that the wp-admin/ folder was set to group writeable permissions (0775), rather than owner write only. Changing permissions on the folder to 0755 fixed the problem for me.

I tried resetting my theme as part of the fix. I actually kind of like this theme (the default) so I might keep it for a while.

Recently I needed to convert a Montgomery form elliptic curve (Curve25519) to Weierstrass form. This post captures some of that work and code for arbitrary Montgomery form curves as well. I am going to do a lot of math hand waving, but will try to provide references as necessary.

Just a quick post to remind myself of this in the future (and hopefully help others!)

Anyways, I’m working on writing a PE parser module. Part of this is listing the relative virtual addresses (RVA) of exported symbols. To figure out how to do this, I was reading the PE & Coff Specification (http://msdn.microsoft.com/en-us/windows/hardware/gg463119.aspx) document for reference. However, there is some conflicting information in it. For the rest of this post, all section numbers apply to Revision 8.3 (February 6, 2013) unless otherwise noted.

Recently, I enrolled in a class on Digital Signals and Systems. One of our first homework assignments was to implement a reverb filter and image smoother in Matlab. I’m not a Matlab expert, but I thought someone else might like to see what I did. Please suggest improvements!

Basically, a reverb and an image smoother are types of difference equations. This is one of the things I’m learning about in my signals class. Essentially, what is happening is every sample y[N] of the output is calculated from an input sample, x[N], along with other past samples from either the input or the output. In the case of the reverb, x[N] is combined with y[N-D] to compute y[N]. For the image smoother, y[N,M] is a function of x[N,M] and all the surrounding samples, x[N-1,M-1], x[N-1,M]], x[N-1,M+1], x[N,M-1], x[N,M], x[N,M+1], x[N+1,M-1], x[N+1,M], and x[N+1,M+1].

Background

The other day, I read the following article. If you don’t want to read it, you really should. It’s awesome. Essentially, a student managed to get access to all of India’s standardized test scores and who they belonged to. The author posted his code and results on Github (thanks for sharing!). However, the data itself was not mirrored and is no longer available. Grumpy. I wanted to pull the data off Github.

This got me thinking about Git, how to use Github with it, and my own personal Git habits. Git is designed as a distributed version control system. This means that there should be no single ‘master’ copy of your source code anywhere; multiple copies should be available from different nodes across the network, be that the local network or the Internet.

Scenario

You are working on a code project at home and dutifully using Git for version control (as you should!). You commit your changes locally and push them to Github. You get off the computer, drink beer, socialize, work on your plan for world domination, sleep, and head to work the next day. Your co-worker asks to see what you were working on (of course you told her about how awesome your side project was). You go to Github to pull the code and *gasp!* Github is down! Not only that, but your cat ate the laptop at home with all the code! Suddenly, all your code is gone forever. (Maybe this example is a bit hyperbolic, but stay with me.)

The Problem

When most people use Git, the only remote they use is Github. In the previous scenario, Github was considered to be the 100% safe backup solution. By pushing to only Github, what you’ve done case is create a single point of failure.

Description

When you only use Github as the remote you push to, you are negating a lot of benefits of distributed version control. Your code should be spread out among multiple nodes across the network. When you only use one remote, you are using two nodes: your local machine and the remote. This may work fine most of the time, but what if you forget your laptop and the remote is down? You should have multiple remotes to pull from in cases like this.

Note that when I am saying ‘remotes’, I essentially just mean nodes on the network. I do a lot of development in my free time and use Git to keep track of my personal projects. In a company environment though, you could also push code to your co-workers, team leads, build servers, and a backup. In case of a build server failure, you can then pull changes from any of those machines.

Solution

The solution is to simply have more than one remote! This is not hard to set up or configure. When you have multiple remotes, you are never at the mercy of a single remote server. Not only could a single remote go down, the admins could decide to be super evil and just delete your code. Bad news bears.

With multiple remotes, if one remote goes down, no worries, just pull and push to the others instead.

Call to Action

There are plenty of free options for Github hosting. Since Git is distributed, just because you are using Github, doesn’t mean you can’t also use BitBucket! I myself useboth. If you have a server at home or pay for a VPS, add that as a remote too! Below I have provided an example of adding 2 new remotes (one for BitBucket and Github) for a project I’m working on in my free time.

Push to the new remote with

Push to multiple remotes at once

This part is somewhat confusing, so maybe check the StackOverflow link for more info. Essentially, you are editing your .git/config file to create a new remote that has multiple URLs (that you added previously) in it. Edit your .git/config file and add:

Summary

If you’re only using Github or one remote server to push your Git code to, you are doing it wrong. Git is designed to have multiple remote servers, so in case of a failure, you simply use a different remote. I have pointed out some options you can use for new Git remotes, such as Github, Bitbucket, or using a personal server. I also showed you how to add these new remotes to your existing repo and to push to them.

Leave a comment if you have any suggestions! I’m not a Git expert by any means, so I’m sure there are other ways of doing this!

I’ve been playing around with some basic HTTP programs lately and noticed that Kaspersky flags them as viruses for some reason. I did some investigation and learned why and how to get around those detections.

While trying to figure out how to use the ADC on my AVR microcontrollers (not Arduino, raw AVRs!), I kept finding a variety of tutorials with examples that just didn’t work for me. I eventually got it working, so thought I would share, hoping it would help someone else eventually!

I am using an ATmega32U4 (awesome chip!), but these steps should be appropriate for most AVRs. Note that my clock is running at 8 MHz. If you change the clock speed, make sure to change the prescalar value.

Note that this code works for a continuously running, non-interrupt driven ADC program. If you want to use single shot conversions or interrupt driven ADC, you will need to change these lines appropriately. I might add that as another post eventually.