Generating a random password from command line

The following uses openssl to generate a random binary sequence “N” bytes long encoded in hex or base64. The “N” is all important. If you use base64 you get uppercase characters in the string which some sites require, you can also use hex which makes for a more readable string but it will be longer. If the people cracking your password are using an offline database (rainbow table) to crack the password longer random strings are better (this assumes they don’t know how you encoded your random bytes).

openssl -rand -base64 32

openssl -rand -hex 32

How long should “N” actually be? This table at wikipedia lists the given entropy in bits for various character sets. If using hex and you want 80 bits of entropy you need 16 bytes. Base64 is not listed but the character set has 64 symbols so the entropy is similar to the case sensitive with numbers which has 62 symbols so 80 bits would require 12 bytes. The number of bits you choose for entropy is up to you. Generally the longer the better and with tools like LastPass there are no reasons not to use 20 or more bytes per password.

qemu bridged networking

My final /etc/networking/interfaces file looks like (this is for Debian)

auto lo eth0 tap0 br0

iface lo inet loopback

iface br0 inet dhcp
bridge_ports eth0 tap0
bridge_maxwait 0

iface eth0 inet manual

iface tap0 inet manual
pre-up tunctl -b -u <my_user_name> -t tap0
pre-up ifconfig tap0 up
post-down tunctl -d tap0

I stole this from the following site joost.damad.be

Beware the username enttry above needs to be changed to your username… You will also need to install uml-utilities. Once I had this running I could start my image as follows:

qemu -net nic -net tap,ifname=tap0,script=no -hda debian.img

Mount You must specify the filesystem type

I encountered this error while trying to mount an image created using qemu. The command from the docs says to run the following command to mount it on the loopback device.

mount -o loop,offset=32256 debian.img ./mntpoint

This is completely wrong because the data start is not 32kb into the image file. To figure out where it starts you need to use the following commands:

]$ fdisk -ul debian.img

you must set cylinders.
You can do this from the extra functions menu.

Disk debian.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00077ccb

     Device Boot      Start         End      Blocks   Id  System
debian.img1   *        2048     5785599     2891776   83  Linux
Partition 1 does not end on cylinder boundary.
debian.img2         5787646     6141951      177153    5  Extended
Partition 2 does not end on cylinder boundary.
debian.img5         5787648     6141951      177152   82  Linux swap / Solaris

Once you have this output you can see that the data starts at sector 2048 and since sector size is 512 on my image I need to set the offset to 512*2048. So the final working command is:

mount -o loop,offset=$((512*2048)) -t ext3 ./debian.img ./mntpoint

and we now have a mounted image file.

Changing your keymap

I recently had an issue where my keyboard when using synergy was inserting a double arrow instead of the usual greater than or less than sign also known as guillemotleft and guillemotright.

To fix this annoying bug I added

keycode 53 = x X greater greater greater greater
keycode 52 = z Z less less less less
keycode 24 = q Q at at at at

to a .Xmodmap in my home directory. If you are wondering how to find the keycodes etc you can use xev. To start it without restarting X use

xmodmap .Xmodmap

Superstition is Rife among developers

I was reading John Stuart Mill’s on Liberty and came across the following passage:

There is a class of persons (happily not quite so numerous as
formerly) who think it enough if a person assents undoubtingly to what they think true, though he has no knowledge whatever of the grounds of the opinion, and could not make a tenable defense of it against the most superficial objections. Such persons, if they can once get their creed taught from authority, naturally think that no good, and some harm, comes of its being allowed to be questioned. Where their influence prevails, they make it nearly impossible for the received opinion to be rejected wisely and considerately, though it may still be rejected rashly and ignorantly; for to shut out discussion entirely is seldom possible, and when it once gets in, beliefs not grounded on conviction are apt to give way before the slightest semblance of an argument. Waving, however, this possibility assuming that the true opinion abides in the mind, but abides as a prejudice, a belief independent of, and proof against, argument this is not the way in which truth ought to be held by a rational being. This is not knowing
the truth. Truth, thus held, is but one superstition the more,
accidentally clinging to the words which enunciate a truth.

 

Have you ever heard Perl and PHP fans get stuck into each other, or Java vs C++, or Vim vs Emacs (there can be only one). It’s crazy! Most of the noise is created by people who have no real understanding of the technology they are arguing against and some of them don’t even understand the tech they’re arguing for. Wikipedia has an entry on Editor Wars.

Basically Mr Mill is stating that if you’re arguing against something with little real understanding about what that something is then your just another superstitious idiot.

Eclipse Cannot connect to keystore

If you get the following error:

An error occurred during provisioning.
  Cannot connect to keystore.
  JKS

You need to check what version of java you’re running. I’m running Debian and hat gij installed and this is no use for eclipse. I tried the following:

apt-get install openjdk-6-jdk
update-java-alternatives -s java-6-openjdk

but this failed miserably. I ended up downloading and installing a new java bundle from Sun and removing every debian package related to Java.

Exim4 Unrouteable Address

I have no idea when or why this started happening for me but I started getting Unrouteable address appearing for any external address.

I’m a huge fan of Debian but there are some things that really piss me off. One is the way they have completely screwed the exim4 configuration. Exim4, if you are not an administrator or mail guru is not the simplest thing in the world to configure, it’s config file is fairly involved and you can do anything in it. Add DEBCONF variables to this and you have a complete nightmare configuration.I spent two days tracking this error down to the following:

DCconfig_internet=1

That was all I had to add to /etc/exim4/exim4.conf.template

Why this changed I have no idea. The setting I am using in /etc/exim4/update-exim4.conf.conf is

dc_eximconfig_configtype=’internet’

I really cannot make head nor tail out of this at all. I sometimes wish I had started learning Postfix instead of Exim but part of me thinks that it’s not Exim but rather the way it has been packaged up thats compicated.

High Performance PC for Gaming

I need a fast desktop for development and was at the dell website when I came across the following link.
alienware.jpg These guys do “high performance PC’s”. I clicked on the fastest looking offering they had and the total price for the basic package is £3008 (I kid you not). For that price I get an odd looking case (see pic on right). The case looks like it was designed as a bottle for mens aftershave (pimp my pc). You also get the following.

Alien Case (see pic on right)
Intel® Core™ i7-940 Performance 2.93GHz 8MB Cache
1GB NVIDIA® GeForce® GTX 280
1000 Watt Alienware® Approved Multi-GPU Power Supply
3GB DDR3 SDRAM at 1600MHz – 3 x 1024MB
Alienware® Approved Intel® X-58 Chipset Motherboard- Socket 1366 Core i7 Ready, Triple Channel DDR3 Memory
Windows Vista® Home Premium 64-bit with Service Pack 1
1.0 TB SATA 3Gb/s 7200 RPM (2 x 500GB)
20X Dual Layer DVD±RW/CD-RW Writer
High-Definition 7.1 Performance Audio – Standard
Logitech® Classic Keyboard UK – Space Black
Standard Optical 3-Button Mouse with Scroll Wheel

To say I am woefully unimpressed with the above is a bit of an understatement. I have not looked overly hard at the rest of the details but those are the main parts.

I decided to put my old hat on and go shopping to see how much it would cost me if I was prepared to build it and this is what I was able to ruffle up in a few minutes.

Case 100
Intel® Coreâ„¢ i7-940 Performance 2.93GHz 8MB Cache  440
1GB NVIDIA® GeForce® GTX 280 300
1000 Watt Power Supply (multi GPU) 150
3GB DDR3 SDRAM at 1600MHz – 3 x 1024MB (Corsair) 91
Intel® X-58 Chipset Motherboard- Socket 1366 Core i7 Ready, Triple Channel DDR3 Memory  270
Windows Vista® Home Premium 64-bit with Service Pack 1   100
1.0 TB SATA 3Gb/s 7200 RPM (2 x 500GB)  100
20X Dual Layer DVD±RW/CD-RW Writer  50
High-Definition 7.1 Performance Audio 85
Classic Keyboard UK 12
Standard Optical 3-Button Mouse with Scroll Wheel  12
1610

I’ll add another £400 in case I have missed something or made an obvious mistake. So we can save £1000, I don”t know about you but thats a lot of money. I probably get some warranty with the Alien machine and it comes packaged etc but it’s not worth £1000. Seasoned Gamers can knock a machine up in a morning so I’d be surprised if many seasoned gamers are using these machines. I bet I could build a significantly faster machine for £3000 than the one above. It might look like shit but it’d be fast as hell.

The following paragraph is most likely way off the mark on what would constitute a good gaming machine. There are various reasons for this, for instance, ensuring the graphics cards work with server hardware, could the game take advantage of 4 CPU’s with a total of 16 Cores, does the vista license allow us to have 4 sockets.

I could fit a rack in the attic or if I was close enough to the garage I could run a monitor cable etc through the roof, floor or wall to the PC. Add a power switch and a mini itx server with shared peripherals and then you can start looking at 4/5U machines with multiple CPU’s with multiple cores. You can pick up some serious hardware on ebay with SCSI and hardware raid built in. Have a look on ebay.com for v40z or Add some decent graphics cards and things would be looking quite fast.

If I was gaming in the states from the UK I would also look at tunneling my traffic to the states from the UK over a compressed line. You can get dedicated servers in the states very cheaply that would make excellent end points for the tunnel. The closer you can get to the server in the states that you are playing your games on the better.

I’m off to look at desktops now.

Learning Computer Science

This is an update from to my earlier  Self Taught Computer Science post.

I’ve started working on the SICP Exercises and so far so good. I’m finding Scheme, the variation I’m using, frustrating but thats to be expected. It’s frustrating because there appears to be no actual standard implementation of Scheme. It’s also perverse that, because it appears so simple, and there’s no standard implementation, people try and create a compliant version of Scheme. Perhaps this is testament to how hard it is to follow a standard as opposed to blazing your own trail the way a lot of popular languages do. There’s another blog post in here somewhere comparing languages that follow standards and languages that …. evolve!

I’m using the DrScheme IDE and I love it for its simplicity. Even though Scheme is frustrating I’m finding it easy to work with. I know Functional languages are based on Lambda Calculus but until I started working in Scheme I hadn’t realised how easy it is to think in functions. This can probably be attributed to the SICP exercises being heavily slanted towards computation and interesting mathematical functions like the Wallis Product or the Fibonacci Sequence. Regardless, I’m finding it easier to think mathematically in Scheme than Perl or Java.

I’ve done one exercise in Haskell so far and its been painful. This is not because Haskell is painful it’s just that almost every tutorial on Haskell I find first wants to teach me how to use the Haskell calculator (my derogatory term for the interpreter), as opposed to telling me how to get the thing to compile a standalone executable. That last sentence is a rant, as I’m digging into Haskell I’m finding more material. I really don’t know what it is about this language that I find so appealing. I’ve seen some really negative reviews of Haskell online but I cannot bring myself to hate it even though it’s driving me a bit mad learning it. Only time will tell if Haskell and me are meant to get on.

So far I’m finding SICP time consuming but digestible. I’m noticing a marked increase in complexity, I’m just hoping I can get through enough during my holidays to learn something.

Self Taught Computer Science

Over the last year I’ve felt as if I’ve reached a plateau. I cannot put my finger on why this is or why I feel like this but regardless of what programming language I use C/Perl/Java I feel like I’m just moving boxes. This is not the first time I’ve felt like this either.

I don’t think this is a problem with the languages I’m using I think its more of a problem with me and the applications I tend to be working on.

After a while (not a very long while) developing CRUD applications loses its appeal. Developing network apps, GUI’s etc… they all start to look dull when you’ve done them a few times. My experience with GUI’s is very limited so the above statement is an assumption in that regard.

I’ve no idea why this is but I’m sure more experienced programmers could probably shed some light on this. I personally think that unless something stretches your ability it will eventually lose it’s novelty.

Though, surely as a programmer who loves to program I should be able to entertain myself in almost any application I write but for me this does not seem to be the case. I’ve never been one for mental wanking and I would prefer not to start. Over complicating an application just to keep it interesting doesn’t appeal to me in the slightest. I watch programmers fall into this trap all the time and its sad to see them commit this cardinal sin. The worst thing is having to watch them explain their contraption as if it’s a simple solution when it’s obviously a complicated  mess of a thing. Don’t get me wrong I’ve been guilty of this sin and in quite a few cases been oblivious of it. Its almost as bad as the Not Invented Here syndrome so prevalent in our trade.

I personally think my main problem is that I don’t feel as if I am getting any better. I look at old applications and where I would normally see a dozen ways to improve it I see two or none and it’s not because it’s perfect or anywhere close, only a fool would believe so. I know I’ve not learned a fraction of what I need to know in my field so why have I hit this wall. Have I reached the limits of my ability or is this a normal phenomenon that programmers go through?

My opinion is that I’m seeing things through the wrong goggles. Most of my education has been self taught so its been led mostly by interest as opposed to formally taught. I’ve been studying with the Open University for several years now in order to get some background mathematics etc but I still think there are areas that I need to improve on in particular around Computer Science.

Unfortunately the Open University computing courses are geared towards popular topics, Java etc in order to attract more students. Having done a few of their computing courses I wish I hadn’t bothered because I gained more from my own work than I did from the taught courses. I cannot say the same thing about the mathematics though. I decided to start mathematics because I knew that whatever I learnt would be applicable regardless of the current fashion or trends in industry and it won’t be out of date in a couple of decades.

Having looked around this for some time I have decided that what I need to do is to start my own computer science program to build on the mathematics I’m doing with the Open University. The areas I’m really interested in is how to go about writing my own computer language, compiler, virtual machine etc so I’ve been looking around to see what other universities are doing and what books they are using in this area.

Having done a fair bit of looking I spotted a definite trend towards functional languages and the further I looked into this the more I noticed that All Roads Lead To Lisp. Or to scheme or to some variant thereof. Abstracting a bit further I am being steered towards learning a functional language. The two languages that interest me the most in this area are Scheme and Haskell. Now all I need to do is decide what books and resources I need to start a course in this area. Most resources online point towards Structure and Interpretation of Computer Programs (SICP) in order to get started so I am looking at this now. I am not sure if I’ll try and tackle Haskell until I get a bit more familiar with scheme although having looked at Haskell the language is appealing to me.

Watch this space for more installments on my self taught Comp Sci education!