Archive for the ‘Computer’ Category

Computer and Arduino controlled car (1:18)

Thursday, February 18th, 2010

So I decided to make something with RC-servos using the Arduino board and the sensor shield which I recently purchased.

I went ahead figuring out how to send arrow signals from my computer to Arduino using USB interface.

Using void setup() { Serial.begin(9600); } on Arduino and screen /dev/ttyUSB0 9600 on my computer, I managed to send commands back and forth. I hooked up the standard servo library and write some code before I mounted the Arduino board on my mini rock crawler. I now had a computer controlled car. Because of Arduino`s simple interface I had it all up and running around an hour. Check the small video and code below.

You can view and or use the code as you like below. (Sorry about the indention, Wordpress messes it up).

//
// LIBRARY
//
#include <Servo.h>

//
// OBJ
//
Servo servo1;
Servo servo2;

// VARS
int readByte;
int servo1Angle = 90; //default servo angle
int servo2Angle = 90;

int minPulse = 700; // minimum servo position
int maxPulse = 2300; // maximum servo position

void setup()
{
servo1.attach(2, minPulse, maxPulse); //connect servo
servo2.attach(3, minPulse, maxPulse);

Serial.begin(9600); // start serial
Serial.println(“Ready\n”);
}

void loop()
{
if (Serial.available() > 1) // procced when two bytes is avaiable
{
readByte; = Serial.read(); //read first byte
if (readByte; == 91)
{
readByte; = Serial.read(); //read second byte to determine arrow type
if (readByte; == 65 && servo1Angle <= 180) //UP
{
servo1Angle += 5;
}
else if(readByte; == 66 && servo1Angle >= 0) //DOWN
{
servo1Angle -= 5;
}
else if(readByte; == 67 && servo2Angle <= 180) //RIGHT
{
servo2Angle += 5;
}
else if(readByte; == 68 && servo2Angle >= 0) //LEFT
{
servo2Angle -= 5;
}

}
}
// set servo positions
servo1.write(servo1Angle);
servo2.write(servo2Angle);
delay(15);
}

Re wounding a brush less mini motor

Friday, November 27th, 2009

After running this motor to hard outside, I managed to burn the motor. You can see pictures of the “burnt” motor in the gallery below.

First of all I opened the motor to take a look noticing protective isolation layer on the copper were melted. Not so strange, because when I approaced the motor after the plane fell from the sky, it was insane hot.

Before removing all wire I measured the wire diameter to 0,30mm. I found this king of wire inside very small tranformators in a computer power supply.

By using this picutre, found on this page. I was able to re wound the motor.

I actually did wound all the poles at the same time, well, one by one, but all three wires were in use, if you follow.

After finish wounding I had to connect wires together to make only three wires, brush less motor has three out wires.

Since it`s a pretty fast motor I made a delta hookup, but I did a mistake at first. This motor should have around 195mOhm per 14-turn, maybe I did not mention it is a 14-turn motor. Which means each pole (there are nine here) needs 14 turns of isolated copper wire and in a small motor like this one, it`s not that easy. Anyway, by hooking up wrong end`s I broke a ESC of mine ($10) so I had to buy another one.

The motor works just great now and I might add a video later.

Gallery

Fixing brushless motor

Installing Frets On Fire on Ubuntu by making .deb package

Sunday, November 8th, 2009

sudo apt-get install dh-make
mkdir fretsonfire-1.3.110
cd fretsonfire-1.3.110
dh_make -s -n
cd debian
rm *.ex *.EX
mkdir fretsonfire
mkdir fretsonfire/usr
mkdir fretsonfire/usr/share

Now download the game
wget http://downloads.sourceforge.net/fretsonfire/FretsOnFire-1.3.110.tar.gz?use_mirror=osdn
tar zxf FretsOnFire-1.3.110.tar.gz
mv Frets\ on\ Fire-1.3.110/ fretsonfire/usr/share/fretsonfire
rm -rf Frets\ on\ Fire-1.3.110/ FretsOnFire-1.3.110.tar.gz

mkdir fretsonfire/DEBIAN
pico control

Make sure it look something like this
Source: fretsonfire
Priority: optional
Section: universe/games
Maintainer: yourname
Homepage: http://fretsonfire.sourceforge.net/
Package: fretsonfire
Architecture: all
Version: 1.3.110
Depends: python-pygame, python-opengl, python-numpy
Description: Open source guitar game

cp control fretsonfire/DEBIAN/
mkdir fretsonfire/usr/bin
echo -e "#\!/bin/dash\ncd /usr/share/fretsonfire/src/\npython FretsOnFire.py" > fretsonfire/usr/bin/fretsonfire
chmod +x fretsonfire/usr/bin/fretsonfire
mkdir fretsonfire/usr/share/pixmaps

# if the following image does not exist, find another one through google
wget http://www.freedownloadsplace.com/photo/Frets-on-Fire-1.png -O fretsonfire/usr/share/pixmaps/fretsonfire.png
mkdir fretsonfire/usr/share/applications
pico fretsonfire/usr/share/applications/fretsonfire.desktop

Overwrite with this text
[Desktop Entry]
Version=1.3.110
Type=Application
Name=Frets On Fire
Comment=A opensourced guitar game
Icon=fretsonfire
Exec=fretsonfire
Terminal=false
Categories=Game;ArcadeGame;

cd ..
dh_builddeb
cd ..
dpkg -i fretsonfire_1.3.110_all.deb

Ubuntu network install (PXE)

Sunday, October 25th, 2009

sudo apt-get install tftpd-hpa tftp-hpa xinetd dhcp3-server
sudo pico /etc/xinetd.d/tftp

Then write following

service tftp
{
protocol = udp
port = 69
socket_type = dgram
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = /var/lib/tftpboot
disable = no
}

Edit TFTP config
sudo pico /etc/default/tftpd-hpa

Make it look something like

#Defaults for tftpd-hpa
RUN_DAEMON="yes"
OPTIONS="-l -s /var/lib/tftpboot"

Create TFTP directory and get latest netboot image

sudo mkdir /var/lib/tftpboot
cd /var/lib/tftpboot
sudo wget -np -r http://archive.ubuntu.com/ubuntu/dists/karmic/main/installer-i386/current/images/netboot/
sudo mv archive.ubuntu.com/ubuntu/dists/karmic/main/installer-i386/current/images/netboot/* .
sudo rm -rf archive.ubuntu.com

Now restart TFTPD
sudo /etc/init.d/tftpd-hpa restart

To check if running@
netstat -uap

For DHCP, make sure you have a fixed ip for your device
pico /etc/dhcp3/dhcpd.conf

I did use firestarter as a DHCP generator since I used my desktop as PXE-server.


# DHCP configuration generated by Firestarter
ddns-update-style interim;
ignore client-updates;
authoritative;

subnet 192.168.66.0 netmask 255.255.255.0 {
option routers 192.168.66.9;
option subnet-mask 255.255.255.0;
option domain-name-servers 130.67.60.68, 193.213.112.4;
option ip-forwarding off;
range dynamic-bootp 192.168.66.10 192.168.66.20;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.66.9; # important for PXE
filename "pxelinux.0"; # important for PXE
}

After the DHCP change we must restart DHCP
sudo /etc/init.d/dhcp3 restart

You should now be able to boot PXE of this machine.

NES emulator written JavaScript!

Friday, October 9th, 2009

http://benfirshman.com/projects/jsnes/

Speaks for itself.

Semilog graph render

Sunday, September 6th, 2009

Ever since we had this laboratory task were we had to figure out which degree of filter (electronic), I couldn`t find a online semilog graph render for this task. It ended by doing it the old way. Print a sheet of semilog paper and manually plot values. I started writing a program for this myself, but I didn`t finish it before now.

It`s still beta, but you can try it out at http://vegard.hammerseth.com/semilogrender/

Ubuntu 9.04 on MacBookPro5,3

Thursday, August 20th, 2009

How I installed Ubuntu Jaunty Jackalope 9.04 on my MacBook Pro 5,3.

After you have installed Ubuntu on your MBP and connected to internet. We need to add some lines in sources.list to be able to get special packages developed for apple products.

WARNING: be carefull with all the ” when pasting, they tend to change into a similar sign!

Update
echo deb http://ppa.launchpad.net/mactel-support/ubuntu jaunty main | sudo tee -a /etc/apt/sources.list
echo deb-src http://ppa.launchpad.net/mactel-support/ubuntu jaunty main | sudo tee -a /etc/apt/sources.list
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 7A6BC20C4FE04DADD10837608DB7F87A2B97B7B8 (DONT WORK)

sudo apt-get update
sudo apt-get upgrade

REBOOT (recommended)

Get hardware packages
sudo apt-get install mbp-nvidia-bl-dkms applesmc-dkms hal-applesmc bcm5974-dkms lm-sensors

Reboot if you want it to work right away or just continue below.

Keyboard
Apple keyboard backlight and Fn-keys should now work.
If you want to change the fn-usage buttons.

echo options hid_apple fnmode=2 | sudo tee -a /etc/modprobe.d/hid_apple.conf
sudo update-initramfs -u

I like to use gnome-do and usually use the Menu key for this. You will be prompted for next login, make sure you load the file.te
keycode 252 = Super_R
echo keysym Super_R = Menu | tee -a .xmodmaprc

If you`re having problems getting the $ or brackets (and more) we need to do edit your keyboard layout. Go to Gnome menu -> preferences -> keyboard -> layout and change keyboard model to apple and make sure you have the right layout selected.

Sensors
For using sensors and fans we need to load apple modules:

echo coretemp | sudo tee -a /etc/modules
echo applesmc | sudo tee -a /etc/modules

Reboot (optional).

Caps lock
By default the green caps-lock does not work. It´s a easy fix.

sudo apt-get remove mouseemu

Monitor
If you don`t like the way your MBP auto dim your screen, you can disable it.

gconftool -s /apps/gnome-power-manager/ambient/enable -t bool false

Touchpad
To get multitouch we need to do a little trick.

echo bcm5974 | sudo tee -a /etc/modules
echo usbhid | sudo tee -a /etc/modules
echo blacklist usbhid | sudo tee -a /etc/modprobe.d/blacklist.conf

Open /etc/hal/fdi/policy/x11-synaptics-bcm5974.fdi and paste.
sudo gedit /etc/hal/fdi/policy/x11-synaptics-bcm5974.fdi

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
 <device>
  <match key="info.capabilities" contains="input.touchpad">
   <match key="info.product" contains="bcm5974">
   <merge key="appledevice" type="bool">true</merge>
   </match>

   <match key="appledevice" bool="true">
        <merge key="input.x11_driver" type="string">synaptics</merge>
        <merge key="input.x11_options.SHMConfig" type="string">1</merge>

        <merge key="input.x11_options.FingerLow" type="string">40</merge>
        <merge key="input.x11_options.FingerHigh" type="string">70</merge>
        <merge key="input.x11_options.ClickFinger1" type="string">1</merge>
        <merge key="input.x11_options.ClickFinger2" type="string">3</merge>
        <merge key="input.x11_options.ClickFinger3" type="string">2</merge>
        <merge key="input.x11_options.TapButton1" type="string">1</merge>
        <merge key="input.x11_options.TapButton2" type="string">3</merge>
        <merge key="input.x11_options.TapButton3" type="string">2</merge>

        <merge key="input.x11_options.VertEdgeScroll" type="string">false</merge>
        <merge key="input.x11_options.HorizEdgeScroll" type="string">false</merge>
        <merge key="input.x11_options.VertTwoFingerScroll" type="string">1</merge>
        <merge key="input.x11_options.HorizTwoFingerScroll" type="string">1</merge>

        <merge key="input.x11_options.MinSpeed" type="string">0.5</merge>
        <merge key="input.x11_options.MaxSpeed" type="string">2.5</merge>
        <merge key="input.x11_options.AccelFactor" type="string">0.15</merge>

        <merge key="input.x11_options.PalmDetect" type="string">0</merge>
        <merge key="input.x11_options.PalmMinWidth" type="string">25</merge>
        <merge key="input.x11_options.PalmMinZ" type="string">250</merge>
   </match>
  </match>
 </device>
</deviceinfo>

Reboot (optional).

Sound
Follow this recipe and your sound should work.


sudo apt-get install linux-headers-generic linux-image-generic linux-restricted-modules-generic
wget ftp://ftp.kernel.org/pub/linux/kernel/people/tiwai/snapshot/alsa-driver-unstable-snapshot.tar.gz
tar xf alsa-driver-unstable-snapshot.tar.gz
cd alsa-driver-unstable
sudo ./configure --enable-dynamic-minors --with-cards="hda-intel" --with-oss
sudo make
sudo make install
cd ..
sudo rm -rf alsa-driver-unstable alsa-driver-unstable-snapshot.tar.gz

REBOOT (recommended)

Now, don´t forget to unmute sound channels.

If you´d want a automatic fan program, I wrote one in bash. It requires lm-sensors (installed above) to work. I will write it in C some day.
#!/bin/bash

# we don`t want to go all the way up to critiacal temp, safe_temp is substracted from critical temp
SAFE_TEMP=10

# AUTOMATIC VALUES BELOW, DON`T EDIT

# CPU critical temp
CPU_CRIT=`cat /sys/devices/platform/coretemp.0/temp1_crit`

# FAN SPEED
FAN1_SPEED_MIN=`cat /sys/devices/platform/applesmc.768/fan1_min`
FAN1_SPEED_MAX=`cat /sys/devices/platform/applesmc.768/fan1_max`
FAN2_SPEED_MIN=`cat /sys/devices/platform/applesmc.768/fan2_min`
FAN2_SPEED_MAX=`cat /sys/devices/platform/applesmc.768/fan2_max`
CPU_CRIT=`expr "(" "$CPU_CRIT" "/" 1000 ")" "-" "$SAFE_TEMP"`

echo 1 > /sys/devices/platform/applesmc.768/fan1_manual
echo 1 > /sys/devices/platform/applesmc.768/fan2_manual

# dynamic values
while [ 1 ]; do

# CPU TEMPS
CPU_TEMP0=`cat /sys/devices/platform/coretemp.0/temp1_input`
CPU_TEMP1=`cat /sys/devices/platform/coretemp.1/temp1_input`
CPU_TEMP=`expr "(" $CPU_TEMP0 + $CPU_TEMP1 ")" "/" 2000`

# calculate
FAN_SPEED=`expr "(" $CPU_TEMP "-" 34 ")" "*" 200`

# if CPU reaches critical - SAFE_TEMP, shut off
if [ "$CPU_TEMP" -gt "$CPU_CRIT" ]; then
shutdown -h now
fi

# don`t go below min limit
if [ "$FAN_SPEED" -le "$FAN1_SPEED_MIN" ]; then
FAN_SPEED=$FAN1_SPEED_MIN;
fi

# don`t go above max limit
if [ "$FAN_SPEED" -gt "$FAN1_SPEED_MAX" ]; then
FAN_SPEED=$FAN1_SPEED_MAX;
fi

# only write if speed has changed
if [ "$FAN_SPEED" != "$FAN_SPEED_OLD" ]; then
#echo $CPU_TEMP $FAN_SPEED
echo $FAN_SPEED > /sys/devices/platform/applesmc.768/fan1_output
echo $FAN_SPEED > /sys/devices/platform/applesmc.768/fan2_output
fi

# store old speed
FAN_SPEED_OLD=$FAN_SPEED;

sleep 5
done

Pommed
If you would like to install pommed on this machine at this time we have to modify pommed. I have notified creator of pommed about macbook5,3 support. If you have version above 1.27 you can skip this how to.

wget https://alioth.debian.org/frs/download.php/3084/pommed-1.27.tar.gz
tar zxf pommed-1.27.tar.gz
cd pommed-1.27/pommed/
pico pommed-mpb5,3.patch

Then paste following.
--- pommed.c-old 2009-08-22 20:23:21.796989322 +0200
+++ pommed.c 2009-08-22 20:22:42.270020918 +0200
@@ -677,6 +677,7 @@
* MacBook Pro 13" (June 2009) */
else if ((strcmp(buf, "MacBookPro5,1") == 0)
|| (strcmp(buf, "MacBookPro5,2") == 0)
+ || (strcmp(buf, "MacBookPro5,3") == 0)
|| (strcmp(buf, "MacBookPro5,5") == 0))
ret = MACHINE_MACBOOKPRO_5;
/* Core Duo MacBook (May 2006) */

Now apply the patch
patch -p0 < pommed-mpb5,3.patch

Install required packages
sudo apt-get install pommed libdbus-1-dev libalsa-ocaml-dev libaudiofile-dev libconfuse-dev libpci-dev

Compile
cd ..
make pommed
sudo cp pommed/pommed /usr/sbin/pommed

Reboot.

Read additional info here.

Recruiting more people to IRC

Friday, July 24th, 2009

We are a few people on our IRC channel(s), talking and helping eachother about RC related stuff.

The problem with IRC or should I say people, is their ability to turn on everything out of their knowledge. IRC can be tricky at first, but it gives you a nice playroom.

To recruite people I had to find a simple way to connect people to IRC and join our channel. A quick google search found web-irc linking to antoher site running CGIIRC. It’s a client which runs on a webserver through your browser and can connect you directly to desired channel. When people get used and addicted to IRC, they will install a decent client locally.

My next step was to get people interested. A way of doing this is by giving them some of our conversations and not just a few, but the latest conversations. By doing this, people will (or should) get interested in connecting.

So, how will I give them our conversations? through a image. Because it’s the only way I can update anything on remote sites such as forums and not letting any one just copy our conversations.

I will now explain how I did it. I will assume you are  a fellow geek and know what I’m talking about, if not, just google the unknown words.

To get latest conversations on our network I ran a eggdrop on our channel on logging modus. The eggdrop is running on the same server as my web server, making it easy to get the required text.

$file = “../../../eggdrop/logs/#rchobby.log”; // this is where my conversations are
$r = $g = $b = 255;
$lines = 8;
$width = 600;
$size = 10;
$text = array();

/* read file and get number of wanted lines */
foreach (array_slice(file($file),-$lines) as $x)
{
$x = str_replace(“<motor> (EFnet) “,”",$x); // have to remove some crap since we have linked networks
$x = preg_replace(“/^\[(\d{2})\:(\d{2})\] <(.*)>/”,”[\\1:\\2] (\\3)”,$x); // custom display format
$x = utf8_encode($x); // to support norwegian characters such as ø æ å
/* split up long sentences to fit width*/
$x = wordwrap($x,$width*0.15); // text can go utside the image, therefore we split it
foreach (explode(“\n”,$x) as $y)
{
if (!empty($y))
{
$text[] = $y;
}
}
}
/* define image and background color */
$image = imagecreate($width,count($text)*11); // create image object
$bgColor = imagecolorallocate($image,$r,$g,$b); // set background color
/* print text with desired font */
$x = $size;
foreach ($text as $line)
{
imagettftext($image,$size,0,0,$x,imagecolorallocate($image,0,0,0),”./ProFontWindows.ttf”,$line); // custom font
$x += $size;
}

imagettftext($image,25,-10,30,30,imagecolorallocatealpha($image,255,0,0,60),”./ProFontWindows.ttf”,”CLICK TO CHAT RC!”); // making it more professional, like a stamp

/* tell browser not to cache, conversation updates */
header(“Cache-Control: no-store, no-cache, must-revalidate”);
header(“Pragma: no-cache”);

/* send png image to browser */
header(“Content-type: image/png”);
imagepng($image);

?>

Now we have a file that displays a image with a given number of lines, but what about customizing colours and number of lines? to match designs on different forums. The solution is simple.

If we add following after variable defining we should be set.

/* custom color */
if (isset($_GET['r']) && is_numeric($_GET['r']) && $_GET['r'] >= 0 && $_GET['r'] <= 255)
{
$r = $_GET['r'];
}
if (isset($_GET['g']) && is_numeric($_GET['g']) && $_GET['g'] >= 0 && $_GET['g'] <= 255)
{
$g = $_GET['g'];
}
if (isset($_GET['b']) && is_numeric($_GET['b']) && $_GET['b'] >= 0 && $_GET['b'] <= 255)
{
$b = $_GET['r'];
}

/* number of lines to display */
if (isset($_GET['lines']) && is_numeric($_GET['lines']) && $_GET['lines'] > 0 && $_GET['lines'] <= 100)
{
$lines = $_GET['lines'];
}

/* image width */
if (isset($_GET['width']) && is_numeric($_GET['width']) && $_GET['width'] > 0 && $_GET['width'] <= 1280)
{
$width = $_GET['width'];
}

/* font size */
if (isset($_GET['size']) && is_numeric($_GET['size']) && $_GET['size'] > 0)
{
$size = $_GET['size'];
}

We’d want to make the image click able, linking it to our web based IRC client. We can also put it in the same file to make it simple and easy to maintain.

My complete program ended looking like this.

<?php
/* we want to display image */
if (isset($_GET['img']))
{
/* define vars */
$file = “../../../eggdrop/logs/#rchobby.log”;
if (!file_exists($file))
{
$file .= “.yesterday”;
}
$r = $g = $b = 255;
$lines = 8;
$width = 600;
$size = 10;

/* custom color */
if (isset($_GET['r']) && is_numeric($_GET['r']) && $_GET['r'] >= 0 && $_GET['r'] <= 255)
{
$r = $_GET['r'];
}
if (isset($_GET['g']) && is_numeric($_GET['g']) && $_GET['g'] >= 0 && $_GET['g'] <= 255)
{
$g = $_GET['g'];
}
if (isset($_GET['b']) && is_numeric($_GET['b']) && $_GET['b'] >= 0 && $_GET['b'] <= 255)
{
$b = $_GET['r'];
}

/* number of lines to display */
if (isset($_GET['lines']) && is_numeric($_GET['lines']) && $_GET['lines'] > 0 && $_GET['lines'] <= 100)
{
$lines = $_GET['lines'];
}

/* image width */
if (isset($_GET['width']) && is_numeric($_GET['width']) && $_GET['width'] > 0 && $_GET['width'] <= 1280)
{
$width = $_GET['width'];
}

/* font size */
if (isset($_GET['size']) && is_numeric($_GET['size']) && $_GET['size'] > 0)
{
$size = $_GET['size'];
}
$text = array();

/* read file and get number of wanted lines */
foreach (array_slice(file($file),-$lines) as $x)
{
$x = str_replace(“<motor> (EFnet) “,”",$x);
$x = preg_replace(“/^\[(\d{2})\:(\d{2})\] <(.*)>/”,”[\\1:\\2] (\\3)”,$x);
$x = utf8_encode($x);

/* split up long sentences to fit width*/
$x = wordwrap($x,$width*0.15);
foreach (explode(“\n”,$x) as $y)
{
if (!empty($y))
{
$text[] = $y;
}
}
}

/* define image and background color */
$image = imagecreate($width,count($text)*11);
$bgColor = imagecolorallocate($image,$r,$g,$b);

/* print text with desired font */
$x = $size;
foreach ($text as $line)
{
imagettftext($image,$size,0,0,$x,imagecolorallocate($image,0,0,0),”./ProFontWindows.ttf”,$line);
$x += $size;
}

imagettftext($image,25,-10,30,30,imagecolorallocatealpha($image,255,0,0,60),”./ProFontWindows.ttf”,”CLICK TO CHAT RC!”);

/* don’t cache */
header(“Cache-Control: no-store, no-cache, must-revalidate”);
header(“Pragma: no-cache”);

/* send image to browser */
header(“Content-type: image/png”);
imagepng($image);
return;
}

?>
<html>
<head>
<title>#rchobby @ quakenet connecter</title>
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8″/>
<meta name=”description” content=”#rchobby on Quakenet.org”/>
</head>
<body>
<strong>Want to chat? click and connect!</strong><br />
<form method=”post” action=”http://portalzona.com/cgi-bin/cgiirc/irc.cgi”>
<input type=”hidden” name=”interface” value=”mozilla”>
Your nickname <input type=”text” id=”nickname” name=”Nickname” value=”rchobby<?php echo mt_rand(100,999); ?>” />
<input type=”hidden” name=”Server” value=”irc.quakenet.org” />
<input type=”hidden” name=”Port” value=”6667″ />
<input type=”hidden” name=”Channel” value=”#rchobby” />
<input type=”hidden” name=”Password” value=”" />
<input type=”submit” value=”CLICK TO CONNECT” />
</form>
<br /><br /><br />
<strong>If you want to customize the image output, you can use following settings and copy image location.</strong><br /><br />
<u>Color settings for background</u><br />
<form method=”get” action=”">
Red &nbsp; &nbsp; <input type=”text” name=”r” length=3 value=”<?php echo (isset($_GET['r'])?$_GET['r']:255); ?>” size=1 /><br />
Green <input type=”text” name=”g” length=3 value=”<?php echo (isset($_GET['g'])?$_GET['g']:255); ?>” size=1 /><br />
Blue &nbsp;&nbsp; <input type=”text” name=”b” length=3 value=”<?php echo (isset($_GET['b'])?$_GET['b']:255); ?>” size=1 /><br />
<br />
<u>Text settings</u><br />
Font size <input type=”text” name=”size” length=2 value=”<?php echo (isset($_GET['size'])?$_GET['size']:10); ?>” size=1 /> pixels<br />
Image width <input type=”text” name=”width” length=4 value=”<?php echo (isset($_GET['width'])?$_GET['width']:600); ?>” size=2 /> pixels<br />
Numer of lines <input type=”text” name=”lines” length=3 value=”<?php echo (isset($_GET['lines'])?$_GET['lines']:8); ?>”  size=1 /><br />
<input type=”submit” value=”Display” />
</form>
<img src=”rchobby.php?img&<?php foreach ($_GET as $key=>$val) { echo “$key=$val&”; } ?>” alt=”" />
<script type=”text/javascript”>document.getElementById(‘nickname’).focus();</script>
</body>

This is the result
img

Spotify invitering

Thursday, February 12th, 2009

Jeg kom over en norsk side som samler opp spotify inviteringer. Den virket for meg sÃ¥ anbefaler at du gir den et forsøk. Husk Ã¥ skriv “Ja” i feltet.

Backup your data with cron, rsync and lftp

Thursday, February 12th, 2009

This post will explain how I do my backups.

In case my crontab should be deleted or lost, I have the script in an own file. Like in my code-nippets.

My computer is only used by me so I only need to backup my home-dir, where I save everything. /dev/sda5 is mounted to /home.

This script backups my home directory to one of my external harddrives, as long as the backup dir on the disk hasn’t been edited the last day and rsync is not running. Off course, rsync could run in other situations, but I don’t want to run two rsync’s at once and is therefore added as a case. It would probably consume all the bandwidth on my laptop when running two rsyncs on my slow 5400rpm harddrive.

if [ -d "/media/WD Elements/backup/" ] && [ -z "`ps --no-heading -C rsync`" ] && [ "`ls -ld /media/WD\ Elements/backup | awk '{print $6}'`" != "`date '+%Y-%m-%d'`" ];
then
rsync -au --force --delete-during /home/vegard/. /media/WD\ Elements/backup;
fi

Code above is from “/home/vegard/Linux/backup.sh” which runs every 5 min, using crontab. Use `crontab -e` to insert your cron-rule.

*/5 * * * * /bin/bash /home/vegard/Linux/backup.sh

Keeping backup of your webhotel is also important, and since I’m allowed ssh access to mine I can use sftp to download my files.

In “/home/vegard/Linux/sftp.sh” i have:
lftp -e "mirror . /home/vegard/Backup/hammerseth.com/" sftp://<user>@<host>/path

For the password, you can use ssh-keyrigs or if you dare sftp://<user>:<passwd>@<host>/path

The file above is run each sunday at 18:00 with this cron-rule
0 18 * * 0 /bin/bash /home/vegard/Linux/sftp.sh

I should also mention that I’m using a wordpress-plugin called Wordpress Database Backup which mails all my database tables to my email, every week. Quite handy.

Be safe.