Latest Entries »

This Rhino has some things to tell you about Git

This Rhino has some things to tell you about Git

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 use both. 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.

Add a new remote

$ # git remote add alt alt-machine:/path/to/repo
$ git remote add github git@github.com:stkerr/MemoryPIN.git
$ git remote add bitbucket git@bitbucket.org:samoz/memorypin.git

Push to the new remote with

$ # git push <remotename> <branch name>
$ git push github master
$ git push bitbucket master

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:

[remote "AllTheThings"]
    url = git@github.com:stkerr/MemoryPIN.git
    url = git@bitbucket.org:samoz/memorypin.git

Then to push to all of those different remotes, do

$ git push AllTheThings master

I used info from here and here for the commands above.

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.

View full article »

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.

ADCSRA |= (1 << ADPS2) | (1 << ADPS1); // prescalar = 64
ADMUX |= (1 << REFS0); // reference voltage from internal source
ADMUX |= (1 << ADLAR); // 8 bits, instead of 10
ADCSRA |= (1 << ADATE); // free running
ADCSRA |= (1 << ADEN); // enable ADC
ADCSRA |= (1 << ADSC); // start A2D conversions

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.

I’ll preface this post with the fact that it will be fairly technical. I have been trying to write a Windows program which can get the EXE path of a specified process ID (PID). I found a couple different ways, so thought I would go through them here.

This Rhino is curious to find EXE paths of applications

View full article »

Read on for a tale of my initial frustration, ever incresaing despair, and eventual victory in this tale of my configuration of audio devices in a Windows 7 VM guest on top of an Arch Linux host.

This rhino is so happy that he can now use his audio software in his VM
View full article »

A quick tip for the Couch (CouchDB that is)

I have been playing around with CouchDB lately as a new tecnology. It is a NoSQL database that stores everything as a ‘document’, rather than as a row like a traditional relationship based database, such as MySQL. What is also cool about CouchDB is that it uses a REST API. That is, every request and operation is done through HTTP, so it works with essentially every language. NoSQL is new to me, but I am liking it so far!

This rhino wishes he had a comfortable couch to lay on.

I am actually using my CouchDB instance as both my database and webserver. Since CouchDB has a REST API and everything in CouchDB is a document, so there is no reason why you cannot simply ues the browser to send an HTTP request and return HTML pages directly from the database! Pretty neat to eliminate Apache, PHP, and MySQL from the web stack and instead use just CouchDB.

Anyways, I have been chugging along merrily, serving static HTML pages or show functions from my database, until I started to use the list functions that CouchDB offers.

Specifically, I was having trouble getting it to return an HTML header, rather than just plaintext.

To solve this, you must format your list function as:

function(head, req)
{
    provides('html', function() {
    ... The list function ...
    send(data);
});
}

This tells the list function to send HTTP headers along with the data, rather than just the data itself.

This took me a while to figure it out, so hopefully it helps you!

Sometimes I read MSDN entries and wonder what the numeric value of a constant, such as GENERIC_READ, is. However, MSDN usually does not list this information, so I am forced to dive into header files.

Fatigued Rhino

He is so sick of looking up constants by hand

Well, I got quite sick of doing this, so I whipped up a few Python scripts and made a database of a lot of the Windows constants.

I do not claim that 100% of them are there, but on the initial import, I found over 100,000, so there are quite a few! In the future, I will be adding POSIX and other constants, as well as some of the Windows constants I missed. Parsing all the headers was a pretty interesting task, so I might publish another entry on it here in the future.

I thought this database might be helpful to others, so I am publicly publishing it at www.namethatwindowsconstant.com.

Enjoy :)

Homemade MIDI Controller!

Since I have been home over winter break, I felt like doing a little bit of fun hacking. As a few of my posts have shown, I am fairly interested in hardware oriented projects, so I thought I would try another. I have several AVR chips and support supplies laying around, so I thought I would use them. Recently, I have also been playing around with DJing. It is fairly common to use a controller to control a DJing setup, but they are all fairly expensive. Since they are just a collection of buttons, knows, and faders, I decided it would be interesting to try to make my own.

My inspiration for this project

This post will cover what I did for the various parts as well as some of the interesting bits of code, so that you can make your own!

View full article »

Lately, I have been doing work with the Pistachio L4 microkernel as part of my research. This requires building various disk images, installing GRUB, and running them inside of a virtual machine. Initially, I was using Linux to do this, since it had all the tools ready to go and was what everyone else was using. However, I have a Mac, so I wanted to be able to use that, rather than SSHing into a server all the time. I didn’t think it would be a big deal, just install the same tools on my Mac, right? Wrong! What follows is the odyssey of what I’ve gone through to do this. Hopefully, it will help anyone else facing a similar circumstance.

View full article »

One day, I was curious about how the computer system goes from booting to actually loading up an operating system. Obviously, it must retrieve the operating system from disk at some point, so I decided to investigate this. The first step in this process is reading the MBR, or Master Boot Record of the hard drive. The MBR is used to store data about where the OS is stored on the drive.

I figured the MBR would be interesting to learn a little bit more about, so I decided to load it up into IDA Pro, a tool for disassembling programs, and see what I could find out.

This baby rhino was also curious about MBRs.


I learned a lot and had a lot of fun, so I’m presenting it here to share my results.

View full article »

Powered by WordPress | Theme: Motion by 85ideas.