Posted on December 30th, 2010 in git | 1 Comment »
or better known as “staging patches”.
So you created some new functionality in a file but you have a lot of other code you’re not quite ready to commit yet. Answer:
git add -p . It will interactively go though modified sections of your file asking if you want to “stage this hunk”. Answer y for yes, n for no, q for stop, then commit as usual. You can even split hunks if you want to get more fine-grained.
For more details check out this page.
Posted on December 26th, 2010 in unix | No Comments »
Just finished the 1000+ pager Unix Power Tools, Third Editionbook over Christmas break and found it a pretty good complete general introduction / refresher to Unix / Linux.
I originally passed the book up as it was last updated in 2002 but my interest was piqued skimming it and in the end I found that 98% of it’s contents still relevant today. It was like having lunch with a old-time unix guy – all the command line stuff just runs faster these days and he talks about
screen instead of
tmux, etc. Additionally, interesting history and tips were given on some unix programs (for ways of dropping out of a shell script faster since back in the day CPU cycles were rented).
Less known tidbits
Here are some quick notes I jotted down of some new things I learned:
pushd and popd is a great way of cd’ing to a far away path, and zipping yourself back where you were:
pushd # pop this directory on the "remember" stack
popd # go back to pop directory
dirs # see your pushd paths
I dabble in jailbreaking my phone occasionally and must download the latest jailbreak app off the torrents. This alerts the security professional in me as I have no idea what’s in the compiled code as anybody could have seeded it. The Jailbreak guys always provide an md5 verification hash on their site of their latest build and now I have the capability to validate them:
md5sum filename(s) > savedhash # create hash
md5sum -c savedhash # compare hash
Sometimes I need to modify the output of a program but also want to keep a copy of it’s unmodified output. Tee does that for me in one go.
echo 'hi there' | tee hi.txt | sed 's/hi/bye/'
# outputs 'by there' while saving original string to hi.txt
Cool way to fix command line typos:
-bash: cd: bydirectory: No such file or directory
# returns and executes: cd mydirectory
Can also do:
echo 'hi thereee'
# returns: hi thereee
# returns and executes: echo 'hi there'
Other short tidbits include:
sdiff <i>file1</i> <i>file2</i> # does side by side diff comparisons
split # split large files into smaller files
fmt # text formatter
man -k string # like M-x apropos in emacs
Lastly, put a -xv at the top of your shell scripts to debug them:
Though emacs has the ability to run a shell inside (three different ones actually), anything that requires more than just a “dumb terminal” doesn’t work as well as I’d like in these emulated terminals. My research in finding a solution has lead to some creative answers such as using tmux (thanks Takashi) which on its own solves and improves tons of daily workflow situations. I, however, will dedicate that topic in it’s entirety to another entry as it does add some optional complexity to your workflow; too much if you’re looking to solve just this one problem.
What I really want to be able to do is to be working in emacs on a remote machine (via ssh) with all my windows and buffers setup and to drop down to shell occasionally to look something up or run some other scripts and then move back to emacs at will. This is easy if you’re running emacs on your local terminal on OS X: just like any other process like top, use
C-z to move emacs to a background process and type
fg when you want to move it back to the foreground. All your current windows and buffers are resumed. On the two remote machines I’ve tested
C-z just moved you to the previous line. I’ve tried unbinding that key combo, but all I get is a terminal beep. After some research and hanging around the #emacs chan (thanks insomniaSalt) the answer is to drop this in your .emacs file. Now
C-z will work as it does on your local terminal:
In a previous project I used a bash script in conjunction with a git hook to concatenate all my js files and increment build numbers in html file references (cache-kill) after every commit. This was convenient at first, but quickly got annoying as I wasn’t always committing js file changes. I eventually opted to just call the script manually before any deployment to qa or production, thinking I would automate it again one day to only be called when JS files were changed (git hooks probably provide this info).
I’m optimizing the web views of an iPhone app in preparation for Christmas traffic and one of the ideas I had was to use small increments of Expires header to cache files client-side. I assumed this would be no problem as all my work with Safari on the iPhone has shown it a very capable browser—as good as any desktop one.
Turns out after some testing that using Expires Header isn’t possible— not because of cache size limitations as one would assume. It looks like the guys in Cupertino wanted to limit this ability on the iOS as every HTTP request made by an iOS device issues a pragma: no-cache directive. I’ve yet to understand why. Better fire up more memcache servers.
Here’s the raw headers if interested: