When Brains Fly

An Awesome Blog About Neuroscience, Computer Science, and Technology

It’s kinda funny that I have only been updating lately when something goes wrong with my computer. Oh well, until I have more time, that’s how it will be.

Lately, my hard drive has been having major startup problems. It would whir and clackle when trying to start after a night or a few hours off and would usually not get detected by my laptop until after ten or fifteen tries to start. So today, I went over to a good friend’s house and swapped my failing hard drive with an old hard drive that he was no longer using. It ran fine in my computer and mine wouldn’t run in his computer so it was the hard drive that had problems and not my good old laptop.

After returning home, I put in the windows 7 repair disk I made yesterday to reinstall Windows. The first few tries didn’t work apparently because my external hard drive was attached. After it loaded, I plugged in my external, loaded the system image that I made yesterday, and replaced the contents of my friend’s hard drive with the image.

Once that finished (and a couple restarts), I used the Win7 backup tool to get all of the files and directories in my data partition back. That didn’t seem to restore everything (visibly, the positions of my desktop icons weren’t restored, but there were other problems) so I sent my system back to the restore point made during the system image/backup yesterday. That fixed the desktop icon positions, but:
1) my Windows Explorer “Favorites” in the sidebar was empty and I could not modify it or restore its contents to the default,
2) (minor) the folder icons for special folder such as “My Music” and “My Documents” didn’t appear, and
3) (minor) in the control panel, all of the user images except for the guest one were blank – changing the picture did change the picture elsewhere on my system, but for some reason the frame showing the current picture in the “control panel” > “add or remove user accounts” was white, even after creating a new user and selecting a picture.

I dug for solutions on the interwebs and remembered that Favorites actually maps to Links in my Users/ directory (not intuitive at all). Once I made that folder, right clicked “Favorites” in the sidebar, and selected “Restore favorite links,” the folder populated with the three default links and I could modify its contents! I was ecstatic since I use the shortcuts that I place there frequently. Also, moving “My Documents” and “My Music” around and back to my E:\ brought back the appropriate icons. I have yet to find a fix for the user image problem, but that doesn’t really affect anything.

Edit: Also had to make all of my data in E:\ not read-only in order to do certain things. Not sure why it was read-only before.

So in case I ever do this again (likely) or any of you do, I hope this helps. =)

Installing Windows 7

[ September 28th, 2009 ]

Through my university’s membership in the MSDNAA program, I acquired Windows 7 Professional for free! Whoo! I backed up my laptop yesterday onto my external hard drive (took up 16gb) and am installing Windows 7 now (which takes about 16gb!), wiping out everything. Hopefully it goes well.

Started around 5:45 or so.

Update 5:50pm – I reformatted my hard drive using the disk utility in the install dvd but was unable to create and resize partitions, which kinda sucks, since I was planning on keeping a separate partition for my OS and for my data. Maybe I can do it after finishing the installation, using the Disk Management Tool? Maybe?

Update 6:05pm (ish) – Done! Now configuring computer settings.

Update 6:10pm (ish) – Windows Update running.

Update the next day – All is working fine and all of the important and relevant files in my life today have been migrated over from my external. I had some annoyances with partitioning but I think it will be okay. The new directory structure and windows explorer sidebar is going to take a little getting used to from XP. The jump lists are pretty cool, and I will probably spend a good chunk of today reading through the many Lifehacker posts on the cool new features in Windows 7. I’ll also be trying to keep my desktop clean and clutter-free as well! Only the recycle bin and very temporarily relevant/important files will be there. I hope I can keep that up. Overall, Windows 7 is pretty sleek and a nice upgrade from XP. I haven’t tried any of the new functionality yet, but appearance- and usability-wise, I like it.

Update the morning after the next day – It seems that adding shortcuts to a folder in the Start Menu is difficult when not logged in as an administrator. I tried to create a shortcut to CCleaner in a new CCleaner folder I made in the Start Menu programs folder, but Windows said it could not be done and asked me if I wanted to make one on the Desktop first. I said yes and it did so after prompting for the admin password, and then I moved the Desktop shortcut into the CCleaner folder in the Start Menu programs folder. It worked (with admin password) and created a new shortcut there. I made sure that the new shortcut pointed to the original .exe file and then deleted the one on the Desktop.

It’s weird that I had to use the Desktop as an intermediate copy area in order to create the shortcut; it probably has to do with problems requiring admin permission for more than one step of the process or creating a shortcut from an admin-only area to an admin-only area. I never used a non-administrator account with XP so I don’t know how that worked before, but this is kinda odd. By the way, I am using a non-admin account for an extra level of security, as recommended by Coding Horror.

Theme Updated and Miscellaneous Code

[ August 22nd, 2009 ]

I wasn’t really liking the Brain Power theme anymore, so I decided to make my own using the handy-dandy WordPress Theme Generator and then tweaked the details to my liking. It looks better now, in my opinion.

Hopefully these changes plus the smackdown on spam will encourage me to blog some more. (Comments will still be moderated until I am sure spam is under control.)

Now for some miscellaneous things:

In the meantime, for my reference, I like to keep two aliases for my bash shell:

alias ll='ls -l'
alias ls='ls -aG' # for the BSD ls
alias ls='ls -a --color=auto' # for the GNU ls

I also like to change the default color for directories (blue) to cyan when in BSD (cyan foreground not otherwise used) so that I can see it better.

export LSCOLORS="gxfxcxdxbxegedabagacad"

In GNU ls, there is a different method and cyan is used for symbolic links, so rather than have two different colors for directories, which I see far more often than symbolic links, let’s change the directory color to blue and symbolic link color to yellow:

—-I’ll finish this up soon—-

For compiling a Java program using Cygwin and including the jxl.jar library (typical bin, lib, src setup):

#!/bin/bash
javac -cp `cygpath -wp lib/jxl.jar:.` -d bin $(find src -name '*.java')

For running a Java program using Cygwin and including the jxl.jar library (two parameters passed):

#!/bin/bash
java -cp `cygpath -wp lib/jxl.jar:src/:.` main.class.Name $1 $2

For running the above Java program on a Mac without the Mac top menu bar and with a specified dock name:

#!/bin/bash
java -cp lib/jxl.jar:src/:. -Dapple.laf.useScreenMenuBar=true
-Xdock:name="Program Name" main.class.Name $1 $2

Note to self: <pre> tags do not have word wrap. Consider using a special scrollable text field or plugin for displaying code.

Finally, I have upgraded to WordPress 2.8.4 and installed Akismet seemingly successfully. Spam be gone! I also set up svn upgrading of WordPress so that I don’t have to do so many steps next time around.

For reference, I used:
http://codex.wordpress.org/WordPress_Backups to backup my stuff first
http://codex.wordpress.org/Upgrading_WordPress to do the upgrade
And then realizing that I could upgrade by svn, I used http://codex.wordpress.org/Installing/Updating_WordPress_with_Subversion. Very nice.

Update: It has been nearly 24 hours and I have gotten no spam comments to moderate in my inbox. Akismet caught 8 of them. Thank goodness. That was really annoying to see a new email every couple hours only to realize that it is spam. Kinda makes me really appreciate Gmail’s spam filter, even though it has screwed up somewhat majorly once.

Edit (2009-12-15):
To upgrade to the latest stable version of wordpress via svn, run the following command from /home/public/ (assuming 2.8.6 is the latest stable version):

svn sw http://core.svn.wordpress.org/tags/2.8.6/ . 

and then go to http://www.whenbrainsfly.com/wp-admin/upgrade.php

Usefulness

[ July 31st, 2009 ]

I think this blog has paid off! I’ve used what I wrote in this post on remote desktop many times already because I just can’t remember how to do it right whenever working with a new mac. Plus, it is now the first result when you google “remote desktop into mac os x”, even without quotes! Too bad most of the comments I get around here are spam. So far, there have been 3 real comments (I think) and 124 spam comments. Joy.

An Update

[ June 25th, 2009 ]

OMG Why do I get so much spam and no real comments?! Ugh.

Anyway.

TODO list for this site:

  • update blogroll
  • maybe change the images
  • make link to comments more visible from front page (e.g. at end of post)
  • update biographical info
  • add $$ to web hosting account
  • make text less wide looking
  • add adsense?
  • Make top links more distinctive or move them to the right side
  • make lists not indent so much within a post

args4j is Awesome

[ May 28th, 2009 ]

Today, I got frustrated writing a command-line input parser for my Java program for lab, so I looked for one on the web. Surely a task so common must have some good libraries that take care of it easily. I was not disappointed.

Apache Commons has one, but it was kind of annoying. It left a lot for me to do. I kept looking and found args4j and thought it looked really neat. It makes good use of Java 5 annotations, which I have seen in action when writing a class JSF project. I tried it out, and after a little trouble learning what the annotation parameters meant (hint: see the javadoc for @Option), and with the help of Eclipse’s automatic getter generator, I got my command line parser up and running in minutes! Ah, the magic.

Here is the code, simple and sweet:

CommandLineValues.java:

import java.util.Random;

import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;

public class CommandLineValues {

	/** Max value for the random seed (minimum is 0). */
	public static final int MAX_RANDOM_SEED = 1000;

	/** Valid options for the experiment type */
	public static enum ExptOption {
		DEGREES,
		FEATURES
	};

	@Argument(required = true, index = 0, usage = "type of experiment")
	private ExptOption exptOption;

	@Argument(required = true, index = 1, metaVar = "FILE",
			usage = "the config file for the experiment")
	private String configFileName;

	@Option(name = "-r", aliases = { "--resultsDir" }, metaVar = "DIR",
			usage = "directory to place the results file")
	private String resultsDir = "results/";

	@Option(name = "-s", aliases = { "--seed" }, metaVar = "VALUE",
			usage = "seed to use for the program's random number"
			 + generator")
	private int seed = (new Random()).nextInt(MAX_RANDOM_SEED + 1);

	// getters for all of the fields
}

The first and second arguments (exptOption and configFileName) are required; their order is set by the index parameter. The other two arguments are optional and have both a short single-dash flag (the name parameter) and a longer double-dash flag (the aliases parameter, which can contain any number of strings). The metaVar parameter describes the type of the argument in short, and the usage parameter describes the value of the argument.

Here is code showing how CommandLineValues.java is used.

Main.java:

public static void main(String[] args) {

	// parse the command line arguments and options
	CommandLineValues values = new CommandLineValues();
	CmdLineParser parser = new CmdLineParser(values);
	parser.setUsageWidth(80); // width of the error display area

	try {
		parser.parseArgument(args);
	} catch (CmdLineException e) {
		System.err.println(e.getMessage());
		System.err.println("java DotsMain [options...] arguments...");
		// print the list of available options
		parser.printUsage(System.err);
		System.err.println();
		System.exit(1);
	}
	// use the getters
}

Awesome! =)

Creating a Seam Project

[ February 25th, 2009 ]

Today, my goal was to integrate Seam functionality into my group’s jsf project. The easiest way seemed to be to create a new project and gradually copy and paste code over to the old project. This would allow us to remove unnecessary or inefficient code that Seam would take care of for us and would let us better learn Seam. Unfortunately, setting up Seam was no walk in the park. Rather than go through every agonizing step that I took to get to an empty Seam project running, I’ll just list some pitfalls and workarounds.

Pitfall #1: Most of the contents of JBossTools 2.1 is incompatible with Eclipse Ganymede 3.4.
- Workaround: Use JBossTools 3.0 or downgrade to Eclipse Europa 3.3

Pitfall #2: Bad JBossTools 3.0 mirror. This was unbearably frustrating because I didn’t even think that that could have been a problem. I ended up installing a slightly newer version of Eclipse 3.4 (SR1) and getting it to install there before reading a note that said that the error I got was most likely due to a bad mirror.

Pitfall #3: java.lang.IllegalStateException: No phase id bound to current thread (make sure you do not have two SeamPhaseListener instances installed) when trying to run a new, empty Seam project. Note that everything is pretty much out-of-the-box at this point. Why didn’t it work?! Seam 2.1.1 (or maybe just 2.1) is sometimes incompatible with JBoss AS 4.2.3.
- Workarounds: Build and use JSF 1.2_10, use JBoss AS 4.2.2, remove jboss-seam from MANIFEST.MF and add it to project classpath manually (doesn’t work, despite what some forums say), download specially modified jsf jars

Pitfall #4: Make sure there is cheap web hosting for the version of JBoss that you select. e.g. JBoss 5.0 is not yet widely supported; better to stick with 4.2 to make sure the code will work for a likely web host.

After about 4 hours of troubleshooting, problem solving, and scouring the web for information, I managed to get an empty Seam project running, using Seam 2.1.1, JBoss 4.2.2, JBossTools 3.0, JSF 1.2_09, and Eclipse 3.4 SR1. It should not take that long. Common mistakes and pitfalls should be well documented on the JBoss and Seam website, especially Pitfall #3.

Now, I can begin the task of moving code over to the new project. Joy of joys.

Using remote desktop, you can access one computer from another computer through the internet or a local area network. Here, I’ll outline how to remote desktop into Mac OS X 10.5 (Leopard) from Windows, which is something I had to do today.

On the Mac, go to System Preferences > Sharing and check “Remote Login,” if it is unchecked. You may get a message saying that your current power settings will not allow remote login when the Mac is sleeping. Just hit OK for that and Take note of the example ssh command given in the information area.

Then check “Screen Sharing,” if it is unchecked. Click the “Computer Settings” button on the right. A prompt should appear. Check “VNC Viewers may control screen with password” and type in a memorable password. Then hit OK and uncheck “Screen Sharing.” This is a security precaution. You will turn this on later when you ssh in.

On your PC, you will need to install PuTTY and TightVNC. You can get PuTTY here: http://www.chiark.greenend.org.uk/~sgtatham/putty/ and TightVNC from here: http://www.tightvnc.com/download.html.

On your PC, open up PuTTY, and in the “Host Name” field, type in the host name of the computer. This is the text after the @ symbol in the provided ssh command example noted earlier, e.g. my.host.name.edu. Select SSH as the connection type.

Then, on the left category menu, click on Tunnels, which is under Connection > SSH. For the “Source Port” box, type 5901, and for the “Destination” box, type localhost:5900. Then hit the Add button. And then hit the Open button in the bottom-right.

A black window will appear and a prompt may appear, asking you whether you trust the host. Click yes. Then, in the black window, you will be asked for your login name – enter your Mac login name. Then it will prompt for your password – enter that too.

Then, enable Screen Sharing by entering the following commands into PuTTY:

cd /Library/Preferences
echo -n enabled > com.apple.ScreenSharing.launchd

Next, open up TightVNC Viewer on your PC. It will prompt you for a VNC Server. Enter localhost:1. (This is possible because you are tunneling Port 5901 through SSH.) Hit "Connect." You should then be prompted for a password. Enter the VNC password that you set earlier.

That's it! A window should appear on your PC with the exact same display as your Mac and you should be able to control the mouse and do most things remotely.

Unfortunately, this method can yield severe lag between the two computers, especially if your Mac's internet connection has a slow upload speed.

One performance tweak you can do on the Mac is enter into a Terminal:

defaults write com.apple.ScreenSharing controlObserveQuality 3

This changes the quality of the remote display to setting 3 which is 8-bit color. The other settings are:
1 = black and white
2 = grey scale
3 = 8 bit color
4 = 16 bit color
5 = full color

Just replace the "3" in the command with the number of the desired setting.

You should probably also change your mac desktop wallpaper to a solid color and/or reduce the resolution so the screen image is more easily compressed.

Finally, before you close the connection, you should disable Screen Sharing. In your PuTTY window, which you must keep active while you are on VNC, enter the following commands:

cd /Library/Preferences
rm com.apple.ScreenSharing.launchd

Edit: Apparently, removal of this file and disabling of Screen Sharing only takes place after you restart the computer. i.e. after you remove this file, you can still vnc into the system. However, I don't know whether you can still vnc into it from a computer different from the one from which you originally vnc'd. You can restart the system immediately (closing all open files without saving changes) with:

sudo shutdown -r now

And that's it! You should now be able to remote desktop into Mac OS X Leopard securely from a Windows machine. Happy remote desktop-ing! Also, please leave a comment below if this was helpful or if you have any questions.

Note: If you have Cygwin installed like I do, then you can just open up a Cygwin shell window and enter:

ssh username@hostname -L 5901:localhost:5900

to ssh in with port forwarding.

Note 2: If you want to be able to access your Mac anytime, go to Energy Saver, which is also in System Preferences, and move the slider for Time Before Sleep to Never. You can also schedule automatic turn on/off of the Mac to save energy, e.g. have it off while you're asleep.

References:
http://lifehacker.com/319528/remote-control-leopard-with-tightvnc
http://www.macosxhints.com/article.php?story=20080318190503111
http://www.alternapop.com/2007/12/01/leopard-screen-sharing-image-quality/

What This Site Is About

[ January 15th, 2009 ]

Now that I finally have a working, styled blog, I can write about what I’m going to write about!

I’ll be primarily writing about two things here on When Brains Fly:

1) my main interest, which is research and technology at the intersection of neuroscience and computer science, in fields such as computational neuroscience, neuroengineering, artificial intelligence, and computer vision; and

2) my adventures in technology, such as how I perform long, complicated technological tasks – in tutorial form – or useful code, for my benefit and the public’s.

And with that introduction, I hope you enjoy my blog!

Proudly powered by WordPress. Theme developed with WordPress Theme Generator.
Copyright © When Brains Fly. All rights reserved.