Thursday, October 30, 2008

Regular expressions

email reg exp:
[a-zA-Z0-9._-]+@(([a-zA-Z0-9_-]{2,99}\.)+[a-zA-Z]{2,4})|((25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9]))
url reg exp:
[a-zA-Z]{3,4}[sS]?://((([\w\d\-]+\.)+[ a-zA-Z]{2,4})|((25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])))((\?|/)[\w/=+#_~&:;%\-\?\.]*)
IP reg exp:
(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])

Thursday, October 2, 2008

Automate sudo password

I'm tired of typing my password to add new packages with Synaptic.

So, one solution is to edit the sudoers list with sudo visudo. To automate the sudo password for all programs add:
%yourgroup ALL = NOPASSWD: ALL
But this is excessive, so to automate the password for just a particular program provide its path like this:
%yourgroup ALL = NOPASSWD: /usr/sbin/synaptic

Now I can add new packages with Synaptic without being prompted for a password.

Sunday, June 1, 2008

Fun with Festival

Festival is a light weight text to speech program originally developed at The University of Edinburgh.

# from the command line
> echo "hello world" | festival --tts

# from a file
> echo "hello world" > file
> festival --tts file

Wednesday, May 28, 2008

file conversion

Open source developers have focussed a lot of energy on the plumbing. Here are some examples for manipulating file types:

# convert between video formats
> ffmpeg -i input.flv output.mpg

# convert between image formats
> convert input.png output.jpeg

# join together audio files
> sox in_1.wav in_2.wav out.wav

# remove sound from video
> mencoder -ovc copy -nosound video.avi -o video_nosound.avi
# add sound to video
> mencoder -ovc copy -audiofile soundtrack.mp3 -oac copy video_nosound.avi -o video_sound.avi

Saturday, April 5, 2008

firefox proxy

If your web browsing is restricted you can use a remote server to get round it. In the firefox network settings choose manual proxy and a port number. Then at the command line type:

> ssh -XfN -D PORT -p 22 user@server

Now when you surf the packets will be redirected through this ssh tunnel.

Sunday, March 30, 2008

Password protect grub

By default with Ubuntu the user can use grub to login with root privileges WITHOUT a password, which I don't feel comfortable with. This is how I password protected grub to prevent changing the boot process:

> grub
grub> md5crypt

Password: YOUR_PASSWORD
Encrypted: abcdef

grub> quit


Now copy the encrypted string into the start of the grub file:

> sudo vim /boot/grub/menu.lst
password --md5 abcdef
lock

After saving change the permissions to prevent other uses viewing the file:
> sudo chmod 600 /boot/grub/menu.lst

Saturday, March 29, 2008

Recover password

If you forget your login password it can be recovered through grub. At boot enter the grub menu and choose 'single'. This will get you a root command prompt. Now run 'passwd' to set a new password. Now anyone can do this if they get access to your machine so you should password protect grub. I will write how to do this later.

Saturday, March 1, 2008

Email from the command line

echo "message" | mutt -s "subject" -x address@host.com

Thursday, February 28, 2008

Passwordless ssh

It becomes a hassle hopping between servers with ssh if you have to type the password each time. To enable passwordless ssh go:

> ssh-keygen -t dsa (ENTER to skip password)
> scp ~/.ssh/id_dsa.pub user@other_server

And on the other server:
> cat ~/id_dsa.pub >> ~/.ssh/authorized_keys
> rm ~/id_dsa.pub

Now you can hop between servers without a password. I only do this for servers that I can afford to be compromised.

Saturday, February 16, 2008

Extracting tar balls

I always forget the flags:

tar -xvvf file.tar
tar -xvvzf file.tar.gz
tar -zxvf file.tgz
tar xjvf file.tar.bz2

Friday, February 15, 2008

Moving and svn repository

To move an svn repository first dump it to a file with:

> svnadmin dump /path/to/repository > svn.dump

Now to create the new repository go:

> svnadmin create new_repository_name
> svnadmin load new_repository_name < svn.dump

Wednesday, January 30, 2008

Mediawiki upload settings

By default the Mediawiki upload settings are too restrictive because they deny most filetypes. And changing the file extension is not enough because Mediawiki also checks the mime type. As a quick and dirty to allow what you want open LocalSettings.php and add:

$wgStrictFileExtensions = false;
$wgCheckFileExtensions = false;
$wgVerifyMimeType = false;

Sunday, January 20, 2008

Mediawiki printing

By default mediawiki includes header and footer information, which looks unprofessional when printing. To disable this open up skins/common/commonPrint.css and add:

#footer {
display: none;
}
.printfooter {
display: none;
}
#bodyContent {
font-family: courier;
}

Tuesday, January 15, 2008

Mediawiki sidebar

To change the Mediawiki sidebar login as sysop and edit the page 'MediaWiki:Sidebar'. Note that the default sysop login name is WikiSysop.

Saturday, January 12, 2008

Mediawiki refresh

To force Mediawiki to refresh anything it has cached just update LocalSettings.php:

> touch /var/lib/mediawiki/LocalSettings.php

Thursday, January 10, 2008

Mediawiki disable new accounts

For privacy I recently made my wiki (Mediawiki 1.7) private and disabled new account creations. To do this I opened LocalSettings.php and added:

$wgGroupPermissions['*']['createaccount'] = false;
$wgGroupPermissions['*']['read'] = false;

The problem is this prevents users logging in. I finally figured out I need to make the login page an exception for anonymous users with:

$wgWhitelistRead = array("Special:Userlogin");

Wednesday, January 2, 2008

First post!

This blog will serve as a repository of solutions to technical problems I faced.

Currently I use the following technologies often:
  • Python
  • Linux (Ubuntu)
  • jQuery
  • web2py
  • Qt