Archive for the ‘inelegant hacks’ Category

Granta Diary 2009

Monday, April 13th, 2009

Problem: The world has gone to the dogs and I can’t lay my hands on the Granta Diary for this year.
Briefly: Create my own, in LaTeX.
Solution: Life trained me to be a planning freak, and Granta gave me a diary that I could actually use. In this space I’ll put down the next installment of the glorious customized LaTeX journal that evolved from my calendars.

Fonts of Fantasy

Sunday, October 12th, 2008

Problem: My thesis requires fonts from Star Trek and Bladerunner, but they’re TrueType and LaTeX does not play well with them.

Briefly: LaTeX is anal about the directory tree. So learn the right directory names and save yourself a bundle of trouble.

Solution: The LaTeX fundus package has Star Trek font; but turns out it doesn’t work with my Ubuntu. So I wrote a script to install a ttf in a local texmf tree. Note that the tex tree conventions
leave you have little flexibility in naming directories. So ${TEXMF}/fonts/tfm, ${TEXMF}/tex/latex/, ${TEXMF}/fonts/truetype, etc. need to be acceptable to tex.
(more…)

Background Brightness

Saturday, October 11th, 2008

Problem: I use windowmaker and think that the brightness setting in bloatier window managers are a Feature I Want ™.
Solution: Change gamma of the picture before setting it with wmsetbg. And to use goog cache as my backup Tool of Choice ™, the nifty script that does little but does it well ™ is here, lol.

wmsetbgbright.sh

#!/bin/bash -x
usage () {
echo ${0} \ \[gamma\] \[wmsetbg options\];
}

BGDIR=${HOME}/GNUstep/Library/WindowMaker/Backgrounds
if [ ${#} -lt 1 ] ; then
usage ${0}; exit;
else
IMG=${1}
GAMMA=${2}
OPTIONS=${@:3}
fi

IMGDIR=`dirname ${IMG}`
IMG=`basename ${IMG}`

convert -modulate ${GAMMA} ${IMGDIR}/${IMG} ${BGDIR}/wm-${IMG}
wmsetbg ${OPTIONS} ${BGDIR}/wm-${IMG}

Virtual Cocktail Party

Thursday, August 7th, 2008

Problem: I want a cocktail party NOW!!!

OK: play multiple media/audio streams dynamically localized in space.

Briefly: Compile spatialization plug-in for mplayer and run multiple instances with different parameters.

Solution:
It’s a hack, it’s a fix, it makes for a real party, especially when you play those a o scott podcasts — with the same person going on in three streams!

Compile the filter into mplayer, by putting in af_spatialize.c in the list of audio filters compiled in libaf:

Code af_spatialize.c
Header carried over from af_hrtf.c listing some constants af_spatialize.h
Header with head-related transfer functions for various directions hrtf_22050_3.h

With the spatialization plugin, a file can be localized at angles compiled into the plugin.

cocktail.sh 45 file1.mp3 &
cocktail.sh -45 file2.mp3 &

#!/bin/bash
IFS=#
~/mplayer/mplayer -af volnorm,resample=22050,spatialize=${1} ${2} 2>&1 > /dev/null &

LaTeX/bash Calendar

Monday, February 18th, 2008

Problem How do I create a manageable calendar that:

  • Is on paper, because I’m cool
  • Has my weekly schedule, so I don’t rewrite my schedule every week
  • Has customizable daily schedule
  • Has space for general todo lists
  • Has space for regular todo lists, e.g. research and course commitments
  • Is cool

Weekly calendar jpeg preview

Briefly LaTeX/Python Planner post makes it easier to generate this. Go read it instead. Use bash to generate the dates; and use latex command definitions to insert weekly schedule. A list of reminders (TODO list with due dates) is maintained at the beginning of the file; when the date appears on the planner, the task appears on the calendar. Monthly schedules don’t recur — each monthly due-date is added iindividually in the TODO list. A three-month calendar a la published calendars is printed on every planning page.

The P/K/M/N are symbols for my commitments B-) and, needless to say, are customizable.

(more…)

MATLAB Cloud Overlay

Friday, December 28th, 2007

Problem I want to compare two surfaces pixel by pixel. Putting them side by side is distracting and exact comparison is difficut (I’m not overlaying a grid on it). Is there some way I can lay one map translucent over the other?

A surface with another surface overlaid

Briefly Turn surface A into RGB image, and darken pixels based on surface B. The figure shows surface A with points lying in [0, 1]. A mask to highlight points lying above 0.5 is overlaid in the lower figure.
(more…)

Thinkpad R60 Modem Disconnect on Call

Thursday, December 27th, 2007

Problem Linux box got a winmodem (Conexant HSF) and needs to

  • dialup
  • disconnect on call

Briefly Modem drivers from de11 and a bash script to disconnect
(more…)

wavplay on Linux

Monday, November 19th, 2007

Problem MATLAB on linux doesn’t have wavplay.

Solution Write sound signal as wav file on disk, and play it using some other program. Better still, write a script that tracks a wav file on disk and plays it whenever it changes. waverunner.sh does just that, and wavplay.m writes wav files on disk just like windows wavplay does.

(more…)

Review Mania

Wednesday, November 7th, 2007

Problem: I want to download movie reviews that give me reason to live. All reviews by A.O. Scott along with the N4 Times photo accompanying the review, preferably in its original formatting. Why? Maybe make it a makeshift book, because N4 Times decided to publish inglorious reviews (1000 best movies?) that list actors and scenes rather than making sense of the movie. I want Scott’s reviews.

Briefly: Use wget to get the world. Script requiring bash, wget, free account with n4 times.
(more…)

G009le Atlas

Wednesday, November 7th, 2007

Problem: You want a printed atlas, as free as it gets

Briefly: Get it from G009le maps, using an unethical (i.e. wastes time, effort and isn’t even elegant) hack, but the code is here. Requires: bash, firefox, g009le map API, latex/pdflatex with pdfpages.sty (if pdf desired), pdfprinter (if pdf desired), headfile.html, tailfile.html

Solution:

  • Figure coordinates of top left and bottom right
  • Install g009le maps api
  • Write script to generate requests for a pageful at a time (determine appropriate scale)
  • Title the page by the map index (row index number and column index alphabet)
  • Print each page with pdf printer
  • Print cover map with top left and bottom right pageful
  • Overlay with a grid in gimp/illy
  • File them all

(more…)