os x

You are currently browsing the archive for the os x category.

How often did you needed to process huge amounts of small files, where a single task uses only a small amount of cpu and memory?
However, today I need a script which does exactly this.

I have a mysql table which contains the filenames located on my hard drive.
Now I created a little script which processes a single file in under 3 seconds. Unfortunately for 10.000+ files this would take more than 8 hours.

So what if I could run them in parallel with a maximum of 10 parallel task’s being executed? This would really speed up the computation!

Luckily in 2005 Ole Tange from GNU merged the command line tools xxargs and parallel into the a single tool ‘parallel‘.
With this great tool there is no need to write any complicated script to accomplish such tasks.
First you need to install it using homebrew.

brew install parallel

After that i had to add the path to my .profile

PATH=$PATH:/usr/local/Cellar/parallel/20110822/bin

Here’s the basic usage:

 $> echo -ne "1\n2\n3\n" | parallel -j2 "echo the number is {.}"

This would echo the numbers 1, 2, 3 to the stdout with a maximum of 2 parallel running echo’s.
Here’s the output:

the number is 1
the number is 3
the number is 2

As you can see printing a 3 outspeeds printing a 2 ;)

So here is my 1 liner to process all my files:

 $> mysql -uroot -p[secretPW] my_database < \ 
    <(echo "SELECT filename FROM files")\ 
    | grep -v 'filename' | parallel -j10 "./processFile.sh {.}"

After using this it took only 37min to process my 10000+ files :)

I found this great tutorial on how to install mcrypt into php under OS X 10.6.1
http://michaelgracie.com/2009/09/23/plugging-mcrypt-into-php-on-mac-os-x-snow-leopard-10-6-1/
Works like charming with OS X 10.6.4 and PHP Version 5.3.2.

#!/bin/bash
mkdir src
cd src
wget http://museum.php.net/php5/php-5.3.2.tar.bz2
wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmcrypt%2Ffiles%2FLibmcrypt%2F2.5.8%2F&ts=1306411641&use_mirror=ignum
tar xzvf php-5.3.2.tar.bz2
tar xzvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --disable-dependency-tracking && make -j6 && sudo make install
cd ../php-5.3.2/ext/mcrypt
/usr/bin/phpize
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Developer/SDKs/MacOSX10.6.sdk/usr/bin/php-config && make -j6 && sudo make install
echo "Completed install, now make sure to edit your php.ini"
echo "and check for \"enable_dl = On\" and add \"extension=mcrypt.so\"" to the dynamic extentions"

This is the little bash script I wrote according to his tutorial. This comes without any warranty!!!
Be aware that you have to enter your root password twice while installing this script.

Big Thanks to Michael Gracie

Today I realized that I had not a single song on my notebook hard disk. Thanks to Last.FM :)
Unfortunately “Simplify Media” has been adopted by Google Inc. and they do not offer a similar service yet. So I needed a solution to stream my iTunes from home to the office. If found a great solution by “Robert Harder” which works like charm. (source).
This is the bash script:

#!/bin/sh
dns-sd -P "Home iTunes" _daap._tcp local 3689 localhost.local. \ 
127.0.0.1 "Arbitrary text record" &amp;
PID=$!
ssh -C -N -L 3689:localhost:3689 username@dyndns_name.dyndns.org
kill $PID

LE Mensa

This week I released my first OS X Dashboard Widget.
It’s called ‘LE Mensa’ and it displays all menues for all cafeterias in Leipzig, which are part of the student union.
If you want to give it a try then visit the project page: http://stinfwww.informatik.uni-leipzig.de/~mai03fln/leMensa/
Today I updated it to version 0.15 !!

It works this way:
1. I wrote a python script which extracts information from the student union homepage and transform it into xml.
2. A .php script can call this .py script and give back those infos.
3. The widget was written in Dashcode with jQuery as an additional package. So it’s mainly javascript, some html and css. The widget now calls this php script, retrieves the xml and displays it in a (hopefully) pretty way.

This is how it looks:
Front View

Finally I found an awnser:
NOTE: This is only for Mac, I don’t know how to do it on a Windows machine.

1. connect your iPhone to your Mac
2. close the starting iPhoto for the last Time ;)
3. open up the “Image Capture” (eng) / “Digitale Bilder” (de) Application
4. select your iPhone and choose “No Application” in the DropDown List.
5. close it and enjoy connecting your iPhone without the annoying autostart

I need to open Safari with a specific URL on command line. The problem is that this has to happen completly in background and should be started through an existing bashscript.
Here is my solutiuon, it should apply to any other app in OS X SnowLeopard. You need to call the bash schript like this:

 
./open_safari_with_url.sh "http://www.site_i_want_to_visit.com"

“open_safari_with_url.sh” looks like this:

 
#!/bin/bash
osascript -e "
tell application \"Safari\" 
	tell application \"Finder\"
		set visible of process \"Safari\" to false
	end tell
	launch
	set the URL of document 1 to \"$1\"
end tell"

[EDIT] It seems that ‘launch’ in AppleScripts starts the app in background. So we don’t need to tell Finder to hide Safari anymore.

