css (1) jQuery (7) linux (38) mac (70) php (29) python (1) svn/git (9) trac (4) ubuntu (1) virtualbox (6) vista (2) windows (14)

Wednesday, 22 September 2010

Big site web servers

Out of random curisoity while I waite for a database to populate I went and checked the server headers from various big websites, amazon's I thought was the best
Google: gws
Yahoo: Yts
Wikipedia: Apache (although I thought they used nginx but apparently they use apache with varnish as a cache)
Amazon: Server (yes that's what it says, Server.....)
Stackoverflow: Doesn't have a Server header...

Recover git deleted file

So you've deleted a file but it was tracked by git at some point and you want it back..well here's how to get it. First use git log to find it, in my case it was a pdf file

git  log --diff-filter=D --summary | grep "pdf\|commit"

The grep "pdf\|commit" filters all pdf files and commit lines, once you see the file you want, choose the commit before it and use git checkout (commit) (file path)

Git Less

By default git uses less to page it's output, to override this use git -c core.pager=" " i.e. git -c core.pager=" " log 

Tuesday, 21 September 2010

Clean up git repositories

If you're like me and have a git repo for each project and have a lot of projects then they could be chewing up some space. Here is a quick command to clean them all (garbage collect)

find . -type d -name '.git' -exec git --git-dir={} gc \;

The command finds all .git directories then executes git gc on the directory which packs and prunes your git repos.

Thursday, 16 September 2010

Recreate the mysql root user

Me being daft accidentally deleted my mysql root user...oops!

To fix it do the following:

1) kill `cat /path/to/mysql/pid/`
2) mysqld_save --skip-grant-tables &
3) mysqldump mysql > mysql.sql (this backs up your mysql users database)
4) echo 'drop table mysql.users' | mysql
5) kill `cat /path/to/mysql/pid/`
6) mysql_install_db (this will reinstall the mysql.users table with an empty root password)
7) (start mysql however you do on your system)
8) mysql_secure_installation (to set your password)
9) edit the mysql.sql dump file removing the root user from it then restore the file to restore your previous privilages

Monday, 6 September 2010

Disable GDM at bootup on ubuntu lucid

Ubuntu lucid replaces the old init system with upstart, this means you can't use update-rc.d gdm -f remove  to stop it starting up at bootup. So to disable it we need to edit the upstart files in /etc/init (note not /etc/init.d!) thanks to sisco311 on the ubuntu forums the solution is to edit /etc/init/gdm.conf and change

start on (filesystem
          and started hal
          and tty-device-added KERNEL=tty7
          and (graphics-device-added or stopped udevtrigger))
stop on runlevel [016]


start on (runlevel [3]
          and filesystem
          and started hal
          and tty-device-added KERNEL=tty7
          and (graphics-device-added or stopped udevtrigger))
stop on runlevel [0126]

Then reboot!

You can start gdm via service gdm start

Sunday, 5 September 2010

IE8 table and JQuery Toggle

JQuery's toggle function doesn't work in IE8 when on a td element (and probably a tr). Why ask Microsoft? Anyway to get around it I made a class called .hidden { display:none; } . And used toggleClass("hidden") instead.

Friday, 3 September 2010

Reduce the size of a virtual box vdi drive.

A lot of people suggest using vboxmanage --compact to shrink a virtual box vdi drive, now every time I try this it corrupts the drive, so after some googling I found a blog post from sun and they suggest an alternative, to clone the drive instead, so here's a step by step process.
(this is for a linux guest)
1) log into the guest, type cat /dev/zero > /zero.file; rm /zero.file; shutdown -h now in the terminal that will fill you free space with 0's then shutdown the machine
2) run vboxmanage clonehd /path/to/your/vdi /path/to/new/vdi this will clone the drive but it won't copy the 0's so it'll be smaller.
3) open virtual box, go to your machine's settings and swap the old drive with the new one.
All done!