Archive for the 'Code' Category

Iterate a Text File in Bash

This is how you iterate thru a text file outputting a line at a time in Bash shell scripting.


IFS=$'\n'; for i in $(cat FILE.TXT); do echo "$i"; done

Watch for Ubuntu 9.10 Launch

This script will run check for ubuntu launch once every 5 mins and let you know if there is an launch.


while [ 1 ]; do if [ -z "`curl -I "http://cdimage.ubuntu.com/releases/9.10/release/"|grep "404"`" ]; then kdialog --msgbox "9.10 Released"; exit; fi; sleep 300;  done

Replacing in Found Files

Replace one string by another in all file found by find.


find . -name *whatyouwant* -exec perl -pi.bak -e 's/TEXT_TO_REPLACE/TEXT_TO_REPLACE_IT_WITH/g' {} \;

Regular Expression Twitter Linker

Regular expression to link twitter users…


Replace this '@(\w+)'
With this '<a href="http://twitter.com/\1">@\1</a>'

Object Or Array Check in JavaScirpt

Test whether an object is an object or an array


if(Object.prototype.toString.apply(arr) === '[object Array]') alert("Array")

Original Article

A Shell Scirpt to Mount ISO files

A Shell Scirpt to Mount ISO files – call it using the command moustiso.sh ImageFile.iso. You need a folder called /mnt/Image for this to work


#!/bin/sh
sudo mount -o loop "$*" /mnt/Image/

Delete Leading Whitespace

Delete leading whitespace (spaces/tabs/etc) from beginning of each line


ruby -pe 'gsub(/^\s+/, "")' < file.txt

Django server on custom Port

Running Django server on a custom Port


python manage.py runserver 8001

Install LAMP Stack on Ubuntu/Debian

Install LAMP Stack on Ubuntu/Debian using apt-get


sudo apt-get install openssh-server openssh-client apache2 libapache2-mod-php5 php5-cli php5-common php5-cgi  mysql-client mysql-common mysql-server php5-mysql php5-sqlite php5-gd phpmyadmin

Start a new Django Project

Command to start a new Django project…


django-admin.py startproject [PROJECT_NAME]
cd [PROJECT_NAME]
python manage.py startapp [PROJECT_NAME]