Commiting parts of a file in Git

´╗┐Sometimes when you are about to commit your changes to Git, you realize that you should have split the changes in a few different commits instead of just one unorganised sloppy commit. Since some files will have overlapping commits, you don't have no choice but to combine all changes into a single commit... Wrong!

In Git you can commit only selected parts of a file by stagging your changes with:

git add -p <file>

This command will prompt you for each chunk of changes and then add them to stagging.

When you've stagged all changes that will be for a commit, you might want to test if this commit will run independent from the rest of the unstagged changes.

Stash away all unstagged changes with:

git stash -k

Run all your tests. If it's OK, commit. Then bring back the changes with:

git stash pop

Now you have no excuse for sloppy commits!

Friday, November 13, 2015   #git #dev #util 

Radare2 - Dissecting 'Hello World'

Lately on reddit's programming there's been some news about Radare2, a reverse engineering tool that seems to be able to dissect and manipulate all kinds of files.

The tool can be used on compiled binaries to follow and understand the flow of execution and viewing resources embedded in files.

You can write plain text or binary data like hex constants and CPU instructions right into binaries.

On Debian you can get it by installing the package radare2.

Let's see it in action with an example of how to change a classical Hello World to a Hello Buddy.

We will compile a binary from this code with gcc:

#include <stdio.h>

int main() {
        printf("Hello World");
        return 0;


gcc -O2 hello.c -o hello

Running the program we get:

Hello World

Start Radare2 and tell the program that we want to be able to write to the file (-w):

r2 -w hello

Seek to the beginning of the file using the command s:

s 0

Search for the text "hello" in lowercase with /i:

0x00000000]> /i hello
Searching 5 bytes from 0x00000000 to 0x00001a30: 68 65 6c 6c 6f 
hits: 2
0x000005b4 hit2_0 "Hello World"
0x00001128 hit2_1 "hello.c"

The program found two occurrences of "hello".

Let's seek to the one called hit2_0:

s hit2_0

Now we are at the position of the text we want to change and we can change it with the command w.

w Hello Buddy

All done. Exit the program with CTRL-d and let's run our executable.

Hello Buddy


It's no coincidence that both strings "Hello World" and "Hello Buddy" have the same amount of characters. When replacing a string in packed data you should replace it with a string that has the same length to not upset the order of the data.

The official Radare2 book is easy to follow along for a programmer. The book gives you a good taste of what the tool can do and shows you the fundamentals of how to use it.

They also have a challenge that let's the user crack a binary file with a password protection.

Monday, November 02, 2015   #radare2 #util #dev #revere engineering #discovery 

Useful bash shortcuts

There are several keyboard shortcuts in standard Bash shipped with most Linux distributions.

If you use the following shortcuts, you never have to move your hand away from the Touch type position to access arrow keys, return or backspace.

  • CTRL-f Move cursor forward one character, as Left arrow
  • CTRL-b Move cursor backwards one character, as Right arrow
  • CTRL-p Back one entry in history, as Up arrow
  • CTRL-n Forward one entry in history, as Down arrow
  • CTRL-m as Return
  • CTRL-h as Backspace
  • CTRL-a as Home
  • CTRL-e as End
  • ALT-f Move cursor forward one word
  • ALT-b Move cursor backwards one word
  • CRTL-w Erase the entire argument before the cursor
  • CRTL-u Erase everything before the cursor
  • CRTL-k Erase everything after the cursor


  • CRTL-d Exit terminal session
  • CRTL-l Clear the screen
  • CTRL-r Opens a history search prompt, lets you search by text query

Tuesday, October 20, 2015   #bash #cli #keyboard #shortcuts #util 

PlantUML - UML for graphviz

There's a lot of software around for modeling UML, but much of it is old and has halted development or is part of an IDE.

Several years ago I used a plug-in for Eclipse, called ObjectAid, and then Umbrello.

