foreach (sort { $y{$a} <=> $y{$b}} keys %y) { printf "%60s %4d\n", $_, $y{$_}; }
Rants and ravings of a semi-autistic developer who has a hard time remembering idiotic nonsense details. Why remember it, when you know where to find it.
Wednesday, February 17, 2010
one line sorting hash perl
Onliner for Sorting a hash in perl
Major Minor code of class files
Here a oneliner for finding out the bytecode version. Based on
http://en.wikipedia.org/wiki/Class_(file_format)
http://en.wikipedia.org/wiki/Class_(file_format)
perl -pe 'open(FILE,$_);binmode(FILE);sysread(FILE,$buf,2,6);close(FILE);@c=unpack("H*",$buf);foreach(@c){$s.=sprintf "%s",ord($_);};$_=$s'
or
import java.io.*;
public class ClassVersionChecker {
public static void main(String[] args) throws IOException {
for (int i = 0; i < args.length; i++)
checkClassVersion(args[i]);
}
private static void checkClassVersion(String filename)
throws IOException
{
DataInputStream in = new DataInputStream
(new FileInputStream(filename));
int magic = in.readInt();
if(magic != 0xcafebabe) {
System.out.println(filename + " is not a valid class!");;
}
int minor = in.readUnsignedShort();
int major = in.readUnsignedShort();
System.out.println(filename + ": " + major + " . " + minor);
in.close();
}
}
Aliasing and passing arguments in Bash
rssh() { xargs -i\{} -t ssh {} $@; }
Usage after setting the function:
$ cat list | rssh 'command'
Thursday, February 11, 2010
bash PS1 setup
export PS1="\h \W$"
\w - absolute path
\u - user
\v - version of bash
\s - shell environment
\w - absolute path
\u - user
\v - version of bash
\s - shell environment
Subscribe to:
Comments (Atom)