amix.dk. Has some code segments, which might be interesting to look at if nothing else.
This page pointed out a bizarre but perfect way of fixing readline on mac. Apparently the GNU license doesn’t play nice for Apple so it doesn’t work by default. I did this:
sudo easy_install ipython sudo easy_install -f http://ipython.scipy.org/dist/ readline
And suddenly readline worked in ipython on mac.
Very odd, but also quite interesting industrial design. Reading this made me realise that sorting these entries by date is silly. I’ll fix this sometime.
I was shown an optimization solver that ran fine with certain parameter sizes, yet started segfaulting with larger problem sizes. It turned out that a desired single large, amorphous array could not be allocated within the available stack size limit. Increasing the stack size limit via ulimit -s 50000 (for example) fixed the problem.
You can view a shell’s resource limits using, for example,
monolith> ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) 6144
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 256
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 266
virtual memory (kbytes, -v) unlimited
Peregrine espresso in Washington, DC (map). The best espresso I’ve had in the US.
Useful page with git configuration details.
travelocity done right: ITA software.
After adding a VPN on mac, you might find it doesn’t really work. Add a new (ethernet, say) interface with network settings, and pick an address on the VPN’s subnet. Then you’ll be able to use services on that server by explicitly referring to that IP.
Sadly, mac’s ‘seemless user interface’ doesn’t seem to carry over to leopard server…
(Only) somewhat ok page about re-raising exceptions.
Set up a new tracked repository.
git remote add remotename username@server:~/repo/
Expire a user’s password, requiring them to change it immediately upon their next login:
passwd -e username
Nice looking free fonts: exljbris and Gentium.
Leopard irritatingly prevents you from creating an ssh tunnel to another computer and then connecting a samba share to your localhost. Get around this by first creating an alias for your localhost interface:
sudo ifconfig lo0 alias 127.0.0.2 up
Then, forward the ports via ssh, eg with
sudo ssh -N -L 127.0.0.2:139:localhost:139 -L 127.0.0.2:445:localhost:445 user@server.com
Finally, connect using Finder to smb://127.0.0.2/sharename.
Paste last executed command in vim: ":p.
Nice way of having two different kinds of syntax highlighting within one file, with vim.
Great setup guide for openvpn. Goes well with Tunnelblick.
Check for common memory errors in C with valgrind. Also profile cache misses and branch mispredictions.
Sample usage:
# Check memory accesses. valgrind --tool=memcheck ./prog # View cache and branch profiling information. valgrind --tool=cachegrind ./prog
For more detailed output from valgrind, add the -g tag to your gcc compilation flags to add debugging information to the binary.
The key component of psfrag is the position specification. Here is the relevant syntax:
\psfrag{tag}[position]{Replacement text}
The position is up to two letters; one from {t, b, B, c} (top, bottom, baseline, center) and one from {l, r, c} (left, right, center). Center is assumed if either is omitted.
Infinite labs: excellent little applications for mac, including PlugSuit and Afloat.
Nice color scheme for vim: ir_black.
Disable highlighting of spurious _ and ^ symbols in LaTeX files as errors (say, when a macro is used to start equation environments).
autocmd Filetype tex syntax clear texOnlyMath
Use multiple processes (and hence cores) with make by using make -j.
Disconnect quickly, even when ^d is not allowed, with ~..
A quick way of finding out where a Python package lives:
>>> import pylab >>> print pylab <module 'pylab' from '/usr/lib/python2.5/site-packages/pylab.pyc'>
Run a Python script through a profiler, then interpret the output. I don’t think it’s worth the bother going through iPython; I couldn’t get %run -p to work properly.
At the shell:
> python -m cProfile -o outprof.tmp examples/bb30.py
Then, in iPython:
>>> import pstats >>> p = pstats.Stats('outprof.tmp') >>> p.strip_dirs().sort_stats('cumulative').print_stats(50)
A reminder of how tee works comes from hunterdavis.com.
./prog | tee >(gzip > logfile.tgz)
From this blog, where there is an installer for ipe for mac, it seems that to convert back from a pdf to an eps the following is required.
gs -dBATCH -dNOPAUSE -dNOPROMPT -sDEVICE=epswrite -sOutputFile=new.eps old.pdf
find and sed operate slightly differently on a mac. Here’s some code that replaces 4.3 with 4.4 in all Makefiles, recursively.
find . -name 'Makefile' -exec sed -i -e 's/4\.3/4.4/g' {} \;
The numbered register "0 contains the text from the most recent yank command, while the numbered register "1 contains the text from the most recent delete or change command. If the delete or change was ‘small’, though, (ie, less than one line), the small delete register "- is used instead.
This means that if you yank some text to move it elsewhere, then rearrange some stuff (including deleting, say, newlines), you can still easily retrieve the text that you yanked with "0p.
I made some aliases for use when writing
documents. Add these
(perhaps unwieldly) lines to your .bashrc:
# Next command on a single line. alias lr='latex -file-line-error-style -interaction=nonstopmode $LR.tex > /tmp/latexoutput || cat /tmp/latexoutput ; grep -e "\(LaTeX Warning\)\|\(Overfull\)\|\(Underfull\)" /tmp/latexoutput | grep -v "There were undefined references"; killall -SIGUSR1 xdvi.bin 2> /dev/null' alias xdj='xdvi -paper us -expert -keep $LR.dvi 2>/dev/null >/dev/null&'
Note: depending on your system, you made need to replace xdvi.bin with xdvi-xaw3d.bin.
Then, when you are preparing a document, you can do this:
> LR=myfilename # set filename. The suffix .tex is added automatically. > lr # compiles your latex document. > xdj # displays your latex document.
This sounds pretty ordinary, but these aliases take advantage of these things:
lr will only show the output if there was a problem. This avoids polluting your screen.
lr will never stop with an error while running
and leave you punching
keys in the hopes of getting back to the command line.
will tell you the line number of any errors.
lr will automatically kick xdvi after compiling the document to show your changes. No need to click on xdvi or wait for it to notice the file changed. I really like the way xdvi permits such updates without flickering.
To see the assembly instructions generated for a piece of C code, use this:
gcc -c -g -Wa,-ahl src.c
Find out the macros, and values, predefined by gcc (includes useful things like __INT_MAX__).
gcc -dM -E - < /dev/null
At http://code.google.com/apis/chart/. Nice charts, like this one.
You generate these by going to a specially written url such as http://chart.apis.google.com/chart?cht=lc&chs=200x125&chd=t:50.0,5.0,4.0,93.0,17.0,18.0,13.0,15.0 for the chart above. It looks like it would be a bit of work to translate from a particular application to this api, though.
Sampling from a discrete distribution, where p is a vector of probabilities:
min(find(rand() < cumsum(p)))
Woah, typing s/search/repl/ in a Skype conversation actually performs a replacement for both parties on your last message (only). You can also remove the last messages with s///. It turns out you can also do the same by right clicking.
Have a look at this bizarre Matlab behaviour:
>> 1 / [1 2 3]' ans = 0 0 0.3333
Apparently, this is how they wanted it. Excusing the use of
as if it were mathematics, we have the equivalence:
leading to the bizarre conclusion that in Matlab,
Of course, the syntax that I really wanted was 1 ./ [1 2 3]'. This is fully consistent with Matlab’s elementwise operations, but would it be so bad if 1 / [1 2 3]' just did not work, especially rather than silently giving you something totally weird but the same shape?
I’ve often tried to use find, but have never really got over its syntax. It seems that it’s one of those powerful tools that’s not necessarily obvious to use at first. Here’s one way to use it:
find . -name '*.sw*' -print
prints filename which have .sw in them (say, leftover vim swapfiles).
You can combine this with grepping:
find . -name "*.bib" -exec echo {}; grep "tribute to" '{}'
looks for the words ‘tribute to’ in files with the extension .bib.
Nice page describing enhancements vim has for Python. Will try the omni-complete from this page soon.
Exceedingly useful for cutting and pasting from the clipboard in vim without indentation problems: :put +. (More info.) Depending on your system, :put * might be what you’re after instead.
Version 4.3 of gcc, apart from significant improvements, has this nice feature:
> gcc -c -Q -Os --help=optimizers The following options control optimizations: -falign-jumps [disabled] -falign-labels [disabled] -falign-loops [enabled] # ---8<--- -fwhole-program [disabled] -fwrapv [disabled]
A few code snippets for timing in C. First, tic() and toc() functions. These work like Matlab: tic() starts the timer, and toc() stops it and gives formatted output. There’s also a tocq() function which just returns the number of elapsed seconds.
#include <time.h> static clock_t tic_timestart; void tic(void) { tic_timestart = clock(); } float toc(void) { clock_t tic_timestop; tic_timestop = clock(); printf("time: %8.2f.\n", (float)(tic_timestop - tic_timestart) / CLOCKS_PER_SEC); return (float)(tic_timestop - tic_timestart) / CLOCKS_PER_SEC; } float tocq(void) { clock_t tic_timestop; tic_timestop = clock(); return (float)(tic_timestop - tic_timestart) / CLOCKS_PER_SEC; }
A bit of code for counting flops: first, a statistics structure, then some defines.
/* CFDIV divides 1/a[3] * CFADD adds c[12] + d[12] * CFMUL multiplies b[4] * h[7] * CFASN assigns A[5] = 0 * CFSTO stores A[5] = (...) * CFTFR transfers A[5] = b[7] * CFNTF negated transfers A[5] = -b[7] * CFCOM compares c[5] < b[7] */ typedef struct statistics_t *statistics; typedef struct statistics_t { long div; long add; long mul; long asn; long sto; long tfr; long ntf; long com; } Statistics; #define CFDIV(i) if (countflops) stats->div += i #define CFADD(i) if (countflops) stats->add += i #define CFMUL(i) if (countflops) stats->mul += i #define CFASN(i) if (countflops) stats->asn += i #define CFSTO(i) if (countflops) stats->sto += i #define CFTFR(i) if (countflops) stats->tfr += i #define CFNTF(i) if (countflops) stats->ntf += i #define CFCOM(i) if (countflops) stats->com += i