osx scroll direction

I’ve gotten used to ‘natural scrolling’ on my macbook. The problem is that I haven’t gotten used to it when using a mouse. This means that when I attach a mouse to my macbook some funny things happen and it is a bit frustrating to use. There are two check boxes in OSX’s preferences: one for the mouse and one for the trackpad, oddly enough they’re linked. Thankfully there’s a product out there called scroll reverser that takes care of the problem. It allows me to revert the direction for the mouse only, and so far works great.


arma mission editing

I forgot how frustratingly stupid the Arma3 scripting language can be. Regardless…it’s fun when it works!
the mission is almost complete. I spent the night dicking around with the helicopter extraction; talk about a pain in the neck. It always feels like a 50/50 shot as to if it’ll actually work or not. I figured out how to use and call functions as well which has been quite useful. The only thing missing right now is weapon persistence through death…one of these days.

multiple legends

It is certainly useful at times to break your legend up into multiple parts, but doing so in python (matplotlib) can be a pain in the neck. Luckily there’s a quick and fairly simple solution!

First thing you need to do, is actually name your plotted lines like so:
 fig=figure()
 ax1=fig.add_subplot(111)

l1 = ax1.plot(x, y, 'bo', label='ONE')
 l2 = ax1.plot(i, j, 'rx', label='TWO')
we now separate these lines and their labels into different variables
legendlines1 = l1
legendlabels1 = [l.get_label() for l in legendlines1]
legendlines2 = l2
legendlabels2 = [l.get_label() for l in legendlines2]
at this point we can’t just plot a legend, then another legend. The second legend always takes precedence and essentially erases the first. So in order to get around this, we name the first legend, and render the second:
legend1 = ax1.legend(legendlines1,legendlabels1,loc=1)
ax1.legend(legendlines2,legendlabels2,loc=3)
if you run the script up until this point, you’ll only have the second legend showing in location 3. In order to get the second legend we add the object via gca():
gca().add_artist(legend1)
and that should do it!
multilegend
full script below:
 from pylab import *
 from numpy import *

x=linspace(0,5,20)
 y=-x

fig=figure()
 ax1=fig.add_subplot(111)

l1=ax1.plot(x,y,label='ONE')
 l2=ax1.plot(y,x,label='TWO')

legendlines1 = l1
 legendlabels1 = [l.get_label() for l in legendlines1]
 legendlines2 = l2
 legendlabels2 = [l.get_label() for l in legendlines2]

legend1=ax1.legend(legendlines1,legendlabels1,loc=1)
ax1.legend(legendlines2,legendlabels2,loc=3)

gca().add_artist(legend1)

show()


backing up my wordpress SQL database

Along the lines of using this as a sort of lab journal for my experiments and thoughts, I think it is important to keep these things backed up. Crontab again comes to the rescue by executing a small snippet of code that will backup the database in case something nutty happens. The script for such an action looks something like so:
#!/bin/bash
/usr/bin/mysqldump -u root -pPASSWORD wordpress | gzip > /home/bob/RAID5/Backups/MYSQL/wordpress_`date +%m-%d-%Y`.sql.gz
I set this to run in the crontab at 5am daily. This will create a new file each time, but I may have it perform this task once a week and have the daily backup overwrite the previous dump.

binary arithmetic…ugh

Looking through the gadget source code I’ve come across a snippet that makes little sense to me:
if(((1 << P[n].Type) & (FOF_SECONDARY_LINK_TYPES)))
where we have ‘<<’ and ‘&’ as bitwise operators. This is nasty binary, another thing I have yet to learn for reasons unknown.
So let’s go through some basics shall we? First what is binary? It’s a simple code of 1s and 0s, or on & off switches. But how do those represent numbers? Well each digit within the binary is a power of two, or as Saju puts it 2^(number of trailing digits):
0001=1
0010=2
0100=4
1000=8
....
Each 0/1 is a bit, and there are 8bits to a byte. As an example we can look at a short int, which is 2bytes. The binary representation is simply 16 1s or 0s representing the number. Let’s look at some binary examples and see how this works:
0011=2+1=3
1001=8+1=9
0110=4+2=6
1000001=2^6+1=65
Now that is under control, how does the “<<” work? This is called a left shift, and basically moves everything to the left a specified number of bits. What we have is “x << y” which means shift x to the left by y bits.
1001 << 3 = 1001000 = 2^6 + 2^3 = 64 + 8 = 72
Our original problem shows that we will be shifting the binary value of 1 by P[n].Type which will range anywhere from 0-5 in gadget.
1 << 0 = 001 << 0 = 000001 = 1
1 << 1 = 001 << 1 = 000010 = 2
1 << 2 = 001 << 2 = 000100 = 4
1 << 3 = 001 << 3 = 001000 = 8
1 << 4 = 001 << 4 = 010000 = 16
1 << 5 = 001 << 5 = 100000 = 32
Typically FOF_SECONDARY_LINK_TYPE = 2^0 + 2^4 = 1 + 16 = 17, which means we are concerned with particle types 0 (gas) and 4 (stars). This brings us to our next operator, the dirty little amperstamp. This is referred to as the bitwise AND operator. From my understanding it simply compares the each BIT between the two different values and if they are both equal to 1 we have a match. So say we have (4 & 17), how does this work? Well FIRST we have to do the left bitwise shift on 1 by 4 bits:
 STARS:
 00001 << 4 = 10000

[10000 & 10001]
 10000 // 16 (STARS)
 10001 // 17
 ----------------
 10000 = 16 (MATCH)

GAS:
 00001 << 0 = 00001

[00001 & 10001]
 00001 // 1 (GAS)
 10001 // 17
 ----------------
 00001 = 1 (MATCH)
Now if we find a match, then the code continues into this if statement, otherwise the condition check fails. As a quick example, let’s perform this same operation for DM particles (Type 1):
 DM:
 00001 << 1 = 00010

[00010 & 10001]
 00010 // 2 (DM)
 10001 // 17
 ----------------
 00000 = 0 (NO MATCH)
At first this made zero sense to me, but now I think I have a much better grip on things. If I have further issues, Saju says to look at this link.

frameless legend()

I keep forgetting how to turn the bounding box OFF for matplotlib’s legend(). It quite simple but I can’t stop forgetting =(

legend(frameon=False)

colorbar for a multipanel plot

I was having some issues tonight getting a colorbar to function properly. If my script simply looked like so:
fig=figure(figsize=(12,6))
p1=fig.add_subplot(121)
column_render(datasets[0],PICKER,logData=LOG,
minIn=datasets[COLOR_SCALE].MIN, maxIn=datasets[COLOR_SCALE].MAX)
axis([XL,XH,YL,YH])
title(r'VSPH')
p2=fig.add_subplot(122)
column_render(datasets[1],PICKER,logData=LOG,
minIn=datasets[COLOR_SCALE].MIN, maxIn=datasets[COLOR_SCALE].MAX)
p2.set_yticklabels([])
axis([XL,XH,YL,YH])
title(r'DISPH')
subplots_adjust(wspace=0,hspace=0,right=0.85,left=0.07)
cb = colorbar()
cb.set_label(r'%s' % datasets[COLOR_SCALE].LABEL,fontsize=18)
show()
I got something that looked like this:
which is obviously not what I was looking for. Apparently I need to add an axis where I will place the colorbar. Tips from stackoverflow and checking out python’s website itself led me to the proper conclusion:
fig=figure(figsize=(12,6))
p1=fig.add_subplot(121)
column_render(datasets[0],PICKER,logData=LOG,
minIn=datasets[COLOR_SCALE].MIN, maxIn=datasets[COLOR_SCALE].MAX)
axis([XL,XH,YL,YH])
title(r'VSPH')
p2=fig.add_subplot(122)
column_render(datasets[1],PICKER,logData=LOG,
minIn=datasets[COLOR_SCALE].MIN, maxIn=datasets[COLOR_SCALE].MAX)
p2.set_yticklabels([])
axis([XL,XH,YL,YH])
title(r'DISPH')
subplots_adjust(wspace=0,hspace=0,right=0.85,left=0.07)
cax = fig.add_axes([0.86, 0.1, 0.03, 0.8])
cb = colorbar(cax=cax)
cb.set_label(r'%s' % datasets[COLOR_SCALE].LABEL,fontsize=18)
show()
by adding an axis for the colorbar to live on lets me customize its location, width, and height. The parameters in add_axis([left,bottom,width,height]) as in it’s drawing a rectangle. With this slight change the plot now looks like this:
GALCOMPARE

MUN

After a day and a half of failed orbits and crashes, I finally landed on the Mun! I beefed up the launch phase by adding two solid boosters and a beefier liquid rocket, then switched to a nuclear rocket for the transfer and slow down phase. Once I got to around 150-200km/s landing got very touchy due to the Mun’s very low gravity.
screenshot31
screenshot35

Space station in orbit!

I finally got a space station of some sort in orbit! Apparently less is more in this case as it becomes easier to lift. Now for the hard part…adding modules…
screenshot27