tell application "Safari" 
	launch
	set the URL of document 1 to "http://whatever..."
end tell"

There are some features in Snow Leopard that Apple try’s to hide from it’s users. I don’t know why but you can’t find those Settings in the “System Preferences” now anywhere else.
Here are my favorites:

1. Animated Preview for Folders in QuickView

defaults write com.apple.finder QLEnableXRayFolders 1

2. iTunes green zoom button
Since iTunes 9 you get the MiniPlayer when pressing the green button in itunes. To get back the max. function you’ll need enter this:

defaults write com.apple.iTunes zoom-to-window -bool YES

Then restart iTunes and be happy.

3. Re-enable auto play for QuickTime
The new Quicktime does not have any preferences, because of this you can’t enable AutoPlay by default. Here’s the command to enable it:

defaults write com.apple.QuickTimePlayerX MGPlayMovieOnOpen 1

4. Keep QuickTime in fullscreen when switching applications
If you are used to work on multi screen systems, sometimes you wan’t to watch a movie or sth. else on another screen. With Quicktime this can be annoying. If you switch to fullscreen and then use Command-Tab to switch the applications QuickTime will automatically quit fullscreen. Type this to get rid of it:

defaults write com.apple.QuickTimePlayerX MGFullScreenExitOnAppSwitch 0

5. screensaver password delay
New SL feature is to set a time delay for password requests. How long does the screensaver had to be active before it requires a password. Do it with:

defaults -currentHost write com.apple.screensaver askForPasswordDelay -int 900

900 == 15min

6. Disable Dock Expose
When clicking on a dock Icon in Leopard you got the “right-click” contex menu. In SL it changed to the DockExpose which will show all current windows of the app. To disable this type:

defaults write com.apple.dock show-expose-menus -boolean no; killall Dock

If you are looking for other hidden settings the best ressource to do this is http://secrets.blacktree.com/.

How to use synergy over ssh with a gateway server, or
How to make port fowarding over a gateway ?

Ok then, someone last week showed me the great tool “synergy”. With it, two ore more computers can be controlled by one keyboard and one mouse. So that’s nothing new.
The nice thing is that if you move your mouse over the boarder of screen 1 if will appear on screen 2 just like this screen was connected to your computer.
It’s working great and I wanted to have this everywhere my MacBook goes.
Setup and Config is real easy and descibed at http://synergy2.sourceforge.net/

The problem is that it’s build upon a server client architecture and you need to have a direct connection between your server and your client. Yes well that should be no problem but I’m working in an office where the networks for hosted computers and the computers ones bring in  are seperated. The only option to get a connection from my macbook to the linux machine I’m sitting right next to, is a connection over a gateway Server that’s somewhere else.
So ssh from my macbook -> gateway
and then from gateway -> to office local linux box
But if i do it this way I won’t be able to establish a direct connection. After some research on the net I came up with this:
Box1 = MacBook
Box2 = Gateway Server
Box3 = office linux box

1st of all start the Server on Port 8033 (or sth. else), Type this on bash in BOX3

synergys -a localhost:8033 -f –config ../conf/synergy.conf

then make a port forwarding from Box2 port 8033 to Box3 port 22. Type this on bash in BOX1

ssh -L 8033:BOX3:22 cb0@BOX2

Then make a port forward from localhost port 24810 to port 8033 on localhost which redirects us directly to Box3. Type this on bash in BOX1

ssh -p 8033 -v -f -N -L localhost:24810:localhost:8033 cb0@localhost

Now on Box1 type this to connect synergy to localhost on port 24810 which redirects it to Box 3.

./synergyc -f localhost:24810

thats it.
Hope you enjoy your new productivity with synergy ;)

A nice project I thought of was to teach my macbook to atomatically connect to a specific server dependent on the enviroment i’m in. This should somehow be possible using apple script but at the moment I have no Idea how.

Marc Lehmann has written a zip Password cracker similar to fzc or zipcrack. It can be used to either bruteforce or try a dictionaty attack on a password protected file.
It’s called fcrackzip and can be found here.
Just follow the instruction given in the Readmefile and compile it. This work’s great for me under 10.5.6 as long as you have X Code installed.

Here’s how I use it:

fcrackzip -b -c aA1 -l 6-8 -v -u file.zip

-b : bruteforce the password
-c : use the following character classes for cracking:

a    use all lowercase character
A   use all uppercase character
1    use all digits

-l 6-8 : Try passwords between 6 to 8 characters in length
-v be more verbose (this will print out the actual used password)
-u file.zip : Try to decompress first file in file.zip with the generated password.

And when the output starts with ‘PASSWORD FOUND!!!!: pw ==’, I’m happy.

For more command line options see the project page under http://www.goof.com/pcg/marc/fcrackzip.html.

On OS X you can easily decode base64 strings with the openssl command

openssl base64 -d -in <(echo “dGhpcyBpcyBhIHRlc3QKCg==”)

just drop the ‘-d’ if you want to encode things.

I found this here

« Older entries