Running SublimeText 2 from Terminal on Mac OSX
by admin on November 7, 2011
Invoke the following command:
$ sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/bin/subl
Now, you can use something like:
$ subl .
to open up current folder with SublimeText
Automatically Setting Terminal’s Window Title to Current Path
by admin on November 6, 2011
While in hacking mood (read Terminal mode), I often end up using multiple terminal tabs. Switching between the tabs are a little pain as every terminal (at least, those I know of) set their title to some non-sense static text. I wanted to have the title showing the current path so that I don’t have to switch between all of them to find the tab I’m looking for. After spending an hour or so, I came up with something as simple as this. Google wasn’t that much helpful to find this out easily.
Append the following lines to your ~/.bashrc or ~/.bash_profile or whatever your are using for dumping your bash configs.
--- >8 --- >8 --- >8 CUT HERE ... >8 --- >8 --- >8
settitle ()
{
echo -ne "\033]0;${PWD/$HOME/~}\007"
}
PROMPT_COMMAND=settitle
export PROMPT_COMMAND
--- >8 --- >8 --- >8 ... TO HERE >8 --- >8 --- >8
Setting up ssh public keys and adding an alias
by admin on September 12, 2011
This post is sort of a ‘note-to-myself’ post. For my Computer Science class, I have to do a lots of ssh-ing into remote host – my university server . I got tired of typing username and password every time I try to connect from home (using my MacBook Pro). I’ve seen people using an alias without even typing a username, password, and a hostname. I’ve once set up the ssh keys on my HP laptop but after I sold the laptop (I wiped out everything before selling
, I’ve been lazy setting up a keys; no more.
Here are the steps I did.
Let suppose our remote server (in my case, university computer) is called server.universityname.edu, your usual username is foouser, and you want to give an alias sshserv to connect to the remote server using ssh.
1. Create a local ssh key on your local computer
$ ssh-keygen -t -rsa
There are other algorithms you can use to create your ssh key. I’m using rsa for this tutorial. ssh key algorithms and secure algorithms are too broad to be covered in this tutorial.
Anyway, you should have a id_rsa.pub file inside ~/.ssh folder. Do
$ ls ~/.ssh/
and make sure you have a id_rs.pub file
2. Copy the public file to your remote server:
$ scp ~/.ssh/id_rsa.pub foouser@server.universityname.edu:.ssh/authorized_key_local
You will be prompted for password. Use your usual ssh password.
3. Log in to your remote server to manage the key:
$ ssh foouser@server.universityname.edu
Again, you will be prompted for a password.
4. Concatenate the contents of ~/.ssh/authorized_key_local to ~/.ssh/authorized_keys:
$ cat ~/.ssh/authorized_key_local >> ~/.ssh/authorized_keys
5. Remove the ~/.ssh/authorized_key_local file which is not required anymore:
$ rm ~/.ssh/authorized_key_local
6. Logout from the remote server:
$ exit
7. You are now set so that you don’t need the password every time you ssh into your remote server. Verify this by:
$ ssh foouser@server.universityname.edu
At this point, you shouldn’t be asked for any password. If you are prompted for a password, please make sure your properly followed this tutorial up to this point.
8. If you are in your remote server, exit so that you are on local computer:
$ exit
Now, let’s setup an alias.
1. Edit your ~/.ssh/config file to add the following. If the file doesn’t exist, create it first.
#The Host is the alias that you want to use
Host=myremoteserv
#The Hostname is the real hostname of the remote server
Hostname=server.universityname.edu
#The user is your username
User=foouser
2. Save the file and try:
$ ssh myremoteserv
You should be able to login to your remote server.
3. If you want to save 3 keystrokes every time you ssh using above command, you can add an alias for the whole command in your ~/.bash_profile file:
alias sshserv="ssh myremoteserv"
4. To use the alias ‘sshserv’, either restart the terminal or update your bash profile:
$ source ~/.bash_profile
5. Now, you can login to your remote server by just using:
$ sshserv
Happy ssh-ing!
CoreWLANWirelessManager Porting Completed
by admin on February 13, 2011
Yay!
After working my ass off for two days, I finally finished porting CoreWLANWirelessManager sample from Apple’s Official Reference Library (http://developer.apple.com/library/mac/#samplecode/CoreWLANWirelessManager/History/History.html) to MonoMac. This was my first time working with Cocoa+MonoMac, and the experience wasn’t that bad. As I was trying to mimic the behavior, naming convention, and style of the official sample, it took me more time than expected. Nevertheless, the coding was a breeze – only couple of times I got stuck. During this time, I was also able to find a bug in MonoMac related to some threading issue (my guess).
Anyways, it feels super awesome to finish a Mac Application in a language that I love (C#) and then distribute the source code for the open source lovers to play, and learn from it. The source code is hosted on github: https://github.com/ashokgelal/CoreWLANWirelessManager
Get your namespace right at first place
by admin on February 5, 2011
Esp. if you are working with MonoDevelop+Gtk#. Believe me it is more painful than getting your balls pinched by someone. I never had this experience (getting the balls pinched) but yes couple of times I’ve been hit with cricket balls, and today’s experience with refactoring/ renaming namespaces was more painful than those hits.
First Python Script: Header Appender
by admin on January 31, 2011
I started learning Python just yesterday and I’m not only making some good progress but also just finished writing my first ever Python script that processes a bunch of *.cs files and appends a header to each files (basically a copyright notice, and a license – Apache 2.0 License in this case).
So, this turned out to be pretty good and pretty productive. I needed a similar kind of script for processing my C# files that I’ve written for my NetFilterFramework. This framework basically allows you to filter a list based on some binary expressions criteria. You just have to create a string expression such off a public property of a class e.g. Name property of a Student class.
Writing this first ever Python Script was fun. I starting was very rough and edgy. I used IDLE at first to see how it goes and then ran a number of tests on some dummy files to see the results. All went fine with some minor problems. The big stumbling block was command line parsing. Although Python’s inbuilt command line parsing (using OptParse) is super awesome, the manual on their site was not that help and too verbose. So, I needed to take the help of some external sites. So was for recursively traversing a folder to read all the files. Following sites turned out to be very helpful while writing this script:
http://www.alexonlinux.com/pythons-optparse-for-human-beings
http://code.activestate.com/recipes/499305/
http://stefaanlippens.net/getcwd
And of course stackoverflow.com is always there. Thanks to heavens for this internet thing.
Read the rest of this entry »
The Greatest Excuse!
by admin on January 30, 2011
