cpulimit
January 11th, 2010
cpulimit is a program that can be used to limit the peak cpu consumption of processes. It’s a piece of functionality that I would like to be standard. Sadly, cpulimit is a bit shaky – it works best if you start the process and then have cpulimit attach to it.
Following a Stream
January 9th, 2010
Following a stream being written to a file is surprisingly easy.
tail -f <file>
I didn’t know about the -f flag before. It definitely seems useful.
How to Debug mex files in Matlab
January 6th, 2010
I always have to look up the procedure for debugging code in compiled mex extensions in Matlab, so here it is:
shell> matlab -Dgdb
gdb> run -nodesktop -nojvm
matlab> dbmex on
matlab> foo() % Execute the mex function being debugged
gdb> break foo.cpp:17 # Set up breakpoints
gdb> continue
Reordering Screen Windows
January 5th, 2010
Screen windows can be reordered by giving windows new numbers. This is accomplished by Ctrl-A, : to open the command prompt and then giving the command :number <n>.
Dealing with nested screens
January 4th, 2010
The proper way to deal with nested screens (e.g. resulting from sshing from one remote computer to another) is to escape commands using Ctrl-A, as shown in this cheat sheat. To e.g. start a new window in the nested screen, use Ctrl-A, A, C .
Screen and X-Forwarding
December 17th, 2009
After a bit of tinkering with screen I found two major annoyances. First: X-forwarding does not work despite the -X flag being set when opening the ssh connection. Secondly: Shift-PgUp and Shift-PgDn do not work for scrolling (and scrolling is in general a pain).
The first problem seems to have a rather simple solution. Just set the DISPLAY environment variable in .bash_profile once a screen session has been detected.
if [ -n $WINDOW ] ; then
export DISPLAY=localhost:10
fi
Detaching Shell Commands - Take Three
December 16th, 2009
I have now run into a system for which neither of the previous two methods mentioned seem to work. A third method is to use GNU screen. Roughly it is done by:
- executing “screen”
- running the command
- detaching the screen using Ctrl-A, Ctrl-D
However, there is so much more to screen than that. I have had my eye on it for a while, but never made the leap to using it consistently. A couple of handy guides to screen should give some idea of what it can do. I’m going to try out automatically running screen when logging in in an attempt to start using it all the time.
SSH Public Key Authentication
October 24th, 2009
A minor heads up when configuring ssh for public key authentication is that ssh on the local machine only checks ~/.ssh/id_rsa and ~/.ssh/id_dsa for private keys to use public key authentication. Hence, if you have multiple sets of key pairs then you might have to explicitly point to the correct private key using the -i flag of the ssh command.
Exporting from dia to LaTeX
July 10th, 2009
Exporting diagrams from Dia into LaTeX (with LaTeX fonts etc) is quite easy once you figure out how to do it. There are several TeX exporting options in Dia, but this is the only one that I could get to produce satisfying results.
Using Dia 0.97, or later, export the diagram as MetaPost. Then run mptopdf on the exported metapost to get a shiny pdf to include in the LaTeX document.
Exporting Graphs from Matlab
July 8th, 2009
Matlab can be nice for cobbling some plots together. Exporting said plots can be a pain though. Thankfully exportfig.m makes it a bit easier .
Detaching Shell Commands - Take Two
April 10th, 2009
I previously made a note about how one can close standard input to detach a shell command from the terminal. I recently discovered the nohup command, which has a similar purpose.
The nohup command seems to emulate an attached process better. I ran across some obscure behaviour where ffmpeg would fail to decode a video file if standard input was closed, but not if it was left attached to a terminal or if nohup was used.
Including date and time in Thunderbird reply
February 5th, 2009
It is possible to configure Thunderbird to include the date and time of the mail being replied to. I.e. to replace
Foo wrote: > Hello Bar!
with
On 02/05/2009 11:27 AM, Foo wrote: > Hello Bar!
It isn’t done through the configuration dialogs, rather it is configured through user.js (which might have to be created). All one essentially has to do is create a file name user.js containing
user_pref("mailnews.reply_header_type", 2);
in the Thunderbird profile directory.
Complete referrals in Google Analytics
February 2nd, 2009
Referring urls in Google Analytics are stripped from query parameters. This makes it hard to know e.g. what thread a referral came from, since that information is typically contained in the referrer’s query parameters. There exists a couple of workarounds to the problem, which a Norweigan blogger has improved upon.
The final remedy is to edit the analytics account and add a filter. The filter should have the following settings:
- Filter Type
- Custom filter, select Advanced
- Field A -> Extract A
- Referral: (.*)
- Field B -> Extract B
- Campaign Medium: (^referral$)|(^organic$)
- Output To -> Constructor
- Campaign Content: $A1
- Field A Required
- Yes
- Field B Required
- Yes
- Override Output Field
- Yes
Search and replace in multiple files
August 17th, 2008
This is always a nice snippet to have around:
for i in `find . -name '*.ext'`; do perl -pi -e 's/foo/bar/' "$i"; done
It searches the current directory and all children recursively and replaces “foo” with “bar” in all files with names matching ”*.ext”.
Upgrading RubyGems and building binary Windows distributions
July 28th, 2008
I have been using RubyGems 0.9.4 for quite a while, putting off upgrading to 1.* due to the problems it brings with building Gecode/R. The problem is that Gecode/R has a binary distribution with pre-compiled binaries for Windows. The binary distribution has to be marked with its platform to keep it separate from the source distributions. Before RubyGems 1.* this was done by setting the gemspec’s platform attribute as follows
spec.platform = Gem::Platform::WIN32
This however stopped working in 1.*, returning the following error message.
WIN32 has been removed, use CURRENT instead
All Gem::Platform:: constants other than RUBY and CURRENT were removed.
The RubyGems user documentation website hasn’t been updated since 0.8.7, so it isn’t easy to find information on why this change was made or how one should now build binary packages for platforms other than the host platform. Looking at the RubyGems source code however reveals that there is still some legacy support; one just has to avoid using the removed constants. The solution is to set the platform in the gemspec using
spec.platform = 'mswin32'
and things will be back to normal (until the legacy support is removed).