Paulitex ][

2 shell tricks

1) Empty file of any size (useful for testing things, e.g. uploads of various sizes):

Did some googling a came up with using ‘dd’… it’s long, hard to remember, and a bit hard to read. For example, if you want a junk ~50mb file:

$ dd if=/dev/random of=./fifty.junk bs=1024 count=50000

that says ‘in blocks of 1024 bytes (1kb, the Block Size) read 50,000 blocks from /dev/random (the In File) and write them to ./fifty.junk’ (the Out File). It works, but a bit unruly. I just wanted to say ‘make a 50mb file.’ So as I was about to write a script to wrap dd named ‘mkfile’ and discovered this:

$ mkfile 50m fifty.junk

Perfect. Size suffixes make sense (b,k,m,g) and very easy to remember. It isn’t installed by default on my Linux (Ubuntu) but it’s on my Mac, so I’d guess it’s in BSD as well. 

2) Bash Math

bc is a simple calculator (Bash Calculator I assume). You can pipe stuff into it. 

e.g. $ echo ‘(20 * 45) / 7’ | bc

will print 128

you could do it with ruby too (or a myriad of other scripting languages), e.g.

$ ruby -e ‘puts (20 * 45) / 7’

will also print 128.

That’s all too much typing. So I wrapped bc in a script called ‘calc’. Now I can just go

$ calc 20*45/7 

and also have 128 printed. Handy. (If anyone knows of an existing just-as-simple solution like mkfile was, please share).

Here it is, copy it to a file called ‘calc’ (no file extension) somewhere in your path (like /usr/local/bin) and make it executable (chmod +x calc)

#!/bin/sh

join=""

for arg in $@; do join=”$join $arg”;done

echo `echo $join | bc`

Enjoy!

Year 292M is the next Y2K

In pursuit of what we can safely use as the infinite future on date comparisons:

scala> val t3 = new Timestamp(Long.MaxValue)

t3: java.sql.Timestamp = 292278994-08-16 23:12:55.807

Yup - that’s year two hundred ninety two million and a lot.


by comparison here’s today. 


scala> val t1 = new Timestamp(System.currentTimeMillis)

t1: java.sql.Timestamp = 2011-05-04 22:58:11.658


So sometime during August 16th, year 292,278,994, longs will no longer fit the current date and everyone still stuck on JVM 1.6 will be facing yet another Y2K style crisis. Good to know?

(I feel like there must be a joke in here somewhere… I’m open to suggestions :) )

OO fail - isn’t that what param types are for?

Potential runtime error of exactly the type the compiler is supposed to catch. 

(I know *why* in Java it has to take a Date and can’t specify a Timestamp object, but that’s a language (and potentially library) design error. I wonder how/if I could solve this in Scala….)

from: http://download.oracle.com/javase/6/docs/api/java/sql/Timestamp.html

 intcompareTo(Date o) 
          Compares this Timestamp object to the given Date, which must be a Timestamp object.
Keeping it real in the dtes

Keeping it real in the dtes

history meme

Haha great idea alex. This is like a programmer’s version of those stupid ‘what are your favourite <blahs>” forwards. Here’s mine, post yours!


Pauls-IcinTosh:Darkhorse paulrl$ history | awk '{print $2}' | sort | uniq -c | sort -rnk1,1 | head -n 20
143 hg
141 cd
79 ls
26 rake
14 ack
13 touch
11 pwd
10 java
 7 ssh
 5 sudo
 5 sc-server
 4 which
 4 script/console
 4 mate
 4 bin/cassandra
 3 sc-build
 3 clear
 2 mv
 2 mkdir
 2 irb

mrtoto:

things I use:

quicksilver:~ $ history | awk '{print $2}' | sort | uniq -c | sort -rnk1,1 | head -n 20 
    244 hg
     48 cd
     35 nmap
     34 ls
     15 sudo
     14 vim
     13 pwd
      9 man
      9 clear
      8 rm
      7 find
      6 cp
      5 ssh
      5 ps
      4 python
      4 less
      4 history
      3 whois
      3 kill
      2 wget

Just finished my last exam of my degree. (and I think I killed it). Just wanted to let it be known :-D