# Sleeping Cyborg

Jonathan David Page talks about whatever he happens to be thinking about. Sometimes other people join in.

A collection of cool people and projects.

## How to create a Windows 7 Install USB from Linux

by on 17 June 2012
in , ,

This is not for your benefit. This is for mine. If you happen to find it useful, that's nice. Feel free to send me questions if you need help.

1. Create a single NTFS partition on the thumb drive.
2. (If you're using a physical install DVD) put the DVD into the drive and mount it or (if you're using an ISO) mount the ISO as a loopback device.
3. Copy all of the files from the DVD or ISO to the thumb drive.
4. Install ms-sys.
5. run ms-sys -7 /dev/sdx to add a bootloader to /dev/sdx, which should be substituted for the actual block device name of your thumb drive.
6. Unmount everything. You now have a functioning Windows 7 install usb.

## Skype 2.2 on Fedora 15 64-bit

by on 24 May 2011
in

After grabbing the RPM from the Skype site, you'll need to install the following packages. Skype devs, if you read this: you're supposed to list these as dependencies so that they install automatically.

• glibc.i686
• alsa-lib.i686
• libXv.i686
• libXScrnSaver.i686
• qt.i686
• qt-x11.i686
• alsa-plugins-pulseaudio.i686 (if you're using Pulseaudio. If you don't know, the answer is yes.)

These can all be installed at once (with dependencies) using the command:

su -c "yum install glibc.i686 alsa-lib.i686 libXv.i686 libXScrnSaver.i686 qt.i686 qt-x11.i686 alsa-plugins-pulseaudio.i686"


## Bash code for finding active IP addresses

by on 10 May 2011
in , ,

I sometimes have to ssh into my brother's laptop. This can be a painful procedure for all involved, because I need to know the IP address, but he can never remember the command to get his computer to tell him. I normally solve this by just pinging everything from 192.168.1.100 to 192.168.1.120 or so, and then attempting to ssh into any that respond, but the other day I got slightly fed up with this.

So without further ado, I give you:

for i in {100..120}
do ping -c 1 192.168.1.$i | \ grep -B 1 ' 0% packet loss' | \ sed 's/^.*$$192\.168\.1\....$$.*$/\1/g;/192/!d'
done


This "simple" bash code just loops through the address range given on the first line, pings each one, uses grep to find ones that responded, and then sed to format nicely. I could probably do it all in sed, but hey. If you think of any improvements message me and I'll add them.

## Mercurial current branch in your Bash prompt

by on 10 April 2011
in , , ,

Edited 2011-06-17: Added Mac OS X support

(Make sure to read the whole thing; my first solution is slow and will cause pain and anguish for the user.)

So I thought it'd be useful to have the current branch of a local Mercurial repository in my bash prompt. This is easy enough, because we have hg branch. The result:

PS1='\u@\h:\w$(hg branch 2> /dev/null | sed "s/.\{1,\}/ [hg:\&]/")\$ '


Basically, it tries to grab the current branch, discards any error, and then sends the results off to sed. The sed script basically says "if there's at least one character (i.e. a repo was found), put it into the format [hg:branchname], otherwise return nothing".

The result:

jonathan@kippersnacks:Code/active/awesomeproject [hg:default]:


It works perfectly, except for one thing.

It's a bit slow. As in perceptibly slow. As in irksomely slow.

Mercurial is not the speediest of version control systems, and this command is no exception. While the delay is acceptable for commits, pushes, and pulls, it is not when attempting to display a bash prompt. One may choose to blame this on Python, but that's sort of irrelevant.

Well, it turns out that the name of the current branch is stored in reporoot/.hg/branch. This is terribly convenient, as we can just cat it—oh wait. We also have to recurse up through directories. I'm sure this is quite possible in bash, it's just it would be rather unwieldy, and possibly evilslow. And I'm not a bash wizard.

Git is quite fast, and has a similar tool for this very purpose—written in C of course. So I took a few minutes to dash off a C program which does the job in about 50 lines. You can find it here: hg-ps1.c

Compile it with gcc -o fasthgbranch hg-ps1.c, put it in your $PATH, and use something like PS1='\u@\h:\w$(fasthgbranch)\$'  as your bash prompt in ~/.bashrc (or ~/.bash_profile if you're on OS X). Lightning fast. It's basically public domain, and you can do whatever you want with it, so enjoy. If you republish or redistribute it, it'd be nice if you credited me, but I don't mind too much if you don't for some reason. If you take credit for it yourself you are an evil scumbag plagiarist but there really isn't much I can do about that. ## Restarting a Stopped Copy With the dd Command by on 29 November 2010 in with some comments, maybe. Quick note; couldn't find this anywhere else on Google. Mostly for my own reference. If you're doing a long-running dd command, and the copy is stopped (either by you or circumstances beyond your control), you can restart it using the following procedure. In all commands, infile is the path of the input file and outfile is the path of the output file. $ ls -ld infile
-rwxr-xr-x 1 you users 199488128 Nov 29 14:49 infile


You're interested in the 5th field, that big number. Now, grab a calculator, and divide the number by the blocksize you're going to use.

Now you can restart the copy:

\$ dd if=infile of=outfile skip=offset seek=offset bs=blocksize


offset is the number you calculated above, and blocksize is the blocksize.

Basically, "skip" causes dd to skip the specified number of blocks before starting the copy. "seek" causes dd to start that many blocks into the output file. You don't need to specify notrunc because dd doesn't touch blocks you've seeked past.