Tips

Applescripting A Remote X-Windows Session for Virt-Manager

1 min read

This isn’t just for virt-manager, but any X-Windows app you’d want to tightly integrate into your daily routine. Instead of firing up X11, then SSH’ing to your VM box and typing out virt-manager (insane!) you can script X11 to do everything with 1 mouse click. I have it in my Dock, and Launchbar also recognizes it as an app.

tell application "Finder"
    launch application "X11"
end tell

set results to do shell script “ssh -X haddad-vmserver ‘virt-manager’”

apple kvm tips
Read more

Making Better Use of your .ackrc file

1 min read

Many command line utils have a . file that people rarely use. Ack is one of them.

For a project I’m working on, there’s a var folder (ignored in git) where all the logs go. When I perform an ack search, I have no interest in ack looking through the var folder every single time.

By default, ack only checks your ~/.ackrc file for it’s default switches. You can have per directory ack settings if you add this to your .bash_profile:

ack linux tips
Read more

Open New Terminal Tip

1 min read

I tend to open up several terminals when working on a project, so I usually want them to start in the same directory I’ve been working with. Stick this in your ~/.bash_profile to have your new terminal windows automatically cd to the directory you last used.

export PROMPT_COMMAND='echo `pwd` > ~/.lastpwd'
cd `cat ~/.lastpwd ``

tips
Read more

Multiple Filetypes in Vim

1 min read

I’m finding this useful as I work with snipmate and have defined custom snippets for solr config files. I still want to use the XML filetype, but I have no real use for the solr fields outside of editing the schema.xml file.

set filetype=xml.solr

Booya.

tips vim
Read more

SSH with multiple hops

1 min read

Excellent question on superuser.com with a fantastic answer. If anyone needs to jump through multiple servers via ssh (or any other protocol) take a look at this answer.

ssh -L 9999:localhost:9999 host1 ssh -L 9999:localhost:1234 -N host2

linux tips
Read more

Using iWatch to Automatically Run Unit Tests (Linux)

1 min read

iWatch is a perl script that uses inotify to monitor files directories. It’s similar to the watch tool, which can do all sorts of stuff if the files or directories it’s watching are modified or affected in pretty much any way at all.

Install iWatch

apt-get install iwatch

I’ve got this 1 liner in a file to quickly watch my directory and execute a PHP unit test .

#!/bin/bash
iwatch -c "phpunit $1" -t '.*php$' -r -v -x ./.git -e modify .

I run this with a my argument (a unit test) and then sit there and code away. When I save, it detects the change and automatically runs my test. It’s pretty awesome.

linux php tips
Read more

'Running Erlang Code from the Command Line '

1 min read

This was really useful for me in scripting TextEdit to run my unit tests, as Erlide has been crashing every time I use it.

erl -run mymodule myfunc -run init stop -noshell

[http://www.trapexit.org/Running_Erlang_Code_From_The_Command_Line](Running Erlang Code From the Command Line)

erlang tips
Read more

Textmate - Stop ._ Backup Files

1 min read

Pretty sure this stops TextMate from creating the ridiculous backup files in my network shares.

defaults write com.macromates.textmate OakDocumentDisableFSMetaData 1

textmate tips
Read more

'Linux/OSX: find out what network ports are in use'

1 min read

To get a quick idea of what ports you have open on your local box, you can use nmap.

~ jhaddad$ nmap localhost Starting Nmap 5.00 ( http://nmap.org ) at 2010-01-05 11:06 PST Interesting ports on localhost (127.0.0.1): Not shown: 499 closed ports, 492 filtered ports PORT STATE SERVICE 80/tcp open http 88/tcp open kerberos-sec 548/tcp open afp 631/tcp open ipp 3306/tcp open mysql 3325/tcp open unknown 5900/tcp open vnc 9000/tcp open cslistener 10000/tcp open snet-sensor-mgmt

apple linux tips
Read more

MacBook Air Battery Drain While Sleeping

2 min read

CCF3038A-5A01-412B-B13C-7F24B836F6DC.jpgI bought a MacBook Air in June this year, refurbished. I didn’t really use it a lot for day to day work, and when I didn’t use it I was charging it. It was very convenient - it weighs practically nothing and has almost no impact on me while traveling. When I cut back on using it, I noticed a few things.

  1. When I’d leave it unplugged for a few days, the battery would be dead. After a bit of testing I noticed I was losing roughly 25% of my battery life overnight if it wasn’t unplugged.

    apple tips
    Read more

Interesting Programmer Links

2 min read

Really interesting read about how to examine what’s stored in memcached.

Peep uses ptrace to freeze a running memcached server, dump the internal key metadata, and return the server to a running state. If you have a good host ejection mechanism in your client, such as in the Twitter libmemcached builds, you won’t even have to change the production server pool. The instance is not restarted, and no data is lost.

linux mysql tips
Read more

Compiling libjpeg on 64 bit Centos

1 min read

I ran into an issue just now compiling libjpeg on 64 bit CentOS. I found this very helpful post that gives a workaround using a config.guess file from libtool. For some reason, I didn’t have the folder he suggested, but I did have the alternative (automake).

cp /usr/share/automake-1.9/config.guess . cp /usr/share/automake-1.9/config.sub .

I copied the above files into my jpeg-6b directory, and

./configure –enable-shared –enable-static

worked correctly.

linux tips
Read more

Report space remaining on disk on unix login

1 min read

I get a kick out of stuff like this. Add this to your .bash_profile to be greeted with the remaining space on your disk.

df -h | awk ‘NR==2 {print “Space available " $4}’

This will actually change depending on which version of df you’re using (i think). I get different output on my Mac than I do on a CentOS machine - df seems to auto wrap lines on long drive names, so when I check the space on the CentOS server I need to change the line number (NR goes to 3) and the column to print (down to 3).

awk tips unix
Read more

Western Digital Drive with Leopard - File system formatter failed.

1 min read

I just bought a 1TB Western Digital drive. I am stoked.

However, I tried to format the drive on my Mac (Leopard) and got the error “File system formatter failed” when I tried to format the disk as MacOS Extended (Journaled). Not cool.

I found this forum thread which suggested using multiple partitions to solve the problem. When I was trying this, I went into options and changed the partition scheme from Master Boot Record to GUID partition table. It formatted fine.

mac tips
Read more

Compiling Imagemagick on MacOS X - Not finding libjpeg

1 min read

I ran into an issue trying to get Imagemagick (convert) working on OSX last night. I had compiled libjpeg and installed it, but when I would compile convert, it would not have jpeg support.

I found this post on dzone, which I followed and was able to use libjpeg just fine.

tar zxvf jpegsrc.v6b.tar.gz cd jpeg-6b cp /usr/share/libtool/config.sub . cp /usr/share/libtool/config.guess . ./configure --enable-shared --enable-static make sudo make install sudo ranlib /usr/local/lib/libjpeg.a

mac tips
Read more

PHP compile error on CentOS Install

1 min read

I installed CentOS 5 on my VMWare a few days ago. I installed gcc via yum, compiled and installed libxml2. I then tried to install PHP 5.2.3 and received this error:

configure: error: installation or configuration problem: C++ compiler cannot create executables.

It took me forever to figure this out, but I had to install the g++ library, then it compiled fine.

yum install gcc-c++

linux php tips
Read more

Calculating the queries per second average in Mysql

1 min read

I didn’t find any simple ways to determine how hard our mysql database was working, so I whipped this up. It uses a 10 second delay to figure out the queries per second average.

time=10 orig=mysql -e “show status” | awk ‘{if ($1 == “Questions”) print $2}’ sleep $time last=mysql -e “show status” | awk ‘{if ($1 == “Questions”) print $2}’ diff=expr $last - $orig avg=expr $diff / $timeecho "$avg"

mysql tips
Read more

Helpful SVN Script For Adding all Unknown files to Repository

1 min read

I use SVN from the command line a lot. I also hate typing things over and over. I wrote this script to add all files to a repository that are not already in there.

svn status | awk '{if ($1 == "?") print $2 }' | xargs svn add

I have this saved in my ~/bin folder as “addall”, which I’ve added to the $PATH variable, which gets set in ~/.bash_profile

svn tips
Read more

Public / private key set up but not working?

1 min read

When you set up public key authentication, make sure your authorized_keys2 file has the permissions set to 600. If you don’t, it’s likely that you will still be prompted for your password.

chmod 600 authorized_keys*

linux tips
Read more

How to roll back commits to an earlier version of a repository in SVN

1 min read

I’ve always wanted to know how to do this, and for some reason I always had a hard time finding out how. I needed to rollback a change I had committed to my SVN repository.

The way you rollback to an earlier version of your repository is to do a reverse merge.

Here’s the example off the SVN site. It will do a reverse merge, and roll back the commit you made in version 303.

svn tips
Read more

10 (very) Basic Tips for PHP Web Application Security

2 min read

Barebones list for the things you should be looking for when developing a web app in PHP. Some of it applies to all web apps, not just PHP.

  1. Use HTML_Safe (or a similar javascript stripping library) to check for and remove javascript when you’re accepting data that will be output to a page.

  2. Check every get and post variable for validity.

Every web site has url like “dosomething.php?id=3”. Make sure that id you’re accepting is actually a number (or whatever type you’re allowing).

apache php tips
Read more

Pretty URLs using Multiviews

2 min read

I saw a post on digg.com about how it’s nice to have “pretty urls” that are easy to tell people. While i’m not sure anyone would remember rustyrazorblade.com slash some ridiculous post name, it’s nice to have for search engines. Unfortunately, it didn’t really go into detail about how to accomplish the urls. A lot of people suggested mod_rewrite. Yes, it’s something you can use, but kind of a pain to set up.

apache php tips
Read more

'MySQL: Number + NULL

2 min read

Maybe not breaking news, but I think it’s interesting enough of a point, and I didn’t really find anything about the topic when I googled it. If you do any addition, subtraction, multiplication, or division (and probably a lot more mathematical functions for that matter) and NULL is one of your values, the entire expression will evaluate to NULL.

For example, this statement returns NULL:

mysql> select 4 + NULL;

+----------+
| 4 + NULL |
+----------+
|     NULL |
+----------+

Normally you wouldn’t do the above in such a simple way, for instance, you might do some addition in a subquery. For example,

mysql tips
Read more

PHP 5.1.4 Install on Intel Mac (Bug?)

1 min read

I noticed after installing PHP 5.1.4 on my brand new MacBook Pro that my scripts weren’t executing. After about 3 hours of messing around, I realized that short_open_tag was turned off in php.ini.

Location: /usr/local/php5/lib/php.ini

Should be: short_open_tag = On

Not sure if this is a common issue, or if the PHP defaults have been changed. I installed the package distributed by Marc Liyanage, found at his homepage.

_Edit: According to the php web site, this should be on by default.  _

php tips
Read more