Tuesday, November 25, 2014

installing ruby without sudo

First off, one should should a version control for ruby. I only know rvm.

The first step is the hair-raising curl | bash combination they list on their website. This should set up rvm. It’s nice and made for non-sudoers; it installs in a local directory by default. If you get any warnings, probably check up on those.

I wanted to use ruby 2.0.0 because that’s what I have on my personal machine. Running the recommended rvm install 2.0 led to requests for a password, which are due to rvm’s desire to install some dependencies as necessary. I crossed my fingers and tried to do without these libraries: rvm install 2.0.0 --autolibs=0.

rvm automatically gives you gem, so I was happy to be able to install my favorite gem: gem install arginine. Worked like a charm.

Wednesday, July 2, 2014

What queues exist on my PBS server?

You can get information on what queues exist by using qstat -Q, but that doesn't give you information about the walltime and total possible number of jobs. You can get all that information from the mysterious qmgr -c 'p s'.

Thursday, May 22, 2014

why i stopped using perl

I wanted to have a double loop over key-value pairs in a hash. I was doing a sensitivity analysis, so I had a hash that linked parameter names to their values. I wanted to loop over the values in that hash, modifying the values one by one. In each loop, I would copy the original hash, change one value, then run the simulation.

So if I had parameters a, b, and c, each with initial value 1.0, I would want to run simulations where a was changed but b and c left alone, then b changed but a and c left alone, and then c changed.

If you do this the naive way in python, you would get screwed:

d = {'a': 1, 'b': 1, 'c': 1}
for key, value in d.items():
    new_d = d
    new_d[key] = value*1.01
    print new_d


{'a': 1.01, 'c': 1, 'b': 1}
{'a': 1.01, 'c': 1.01, 'b': 1}
{'a': 1.01, 'c': 1.01, 'b': 1.01}

because new_d is never a new object, it just points to the original dictionary d. I verified this by printing id(d) and id(new_d):


Changing that line to new_d = dict(d) suitably rescues the result:

{'a': 1.01, 'c': 1, 'b': 1}
{'a': 1, 'c': 1.01, 'b': 1}
{'a': 1, 'c': 1, 'b': 1.01}

Doing the (I thought) sensible thing in perl leads to bizarre results:

use 5.10.1;
my %hash = ("a" => 1, "b" => 1, "c" => 1);

while (my ($key, $value) = each %hash) {
    my %new_hash = %hash;
    $new_hash{$key} = value*1.01;
    print "$_: $new_hash{$_}, " for (keys %new_hash);
    print "\n";

causes in infinite loop:

c: 1.01, a: 1, b: 1, 
c: 1.01, a: 1, b: 1, 
c: 1.01, a: 1, b: 1, 
c: 1.01, a: 1, b: 1, 

I thought I had made the python mistake, so I printed \%hash and \%hash_new, but I saw different memory addresses:


It turns out that in perl, every hash has exactly one internal iterator. In the first step of the while-loop, that iterator points to c. When I copy the hash, the iterator goes back to the beginning and ends up pointing to c again in the next iteration of the loop.

You can rescue this in a bunch of ways, one of which is to just loop over keys:

for my $key (keys %hash) {

but I was so disgusted by this bizarre and crazy behavior that I just stopped using perl.

Tuesday, May 20, 2014

Pushing to a github repo from a firewalled cluster

I cloned my repo from github, but then when I tried to push, I got this complaint:

$ git push
error: The requested URL returned error: 403 while accessing https://github.com/user/repo.git/info/refs

I fixed this by issuing

$ git remote set-url origin https://user@github.com/user/repo.git

Wednesday, April 23, 2014

Cisco AnyConnect reconnection on Mac

My Cisco AnyConnect thingy would complain whenever I lost an internet connection. I enabled reconnection by looking in /opt/cisco/anyconnect.

First I made a backup of AnyConnectLocalPolicy.xsd.

Then, inside that file, I added the following block inside the <xs: all minOccurs="0"> tag (line 5 for me, above the tag name="FipsMode"):

<AutoReconnect UserControllable="true">true
  <AutoReconnectBehavior UserControllable="true">ReconnectAfterResume</AutoReconnectBehavior>

C'est tout.

Wednesday, April 16, 2014

Using a usb for Mac and then Linux

I've been using a usb stick on my Mac and I wanted to use it to boot a different machine for Linux. After fiddling with a bunch of file formats and partitions on my Mac, I decided I had done something bad to the usb stick that even mkfs couldn't fix.

I got around this by cleaning out the usb stick (mine is at sdc):

sudo dd if=/dev/zero of=/dev/sdc bs=4M (not sdc1, since I want to kill the whole stick; bs is to speed things up)
sudo fdisk /dev/sdc

There should be no existing partitions, so pressing d should say "No partition defined yet".
Make a new partition (n, then p, then 1, then default, then default, then w).

sudo mkfs.vfat /dev/sdc1
umount /dev/sdc1 (if it got mounted)
sudo dd if=/path/to/iso.iso of=/dev/sdc bs=4M

Should work.

Monday, March 17, 2014

Swap caps lock and escape on Mac

I'm a vim user, so I want a handy escape key, but I'm also enthusiastic, so sometimes I want caps lock.

I have a Macbook Air with 10.8.5. I got PCKeyboardHack and selected 'Change Caps Lock' to code 53 and 'Change Escape' to 57.

I had to keep the Modifier Keys options under System Preferences | Keyboard the same.

Monday, March 10, 2014

Mac does weird things with tar files

I ran across this problem while trying to edit an R package's source code. I downloaded the source .tar.gz, extracted it, made a modification, compressed it again, and tried to feed that into R. R complained with a bunch of weird errors:

._bipoilog_s_cint.c:1:1: warning: null character(s) ignored [enabled by default]
._bipoilog_s_cint.c:1:2: error: stray '\5' in program
._bipoilog_s_cint.c:1:2: error: stray '\26' in program
._bipoilog_s_cint.c:1:2: error: stray '\7' in program
._bipoilog_s_cint.c:1:5: warning: null character(s) ignored [enabled by default]
._bipoilog_s_cint.c:1:2: error: stray '\2' in program
._bipoilog_s_cint.c:1:7: warning: null character(s) ignored [enabled by default]
._bipoilog_s_cint.c:1:9: error: unknown type name 'Mac'
._bipoilog_s_cint.c:1:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'X'

Macs have special interpretations for ._* files that appear in tar archives. I got around this by using:


And then after editing,

COPY_EXTENDED_ATTRIBUTES_DISABLE=true COPYFILE_DISABLE=true tar cf poilog_0.4.tar.gz poilog

Thanks go to Chris Johnsen in this thread.