I tried the latest version of Umbrello, but there seems to be a bug in both the Linux and Windows versions that prevent you from saving your documents. This is of course a deal breaker, so an alternative has to be found.

Graphviz has been around for a long time, and you can certainly use it to make graphs. However, you need a lot of tweaking to make it look good. It also lacks a smooth way of modeling UML.

After searching around the webs, I came across PlantUML. This program uses Graphviz for rendering and has similar syntax. Graphviz+PlantUML will figure out a smart way of organising your diagram.

This is a snippet of a deployment diagram for a home network:

cloud Internet

node Router {
    component "Open port" as port_ssh
    component "Open port" as port_torrent

frame LAN {
    node "Home server" as Closet <<Raspberry PI>> {
        component "SSH" <<Open SSH>> as rasp_ssh
            component "Torrent" <<Transmission>> as rasp_torrent

    agent "Home wifi" as wifi

Internet -(0)- Router : "  100/100 Mbit  "
port_ssh -(0 rasp_ssh
port_torrent -(0 rasp_torrent

Router -- wifi

And rendered:

LAN Graph

Tuesday, October 13, 2015   #plantuml #discovery #graphviz #uml #tech #util #umbrello 

Redesigned site again

So I ran into some problem using a single-page oriented system with knockout.js for my site.

The problem is not the browsing, but the indexing. I want my page to be able to appear on search results from web search engines.

If you are using a single-page design, you will have some problems with this. Search engines can't crawl you page properly and keywords are hard to inject.

I tried using the escaped fragment approach but I figured this would only solve the problem for Google. Not any other search engine or crawler.

So I've migrated over to a classical server side rendering. The rendering is done with express and pages are written in Jade.

So far I really like Jade. It requires little html-coding, lets you focus more on the model behind the page and doesn't mix rendering and model like a classical PHP setup usually do.

Lazy git aliases

When you are working with version control system, you tend to do the same operations over and over all the time. Therefore you should take every shortcut you can find to make the process as smooth as possible, limiting the amount of text you type.

Before switching to Git, I used Svn a lot. In Svn they have added shortcuts for the most common commands:

  • svn update = svn up
  • svn commit = svn ci
  • svn status = svn st
  • svn checkout = svn co

Using the short versions instead of the longer ones will save you some time. When using svn st I mostly add the option -q to get a more limited output.

Most of the commands in Git are verbose and that's a hazzle. To my knowledge there are no standard aliases in Git like the ones in Svn so lets create some!

When you create aliases in Git you specify what command will be executed and you can also specify parameters. Basically you tell Git what to add after the git command.

git config --global "commit"
git config --global alias.fe "fetch -v --all"
git config --global alias.rb "rebase -v"
git config --global "merge"
git config --global alias.meff "merge --no-edit --ff"
git config --global alias.menff "merge --no-ff"
git config --global "checkout"
git config --global "status -uno -s -b"
git config --global alias.lo "log --decorate"
git config --global alias.tree "log --graph --decorate --pretty=oneline --abbrev-commit"

Copy these into your terminal to store them in your Git configuration file ~/.gitconfig. They all bring down the amount of key presses needed, and some of them have a bit added functionality

I use git fe all the time to make sure I'm working against the newest code. The added -v will give you a simple list instead of a verbose message, and --all will fetch data from all repositories. If any of the branches have been updated you will se it in the list.

The merge comes with an extra two variants. The meff will tell Git to explicitly make an fast-forward, and menff not to make a fast-forward.

The tree alias will print you a decent view of how the branches and commits are connected. I found this alias online by searching for git tree alias. There are a few variants of this command.

I have a github gist file with all the aliases that I use: Gist.

Tuesday, October 06, 2015   #tech #dev #git #lazy #alias #cli #config 


tmux - Multitasking in cli- Tuesday, September 22, 2015 #tech #tmux #discovery #cli #ssh #util Redesigned site- Monday, September 21, 2015 #tech #dev #journal #nodejs #expressjs #bloggy #knockoutjs #pagerjs