Tuesday, January 31, 2012

Terminal Unmounting

I'm reducing the amount of clicking I do when using my computer. To that purpose, I wanted to learn how to unmount/eject media, either virtual or physical, from the command line instead of having to simulate a right-click by pressing the Ctrl button _ aiming the trackpad to the volume's icon, after having had to find it on the desktop.

So I learned. Simple:
sudo umount /Volumes/Name

and if it's stubborn,
sudo -f umount /Volumes/Name

and if it's stubborner,
sudo diskutil umount force /Volumes/FooBar

Credits:
http://loopkid.net/articles/2008/06/27/force-unmount-on-mac-os-x

p.s: On the same clicking-reduction line, the terminal command "open" will open any file or directory, just as it would by double-clicking on it through the GUI. Yay.

Monday, January 30, 2012

Command line Java NoClassDefFoundError


So I was having trouble with Java. Eclipse worked perfectly, but when I wanted to compile/run from the command line, I always got this:

Exception in thread "main" java.lang.NoClassDefFoundError: Adder/class
Caused by: java.lang.ClassNotFoundException: Adder.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)


So I looked up the error, and found this nice post:
http://www.codegravity.com/blog/noclassdeffounderror

The solution is to include the current path (.) in the classpath, such as:

java -classpath . Adder (Adder is the name of the class).
Tha's it.

Attaching JDK Source Code

So I installed Eclipse on my Mac OS X 10.7 Lion, and everything was working peachy, except I can't see the core JRE source code :(. Can't go into String's or Integer's source code, criticize Sun source code, or figure out what some obscure but potentially useful classes actually do.

So it's not critical. But it's annoying. So today I looked it up, and I think I found the solution. Credit to
https://developer.apple.com/downloads/index.action

and shame on Apple for being so annoying so often.

And in case of broken link, the pasted steps are here:



  • Go to http://connect.apple.com and download Java for Mac OS X 10.6 Update 3 Developer Package




  • Install it.




  • Open a Terminal.app window




  • sudo -s




  • cd /System/Library/Frameworks/JavaVM.framework/Home




  • ln -s /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/src.jar .




  • ln -s /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/docs.jar .




  • Replace for your current versions, of course.

    Hadoop Setup

    So I gotta install Hadoop on my Mac OS X 10.7 Lion, and I start running into some errors. I'm following the official setup tutorial: http://hadoop.apache.org/common/docs/current/single_node_setup.html. To avoid these, do the following:

    • Modify hadoop-x.x.x/conf/hadoop-env.sh with these lines:
    export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    export HADOOP_OPTS="-Djava.security.krb5.realm=OX.AC.UK -Djava.security.krb5.kdc=kdc0.ox.ac.uk:kdc1.ox.ac.uk"

    The first line allows things to run. The second avoids the weird runtime warning
    "Unable to load realm info from SCDynamicStore".
    • Enable ssh to localhost for pseudo-distributed operation:
    Go to System Preferences -> Sharing -> Remote Login -> check little checkbox.

    That's it. Just follow the rest of the instructions and you'll be set up good :).

    Friday, November 18, 2011

    And Randall Munroe too.

    See, that's what I mean when I talk about old-and-solved-but-forgotten problems!
    http://www.xkcd.com/979/
    "History has a way of repeating itself",
    "Let us learn from our mistakes",
    and all that stuff.

    Thursday, November 17, 2011

    Vertical select


    Do you sometimes have a list with columns displayed on your screen or on a text editor, and you only want to select one or a few of the columns, like so?

    Option-Click to the rescue! (On Mac OS X only). Press Option key, click'n drag, copy, paste. Like so!



    Desktop
    Documents
    Downloads
    Dropbox
    ED
    Library
    Movies
    Music
    Pictures
    Public
    Tera
    data
    dev
    nltk_data

    Also works on TextEdit and stuff. Not on browsers. (Not on Chrome, at least). Courtesy of Kaan's facebook post on Nov 16th, 2011:

    just discovered that OSX Terminal supports vertical select (option-click)

    Comparing Directory Structures


    I often face a problem, spend significant amounts of time finding the solution, apply the solution, and then forget it. And when I face the same problem later on, I remember I knew the solution once, but have long forgotten it by then. And I ask myself:

    How the Hell did I do that?

    Hence this blog. And for my first post, directory structure comparison. Handy for anyone who wants to keep data synced across external hard drives, or who wants to make sure that a big copy procedure went well. This is linux-based, it also works on Mac OS X, here goes:
    1. find /path1 -exec basename {} \; | sort > file1
    2. find /path2 -exec basename {} \; | sort > file2
    3. # at this point you can use diff file1 file2
    4. # or
    5. # here we want files only listed in file1 but not in file2
    6. comm -23 file1 file2
    7. # here we show files listed in file2 but not in file1
    8. comm -23 file2 file1
    And the be-nice reference link to where I found it: