New Ultrasound Pics and Video

June 12th, 2008

Pics: http://www.flickr.com/photos/27569389@N05/sets/72157605563771842/

Video: http://video.google.com/videoplay?docid=1572162163126884009

Delete Everything Between an XML Tag Using SED

March 5th, 2008

sed -i -n -e “/[myblock]/{
p
: loop
n
/[\/myblockt]/!b loop
}
p” $xmlfile

Loading Output Lines of a Program into a Bash Array

March 4th, 2008

OIFS=$IFS
IFS=$’\n’

myarray=( $(./myprogram) )

IFS=$OIFS

for u in ${myarray[@]} ; do
echo $u
done

Editing Previous Line In Sed

December 6th, 2007

This can come in handy when trying to edit an XML in bash. Say you have an ‘enable=true’ attribute in an xml tag and there are many of these tags in an xml file:

[event enable=true]

You now want to disable any events that have the name giggady, but this name tag appears after the event line:

[event enable=true]
[name]giggady[/name]
[\event]
You can change this event to false with the following sed command:

sed -i ‘
/event/ {
N
/giggady/ {
s/true/false/
}
}’ ./d

Linux Kernel Packing Targets

November 30th, 2007

Easy way to distribute your kernel, just type make “target”
-
rpm: builds the kernel first and then creates an rpm package
rpm-pkg: source rpm for the kernel
binrpm-pkg: rpm package of kernel binaries
deb-pgk: debian package of kernel binaries
tar-pkg: tarball of kernel binaries
targz-pkg: gzipped tarball of kernel binaries
tarbz2-pkg: bzipped tarball of kernel bianries

Creating a bridge for Virtualbox

July 20th, 2007

chown root:vboxusers /dev/net/tun
chmod 0666 /dev/net/tun

#Add a bridge, add eth0
brctl addbr br0
ifconfig eth0 0.0.0.0 promisc
brctl addif br0 eth0
dhclient br0

# Create tap1
tunctl -t tap1 -u user_name

# Enable tap1
brctl addif br0 tap1
ifconfig tap1 up

Colors in Bash

April 13th, 2007

Variables for the color codes:
bold=$’\e[1m’
off=$’\e[0m’
underline=$’\e[4m’
reverse=$’\e[7m’

black=$’\e[30m’
red=$’\e[31m’
green=$’\e[32m’
yellow=$’\e[33m’
blue=$’\e[34m’
magenta=$’\e[35m’
cyan=$’\e[36m’
white=$’\e[37m’

bgblack=$’\e[40m’
bgred=$’\e[41m’
bggreen=$’\e[42m’
bgyellow=$’\e[43m’
bgblue=$’\e[44m’
bgmagenta=$’\e[45m’
bgcyan=$’\e[46m’
bgwhite=$’\e[47m

Source these variables and you can use colors like:
echo ${cyan}I am cyan${off}
If you don’t turn them off aftwars, your shell will always be in that color
If you want to get fancier
echo “${red}${bggreen}${underline}${bold}Im red with green background, underlined and bold{$off}

Handy Lock File Use in Bash

April 13th, 2007

You can trap the exit signal to automatically remove the lock file when the script exits. Start your script with:

LOCKFILE=/var/lock/mylock
[ -f $LOCKFILE ] && EXIT 0
trap “{rm -f $LOCKFILE; exit 255;} EXIT
touch $LOCKFILE

Using Optargs in Shell Scripts

April 13th, 2007

Just a quick example… it’s pretty straight forward.

unset a
unset b
while getopts “ab:” opt; do
case $opt in
a) echo “Option -a specified”;;
b) echo “Option -b specified with [$OPTARG]”;;
?) echo “Usage: $0: [-a] [-b value] args”
esac
done
shift $(($OPTIND - 1))
echo “Remaining Arguments are: $*”

Make Bash Scripts Better with Dialog

April 5th, 2007

The dialog command make creating ncurses menu applications easy.

Usage: dialog { –and-widget }
where options are “common” options, followed by “box” options

Special options:
[–create-rc “Ifile”]
Common options:
[–aspect ] [–backtitle ] [–beep] [–beep-after]
[–begin ] [–cancel-label ] [–clear] [–colors]
[–cr-wrap] [–default-item ] [–defaultno] [–exit-label ]
[–extra-button] [–extra-label ] [–help-button]
[–help-label ] [–ignore] [–item-help] [–max-input ]
[–no-cancel] [–no-collapse] [–no-kill] [–no-shadow]
[–ok-label ] [–output-fd ] [–print-maxsize] [–print-size]
[–print-version] [–separate-output] [–separate-widget ]
[–shadow] [–size-err] [–sleep ] [–stderr] [–stdout]
[–tab-correct] [–tab-len ] [–timeout ] [–title
[–trim] [–version]

More user friendly information can be found at:

http://www2.linuxjournal.com/article/2460

Linux Kernel Resources

April 5th, 2007

Two helpful books are now available under the Creative Commons Attribution-ShareAlike 2.5 license.

Linux Kernel In a Nutshell is source for information on how build and configure your kernel.
http://www.kroah.com/lkn/

If you want to learn about driver development, check out Linux Device Drivers V3 (LDD3)
http://lwn.net/Kernel/LDD3

The Linux Kernel Module Programming Guide is always a good read as well
http://www.tldp.org/LDP/lkmpg/2.6/html

Write your own filesystem
http://www.geocities.com/ravikiran_uvs/articles/rkfs.html

Simple Postfix Queue Handling

March 29th, 2007

To delete your entire queue
postsuper -d ALL

To delete individual messages
postsuper -d queue_id (delete)

To list your queue
postqueue -p

To flush your queue
postqueue -f

Display postfix settings
postconf -d

Edit postfix setting
postconf -e settings=value

Reload postfix config
postfix reload

Remote Connections for X

March 28th, 2007

It’s not usually a good idea to allow remote connections for X, but if you need it and ‘xhost +’

If it isn’t working out for you, X may not be listening on port 6000. Do a ‘ps -ef | grep nolisten’ to see if this is the case. If it is there are few files you can look at to disable this, depending on your display manager.

For gdm, you can edit the /etc/X11/gdm/gdm.con file and set DisallowTCP=false.

For kdm, you can edit the /etc/kde3/kdm/kdmrc file and comment out the line ‘ServerArgsLocal=-nolisten tcp’

For some distributions, check the /etc/sysconfig/displaymanager file for a line that reads
DISPLAYMANAGER_XSERVER_TCP_PORT_6000_OPEN=”no”
Change it to “yes”

Another place to check is /etc/X11/xdm/Xservers. Remove the ‘-nolisten tcp’ from the X start line.

Usefull Bash Tidbits

March 27th, 2007

Error Detecting in Variables
Error message if a variable does not exist:
A=${FOO:?”FOO does not exist”}
returns: -bash: foo: foo does not exist
error code of 1

Without error detection
A=${FOO}
returns: nothing
error code of 0

Size of String
FOO=IAMFOO
echo ${FOO}
IAMFOO
echo ${#FOO}
6

Indirect Expansion
FOO=IAMFOO
AGAIN=FOO
echo ${AGAIN}
FOO
echo ${!AGAIN}
IAMFOO

Replace all occurances in a string
TEST=${TEST//search/replace}  # note the two /’s

Parsing a GET String in Bash

March 23rd, 2007

This is for all the farmers in the valley. Keep it real up in the fields.
This assumes we don’t care about the names of the variable, they will be substituted out.
All the variables past in will be ‘title[1-12]’
If you want to keep the variables names, they can be stored in an array in the same manner as the values.

#Sample get string
string=’tile1=1&tile2=2&tile12=12′

OIFS=$IFS
IFS=”&”
set $string

#Remove any variables names we don’t want
#Store the values into an array
counter=0
for u in $string; do
new=${u/tile[1-9]*=/}
arr[counter]=$new;
let counter=$counter+1
done

IFS=$OIFS

#loop through the array and print out the variables
for u in ${arr[@]}; do
echo $u
done

Rubik’s 5×5x5 Parity Fix

March 21st, 2007

For the most part, the 5×5x5 can be solved in the same way as the 4×4x4, with one parity exception. Just solve the center, then line up the edges and solve like a 3×3x3.

The problem comes in lining up the edges. If you use the same method as a 4×4x4, you may end up with just 2 pieces that need to be swapped and no way to swap them with the normal method.

Align those pieces so they are on the left side of the the top layer and perform
R1-u2-R1-u2-R1-u2-R1-u2-R1-u2

This should give you three messed up edges which can be fixed with one of the normal edge moves.

Control Core Files

March 19th, 2007

Core files can of course be turned on and off by setting setting the ulimit in the shell. ‘ulimit -c 0′ to turn them off and ‘ulimit -c unlimited’ to allow a core of unlimited size.  Changing the number value passed in -c can limit the size of the core.

To change the name and location of a created core file, you can echo values to /proc/sys/kernel/core_pattern

Changing a core to be created in temp can be done with 'echo "/tmp/core.%p" > /proc/sys/kernel/core_pattern"
Other core naming options include:
  - %%  A single % character
- %p  PID of dumped process
- %u  real UID of dumped process
- %g  real GID of dumped process
- %s  number of signal causing dump
- %t  time of dump (secs since 0:00h, 1 Jan 1970)
- %h  hostname (same as the 'nodename'
returned by uname(2))
- %e  executable filename

Rubik’s 2×2x2 Final Step

March 17th, 2007

First do the top layer, it’s easy.

Get two of the bottom pieces in the right position, don’t worry about rotation.
If necessary,
1. To swap DFR, DBL do F’R'D’RDFD’
2. To swap DFR, DFL do FDF’D'R’D'R

Finally fix the last two pieces,
1. To twist DFL-, DBL+ do R’D'R F’ DR’DR D2F2
2. To twist DFL+, DBL- do F2D2 R’D'RD’ F R’DR
3. To twist DFL-, DBR+ do R2D’R D2R’D2R D’R2D
4. To twist DFR-, DRB-, DBL- do R’D'RD’ R’D2RD2
5. To twist DFR+, DRB+, DBL+ do D2R’D2R DR’DR
6. To twist DFR-, DRB+, DBL-, DLF+ do R2D2 R D2R2 D
7. To twist DFR+, DRB-, DBL-, DLF+ do RDF R2D2F2 DF’DR2

For more information, see
http://home.everestkc.net/ehess/cube2.html

Rubik’s 4×4x4 Final Steps

March 17th, 2007

If you can solve a 3×3x3, the 4×4x4 won’t be hard until the end. First solve the center squares on each face, then match up the edge peices. You can then solve the cube just a 3×3x3.

When you get to the last layer, there may be some pieces that need to be rotated.
These steps come from http://www.speedcubing.com

To rotate an edge peice, use:
r2 B2 U2 l U2 r’ U2 r U2 F2 r F2 l’ B2 r2

To swap two corners use:
(Uu)2 (Ll)2 U2 l2 U2 (Ll)2 (Uu)2 F’ U’ F U F R’ F2 U F U F’ U’ F R

For details on solving the 4×4x4 see the speed cubng site
http://www.speedcubing.com/chris/4speedsolve1.html

Writing OSX Start Scripts

March 9th, 2007

Start scripts for OSX are almost the as normal *nix start scripts, with just a slight syntax variation and a different location.

The scripts are located in either /Library/StartupItems or /System/Library/StartupItems

First create a folder for the service you wish to start on boot
mkdir /System/Library/StartupItems/Myapp
Read the rest of this entry »