Tuesday, February 18, 2014

Terminal adventures

I do a lot of work remotely for work. Somewhere in the server room there is a beast of a computer with 100's of GB of RAM and a 10-gigabit connection to a dozen other computers hosting half a petabyte of storage.

Mostly I work in MATLAB. If I need graphics, we have a nice OpenNX setup that does remote desktop quite well. It's nearly seamless when I'm on-site, and is still tolerable when I use it from home over DSL (as long as nobody else at home is using the upload capacity).

But often I don't need full graphics, just a text editor and the MATLAB command window. So in today's adventure, we are going to try setting up tmux and vim.

Monday, September 2, 2013

Xbox 360: 120mm fan mod for quietness

I wanted to watch a movie yesterday, but my Xbox's fans are too loud. So I decided to do something about it!


Batch photo resize preserving modify date

On Mac OS with ImageMagick installed (see also this older post):

mkdir resized
cp 2013-09-02*.jpg resized
mogrify -resize 3056x3056 resized/*.jpg
find resized -name "*.jpg" | sed "s/resized\///" | xargs -I {} touch -r "{}" "resized/{}"
mv resized/*.jpg .
rmdir resized

The crazy find/sed/xargs thing does the following:
  1. find : Find all the jpg files in the "resized" folder and return their relative path.
  2. sed : Find and replace all instances of "resized/" with an empty string. sed returns the full string with replacements, not just the match.
  3. xargs touch : Change each of the files in the "resized" folder to have the same modify date

Monday, July 22, 2013

Git rebase

After seing git rebase show up on StackOverflow a few times and purposely ignoring it (due to the overhead required to learn a new git command), I finally broke down and learned what it does.

And it turns out it's not that bad! The git book has a good page introducing it with nice pictures:

http://git-scm.com/book/en/Git-Branching-Rebasing

and I'll describe how I applied it to my particular situation.

Scenario

I have been pulling from a repository at origin/develop, but also making local changes and committing them to my local repository. Now I want to push some (but not all) of the changes to origin/develop.

Procedure

First, I wanted to see how my local repository (currently on branch develop) differed from origin/develop:

git diff --name-status origin/develop..develop

Now if I wanted to make all of those changes, I can just do git push origin, and it would be done. Instead I want to make a subset of those changes, but I can't just arbitrarily pick changes because maybe some of them depend on previous commits.

That's how rebase helps: it lets us re-order the commits. It puts all of the remote changes first (this makes pushing trivial), and then it applies our local changes in whatever order we tell it to. So we do:

git rebase -i origin/develop

and this opens up a text editor with all the local changes that have happened since we first diverged from origin/develop. We can rearrange the commits, collapse multiple commits into one using squash, and do all sorts of other things that are covered in this tutorial. In my case, I simply moved the changes I wanted pushed to the top of the list.

Once we save and close this file, git-rebase will try to apply each of those changes, in sequence, using origin/develop as a starting point. This may not proceed entirely smoothly, especially if you have re-ordered some commits.

Once this is finished, I go find the hash of the last commit I want pushed and push all the commits up to that one:

git push origin 1fc6c95:develop

And that's that!

Sunday, April 28, 2013

Fish tube, again



We re-installed the fish tube, and it seems to be much more popular this time around! Everybody's had a turn at it: the rasboras, panda cory, Amano shrimp, and even our nerite snail! The snail must have climbed up on a plant or something, because the tube doesn't touch the walls of the tank.

There is regularly at least one rasbora in the tube. It's usually a different rasbora each day, which is a relief.

Pita bread

Had leftover chicken from Zankou, but no pita to go with it, so I decided to make some!

I followed this recipe, paraphrased here:
  • 227 g (~1.5 C) flour
  • 65% water
  • 6% olive/canola oil
  • 1.5% dry yeast
  • 2.7% salt
Percentages are by mass, relative to flour. Special thanks to my roommate, who bought a 2 kg digital scale and a thermocouple reader for his coffee-making.

Let rise for 5 hr at 22°C. This produces a lot more gas than my usual bread recipe at the same temperature, probably due to the increased amount of yeast. Punch down, let rise for another half hour or so.

Preheat oven, with baking stone, to 475°F.

Divide dough into 6 balls. Flatten into discs and then roll out with a rolling pin.

Sprinkle some water on top, and let sit for 10 min or so. Ensure bottom is well-floured, and slide onto baking stone. Bake for 3 min.

Magically, it ballons up and then you get a pita! I still don't understand how this happened.

And it came out pretty good! A bit salty, but that wasn't so noticeable after filling it with chicken and garlic sauce and hummus. Need to be careful not to get it too thin during the rolling and handling process.

Saturday, December 1, 2012

SSH tunneling and git

I can only connect to my lab's computers via a router. For simple stuff, this suffices:

homecomp:~ jdoe$ ssh jdoe@router.university.edu
[jdoe@router ~]$ ssh jdoe@labcomp

But this gets annoying for things like copying files. Fortunately, you can set up an SSH tunnel:

homecomp:~ jdoe$ ssh jdoe@router.university.edu -L 4321:labcomp:22

Here you are connecting to the router and also telling it to set up a tunnel from homecomp's local port 4321 to lapcomp port 22 (the default for ssh traffic). You can also add a -N flag (which stops you from running any commands through this terminal) and/or a -f flag (which makes this run in the background). I prefer not to use -f; this way it is easier to kill the tunnel should you need to.

And then you can do things like:

homecomp:~ jdoe$ ssh jdoe@localhost -p 4321

homecomp:~ jdoe$ scp -r -P 4321 jdoe@localhost:~/Documents ~/Desktop/workDocs

homecomp:~ jdoe$ git clone ssh://jdoe@localhost:4321/~/MATLAB

Yay!

Wednesday, October 3, 2012

How to open source!

I have heard a lot about open source stuff but haven't really been good enough "with computers" to attempt that. Until now! I am attempting to install an open-source video codec called x264 on my Mac.
  1. Have Xcode installed (got it from Apple; it's a standard installer).
  2. git comes pre-installed on my Mac.
  3. Go to a directory where you can put the source code. I just used the desktop; hopefully there won't be any permissions issues.
  4. Get the repository:
    git clone git://git.videolan.org/x264.git
  5. Go to the branch called "stable" (I don't know if this actually changed anything):
    git checkout stable
  6. Attempt to compile...Oh no! It needs an assembler:
    Found no assembler
    Minimum version is yasm-1.0.0
    If you really want to compile without asm, configure with --disable-asm.
    make: *** [config.mak] Error 1
  7. Get YASM:
    git clone git://github.com/yasm/yasm.git
  8. Compile it:
    ./configure
    make
    sudo make install
  9. Oh no! That didn't work...there isn't a configure file! There is a configure.ac file, though, which suggests maybe we need to generate it using autoconf:
    autoconf
  10. A error! Something about macros:
    configure.ac:14: error: possibly undefined macro: AM_INIT_AUTOMAKE
  11. Apparently there is this thing called aclocal:
    aclocal
    autoconf
  12. Still errors! According to the Internet, there should already be a configure file here. So I downloaded the tarball instead, and that has it. Okay. Let's try compiling it again:
    cd yasm-1.2.0
    ./configure
    make
    sudo make install
  13. That seems to have worked!
    $ which yasm
    /usr/local/bin/yasm
  14. Okay, now we can go back to the x264 folder and try installing it:
    cd ../x264
    ./configure
    make
    sudo make install
  15. It worked! Yay!
UPDATE: I subsequently needed to perform this installation on another computer, which I only have ssh access to at the moment. It turns out you can also install YASM using MacPorts, which is very easy:
sudo port install yasm

UPDATE 2: Later I needed to do this installation on a computer that didn't have ffmpeg installed, and also I'm not a super user for, so I had to install it to my home directory.
git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure --enable-shared --prefix=/home/username/myBin
make
make install
and then re-install x264 with appropriate flags to tell it where the ffmpeg library is:
cd x264
export LDFLAGS="-L/home/username/myBin/lib"
export CFLAGS="-I/home/username/myBin/include"
export LD_RUN_PATH="/home/username/myBin/lib"
./configure --enable-shared --prefix=/home/username/myBin
make
make install
Then the call to x264 is:
x264 -q0 --preset placebo -o outputFile.mkv inputFile.avi

Friday, September 28, 2012

Macports madness

How to install older versions with MacPorts:
  1. Go to https://trac.macports.org/browser/trunk/dports and find the revision and directory you want. In my case, it was 91935 and devel/automake
  2. Go to some temporary directory (one accessible to everybody; see step 5)
  3. svn co -r 91935 http://svn.macports.org/repository/macports/trunk/dports/devel/automake
  4. cd automake
  5. Change read/write permissions and/or ownership so that macports can access Portfile and potentially files. For example, sudo chown -R macports:macports Portfile files
  6. sudo port install
  7. You can check the newly-installed version with port installed automake

Wednesday, July 4, 2012

More black-and-white photos

I've taken some more photos (3 rolls of 120 and 1 roll of 35mm) since my last post; here are some that I liked:





The last two were with a 20mm lens on 35mm film and I thought the exaggerated sense of perspective was interesting. The last one was a handheld 1/8 second exposure so I took a couple shots (because processing this film is cheap!) and just hoped for the best. I should've turned on the oscilloscope and captured an interesting waveform, though. Note the computer desktop background!

I don't know if this is a limitation of the film format, my equipment, or my scanning, but the medium-format photos (the first three) show a lot more detail and less grain than the 35mm photos.