OSX Automount

When reinstalling OSX on my hackintosh I’m always troubled with the question of how do I automatically reconnect to my server’s network drive on startup? I previously had an apple script that did just that, but for whatever reason it no longer works in OSX 10.9 Mavericks. Apparently Apple’s Automater is a lot easier to work with and does the same thing. Thanks to this post I found a clever and simple solution that should continue to work regardless of the OS version:

  1. Launch Automater
  2. Choose Application
  3. Search for pause and drag it to the right pane (enter 5secs or so)
  4. Search for server and drag Get Specified Servers and Connect to Servers (in this order) to the right pane.
  5. In Get Specified Servers click Add, and add the address (in my case it was afp://192.168.1.18/RAID5)
  6. Save the application, and add it to your OSX startup!

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.


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.

head command + animated gifs

Date Category Tech
I consider myself pretty knowledgable in Linux…but I seem to be learning new commands and techniques quite often. Today I learned about *head* which essentially gives you the first few lines of a file and prints it on the screen. You can customize this experience by adding parameters, one of the more useful ones is -n # which as you would expect returns a specific number of lines from the beginning of your file. This is going to prove particularly useful when comparing .out files that contain compilation options. On Eureka for instance, I’ve found that
head -n145 something.out > textfile.txt
does a good job at capturing that.
Also had to make a quick animated gif today, easiest way I found was to use image magick via:
convert -delay 50 SH03_%d.tiff[0-1] animated_gif.gif
and the result is:
image0

VPN

Setting up a true VPN (and not just an SSH tunnel) on ubuntu isn’t exactly challenging, but took a little bit of dinkering around. The nice thing is that it works wel and will make things a bit easier when it comes to changing settings while sitting outside of my network, while ‘pretending’ I am inside of my network! I simply followed the straight forward instructions here.


auto-login followed by auto-lock

I’m heading away for a while and will need continued access to my server. Usually that means via ssh, but occasionally I have to VNC into the machine. The problem is - if the server goes down for any reason, when it comes back up the VNC server does not start until I login. So is there a way to set automatic login and lock the screen at the same time? Yes! This is linux, of course there is! Simply create a new file

/home/USERNAME/.config/autostart/screen_lock.desktop

and add the contents

[Desktop Entry] Type=Application Name=Lock Screen Exec=gnome-screensaver-command -l

and that was that, works like a charm. Courtesy of AskUbuntu.


Aquarium webcam

I’m headed out of town for a bit and I’d like to keep an eye on my tank. Luckily linux has software that can do that called motion (obtained via apt-get install motion). You can do all sorts of things with it like time lapse photography, stream at whatever fps you like, auto adjust brightness, etc etc. Had to remove the filter from my ps3eye so a little too much IR is showing through, but it should be sufficient to make sure everything isn’t dying, here’s a live picture (refresh to get a new one):

Aquarium!

[iframe src="http://192.168.1.18:8083/?action=stream"]

edit: something to check out in the future for a more permanent solution - zoneminder


OSX mouse lag…

Apparently I’ve been spending my time in OSX gimped by an unnoticed mouse lag. There’s always been something different between windows and OSX when it comes to mouse movement but I could never quite put my finger on it. Was it the mouse acceleration curve, or something else? Just ran across some software thanks to reddit that makes the mouse feel a hell of a lot like windows called SmoothMouse. The only problem is…my mouse bindings for mission control no longer work.

Time to give USB Overdrive another shot…lets hope this reboot doesn’t kill the machine.

EDIT: Kernel did not panic….so far so good…


the beauty of crontab

I’ve never really understood the linux startup process (and still don’t), so it’s always been difficult to figure out how start things on every reboot.  Luckily, crontab is a beautiful thing that allows one to do just this and more!  Say I have a script that I’d like to run as admin on every reboot.  All I have to do is:

> sudo crontab -e

then add the line:

@reboot /home/bob/local/scripts/something.sh

and on upon every reboot the script will run.  What’s even cooler is that there are separate crontabs for each user.  So instead of using sudo in the above command if you simply use ‘crontab -e’ you will edit the current user’s crontab. For instance I have two entries in my server’s current crontab that periodically deletes a huge log file, and starts my ipython notebook server:

# m h  dom mon dow   command
10 06 * * * /home/bob/local/scripts/delxsessionerrs.sh
@reboot /home/bob/local/scripts/ipynotebook.sh

The first command tells the system to run delxsessionerrs.sh at 6:10am every day, the second line launches ipynotebook.sh on every reboot. Now I imagine one could insert the commands directly into the crontab, but I prefer the above script method.