Saturday, 15 June 2013

Howto enable AHCI Mode MacBookPro1,2 and MacBookPro4,1

I added this after insmod ext2 in grub:

setpci -s 0:1f.2 90.b=40

This sets Intel ICH7 (page 509) or ICH8 (page 486) controller into AHCI mode.

A similar command will probably work for other ICHx devices.

I got my bus:slot.function from running lspci - take value from line that states SATA IDE mode


00:1f.2 SATA controller: Intel Corporation 82801GBM/GHM (ICH7-M Family) SATA Controller [IDE mode] (rev 02)

Both MBP1,2 and MBP4,1 have same bus:slot.function and use same value (40h) to put controller into AHCI mode.

UPDATE: Should be MacBookPro1,2 not MacBookPro2,1

Monday, 3 June 2013

Root Huawei X3 8150 Without Windows or a Working Touchscreen

I got some of this from here

Some phone modes


Disconnect USB.
Power-off phone.
RED+VOL-DN+POWER - hold for about 5 seconds. Phone will vibrate and show a white screen with IDEOS displayed.
Connect USB.


Disconnect USB.
Power-off phone.
GREEN+VOL-UP+POWER - hold for about 5 seconds. Phone will vibrate, show a white screen with IDEOS displayed and then show Recovery menu.
Connect USB.

Enter DOWNLOAD mode

Disconnect USB.
Power-off phone.
RED+GREEN+POWER - hold for a few seconds until screen turns pink/magenta.
Connect USB.
(This does not work for me under Linux)

Replace Stock Recovery with ClockWork Recovery

Install Android SDK
From ubuntu this is very easy now:
apt-get install android-tools-adb
apt-get install android-tools-fastboot
Open root terminal or open terminal and sudo su.

Check that all is well, that USB connection is working and that ADB is correctly installed

Enter RECOVERY mode
Phone should boot into 'Android system recovery'

# adb devices
List of devices attached 
308730C82377 recovery

Enter FASTBOOT mode

# fastboot erase recovery
erasing 'recovery'...
OKAY [  0.033s]
finished. total time: 0.033s

Get ClockWorkMod Recovery
All available Recovery's are here:

Get ClockWork Recovery fro IDEOS
I used

# fastboot flash recovery /home/phil/Downloads/recovery-clockwork- 
sending 'recovery' (3796 KB)...
OKAY [  0.255s]
writing 'recovery'...
OKAY [  0.806s]
finished. total time: 1.061s

# fastboot reboot
Phone should reboot.

Get Root
Get files from

# adb push ../../rootme/rageagainstthecage-arm5.bin  /data/local/tmp
127 KB/s (5392 bytes in 0.041s)

# adb ls /data/local/tmp
000041fd 00000000 51208853 .
000041fd 00000000 51208845 ..
000081b6 00001510 4c77ab24 rageagainstthecage-arm5.bin

# adb shell
~ # cd /data/local/tmp
/data/local/tmp # chmod 0755 rageagainstthecage-arm5.bin 
/data/local/tmp # ./rageagainstthecage-arm5.bin 
/sbin/sh: ./rageagainstthecage-arm5.bin: not found

I give up. I'll exit shell and try again.

/data/local/tmp # exit

# adb shell
~ # whoami

Hmm. It seem I was already root! I suspect that SuperuserOneClick that I experimented with - but did not log - using mono under linux may have worked - although I had no indication that it did.

I'll carry on.

Next I remount mdtblock4 to be able to write to it.

~ # mount -o rw,remount /dev/block/mdtblock4 /system
mount: mounting /dev/block/mdtblock4 on /system failed: Invalid argument

But it seems it is not mounted.

~ # mount          
rootfs on / type rootfs (rw)
tmpfs on /dev type tmpfs (rw,relatime,mode=755)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
/dev/block/mtdblock5 on /cache type yaffs2 (rw,nodev,noatime,nodiratime)

~ # df
Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                    91624        32     91592   0% /dev
/dev/block/mtdblock5     95232      1688     93544   2% /cache

In my case, mtdblock4 is not mounted so I mounted it.

~ # mount /dev/block/mtdblock4 /system

~ # ls /system/
app         etc         lib         tts         xbin
bin         fonts       lost+found  usr
build.prop  framework   media       wifi

Now I realise that I made a typo: I entered mdtblock4 instead of mtdblock4.

~ # mount -o rw,remount /dev/block/mtdblock4 /system 
~ # df
Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                    91624        32     91592   0% /dev
/dev/block/mtdblock5     95232      1688     93544   2% /cache
/dev/block/mtdblock4    174080    131780     42300  76% /system

Ok. mtdblock4 is now writeable.

Copy su, busybox, sqlite3, Superuser.apk to device.

# adb push rootme/su  /system/bin/su
837 KB/s (26264 bytes in 0.030s)

# adb push SuperOneClickv2.3.3-ShortFuse\ \(1\)/Dependencies/busybox  /system/bin/busybox
1978 KB/s (1075144 bytes in 0.530s)

# adb push SuperOneClickv2.3.3-ShortFuse\ \(1\)/Dependencies/sqlite3  /system/bin/sqlite3
333 KB/s (24120 bytes in 0.070s)

# adb push SuperOneClickv2.3.3-ShortFuse\ \(1\)/Root/  /system/bin/sqlite3
Superuser.apk  su-v1          su-v2          

# adb push SuperOneClickv2.3.3-ShortFuse\ \(1\)/Root/Superuser.apk  /system/app/Superuser.apk
2095 KB/s (843503 bytes in 0.393s)

Now to change permissions.

# adb shell
~ # cd /system/bin
/system/bin # chmod 4755 su
/system/bin # chmod 4755 busybox 
/system/bin # chmod 4755 sqlite3 

/system/bin # cat /proc/cpu
/proc/cpu/     /proc/cpuinfo

What CPU do we have?

/system/bin # cat /proc/cpuinfo 
Processor : ARMv6-compatible processor rev 2 (v6l)
BogoMIPS : 594.73
Features : swp half thumb fastmult edsp java 
CPU implementer : 0x41
CPU architecture: 6TEJ
CPU variant : 0x1
CPU part : 0xb36
CPU revision : 2

Hardware : HUAWEI U8150 BOARD 
Revision : 0000
Serial : 0000000000000000

Mount /data using ClockWorkMod Recovery
(could have done this using adb)

/system/bin # df
Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                    91624        32     91592   0% /dev
/dev/block/mtdblock5     95232      1688     93544   2% /cache
/dev/block/mtdblock4    174080    133716     40364  77% /system
/dev/block/mtdblock6    170624     12340    158284   7% /data

/data is mounted and this seems to be where settings are stored.
 Open settings using sqlite3

/system/bin # ./sqlite3 /data/data/ 
SQLite version 3.6.22
Enter ".help" for instructions
sqlite> .dump
CREATE TABLE android_metadata (locale TEXT);
INSERT INTO "android_metadata" VALUES('en_AU');
INSERT INTO "system" VALUES(4,'volume_voice','4');
INSERT INTO "system" VALUES(5,'volume_alarm','6');
INSERT INTO "system" VALUES(6,'volume_notification','5');
INSERT INTO "system" VALUES(7,'volume_bluetooth_sco','7');
INSERT INTO "system" VALUES(9,'vibrate_on','6');
INSERT INTO "system" VALUES(10,'mode_ringer_streams_affected','166');
INSERT INTO "system" VALUES(11,'mute_streams_affected','46');
INSERT INTO "system" VALUES(12,'dim_screen','1');
INSERT INTO "system" VALUES(13,'stay_on_while_plugged_in','0');
INSERT INTO "system" VALUES(14,'screen_off_timeout','60000');
INSERT INTO "system" VALUES(15,'emergency_tone','0');
INSERT INTO "system" VALUES(16,'call_auto_retry','0');
INSERT INTO "system" VALUES(17,'dtmf_tone_type','0');
INSERT INTO "system" VALUES(18,'hearing_aid','0');
INSERT INTO "system" VALUES(19,'tty_mode','0');
INSERT INTO "system" VALUES(20,'airplane_mode_on','0');
INSERT INTO "system" VALUES(21,'airplane_mode_radios','cell,bluetooth,wifi');
INSERT INTO "system" VALUES(22,'airplane_mode_toggleable_radios','wifi');
INSERT INTO "system" VALUES(23,'auto_time','1');
INSERT INTO "system" VALUES(24,'screen_brightness','77');
INSERT INTO "system" VALUES(25,'screen_brightness_mode','0');
INSERT INTO "system" VALUES(26,'window_animation_scale','0.0');
INSERT INTO "system" VALUES(27,'transition_animation_scale','0.0');
INSERT INTO "system" VALUES(28,'accelerometer_rotation','1');
INSERT INTO "system" VALUES(29,'haptic_feedback_enabled','1');
INSERT INTO "system" VALUES(30,'end_button_behavior','1');
INSERT INTO "system" VALUES(31,'notification_light_pulse','1');
INSERT INTO "system" VALUES(32,'set_install_location','0');
INSERT INTO "system" VALUES(33,'default_install_location','0');
INSERT INTO "system" VALUES(34,'power_sounds_enabled','1');
INSERT INTO "system" VALUES(35,'low_battery_sound','/system/media/audio/ui/LowBattery.ogg');
INSERT INTO "system" VALUES(36,'dock_sounds_enabled','0');
INSERT INTO "system" VALUES(37,'desk_dock_sound','/system/media/audio/ui/Dock.ogg');
INSERT INTO "system" VALUES(38,'desk_undock_sound','/system/media/audio/ui/Undock.ogg');
INSERT INTO "system" VALUES(39,'car_dock_sound','/system/media/audio/ui/Dock.ogg');
INSERT INTO "system" VALUES(40,'car_undock_sound','/system/media/audio/ui/Undock.ogg');
INSERT INTO "system" VALUES(41,'lockscreen_sounds_enabled','0');
INSERT INTO "system" VALUES(42,'lock_sound','/system/media/audio/ui/Lock.ogg');
INSERT INTO "system" VALUES(43,'unlock_sound','/system/media/audio/ui/Unlock.ogg');
INSERT INTO "system" VALUES(44,'vibrate_in_silent','1');
INSERT INTO "system" VALUES(47,'alarm_alert','content://media/internal/audio/media/5');
INSERT INTO "system" VALUES(48,'notification_sound','content://media/internal/audio/media/28');
INSERT INTO "system" VALUES(49,'ringtone','content://media/internal/audio/media/55');
INSERT INTO "system" VALUES(57,'volume_system','0');
INSERT INTO "system" VALUES(58,'volume_system_last_audible','7');
INSERT INTO "system" VALUES(59,'volume_ring','0');
INSERT INTO "system" VALUES(60,'volume_ring_last_audible','1');
INSERT INTO "system" VALUES(61,'mode_ringer','1');
INSERT INTO "system" VALUES(62,'volume_music','10');
INSERT INTO "system" VALUES(63,'volume_music_last_audible','10');
INSERT INTO "system" VALUES(75,'next_alarm_formatted','');
DELETE FROM sqlite_sequence;
INSERT INTO "sqlite_sequence" VALUES('system',75);
INSERT INTO "sqlite_sequence" VALUES('secure',25);
INSERT INTO "sqlite_sequence" VALUES('systemex',1);
INSERT INTO "secure" VALUES(1,'bluetooth_on','0');
INSERT INTO "secure" VALUES(2,'data_roaming','0');
INSERT INTO "secure" VALUES(3,'default_input_method','');
INSERT INTO "secure" VALUES(4,'enabled_input_methods','com.huawei.inputmethod.hwpal/');
INSERT INTO "secure" VALUES(5,'install_non_market_apps','0');
INSERT INTO "secure" VALUES(6,'location_providers_allowed','gps');
INSERT INTO "secure" VALUES(7,'assisted_gps_enabled','1');
INSERT INTO "secure" VALUES(8,'network_preference','1');
INSERT INTO "secure" VALUES(9,'usb_mass_storage_enabled','1');
INSERT INTO "secure" VALUES(10,'wifi_on','0');
INSERT INTO "secure" VALUES(11,'wifi_networks_available_notification_on','1');
INSERT INTO "secure" VALUES(12,'preferred_network_mode','0');
INSERT INTO "secure" VALUES(13,'cdma_cell_broadcast_sms','1');
INSERT INTO "secure" VALUES(14,'preferred_cdma_subscription','0');
INSERT INTO "secure" VALUES(15,'mock_location','0');
INSERT INTO "secure" VALUES(16,'backup_enabled','1');
INSERT INTO "secure" VALUES(17,'backup_transport','');
INSERT INTO "secure" VALUES(18,'mount_play_not_snd','1');
INSERT INTO "secure" VALUES(19,'mount_ums_autostart','0');
INSERT INTO "secure" VALUES(20,'mount_ums_prompt','1');
INSERT INTO "secure" VALUES(21,'mount_ums_notify_enabled','1');
INSERT INTO "secure" VALUES(22,'android_id','9774d56d682e549c');
INSERT INTO "secure" VALUES(23,'adb_enabled','0');
INSERT INTO "secure" VALUES(24,'voice_recognition_service','');
INSERT INTO "secure" VALUES(25,'throttle_reset_day','3');
CREATE TABLE bluetooth_devices (_id INTEGER PRIMARY KEY,name TEXT,addr TEXT,channel INTEGER,type INTEGER);
CREATE TABLE bookmarks (_id INTEGER PRIMARY KEY,title TEXT,folder TEXT,intent TEXT,shortcut INTEGER,ordering INTEGER);
INSERT INTO "bookmarks" VALUES(1,'Browser',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;;end',98,NULL);
INSERT INTO "bookmarks" VALUES(2,'Contacts',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;;end',99,NULL);
INSERT INTO "bookmarks" VALUES(3,'Email',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;;end',101,NULL);
INSERT INTO "bookmarks" VALUES(4,'Gmail',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;;end',103,NULL);
INSERT INTO "bookmarks" VALUES(5,'Calendar',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;;end',108,NULL);
INSERT INTO "bookmarks" VALUES(6,'Music',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;;end',112,NULL);
INSERT INTO "bookmarks" VALUES(7,'Messaging',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;;end',115,NULL);
INSERT INTO "systemex" VALUES(1,'white_languages','en_PK,en_AU,en_US,es_ES');
CREATE INDEX systemIndex1 ON system (name);
CREATE INDEX secureIndex1 ON secure (name);
CREATE INDEX bookmarksIndex1 ON bookmarks (folder);
CREATE INDEX bookmarksIndex2 ON bookmarks (shortcut);
CREATE INDEX systemexIndex1 ON systemex (name);

I wonder what INSERT INTO "secure" VALUES(23,'adb_enabled','0'); is?

I think I want to try this to turn USB Debugging on (based on

update secure set value=1 where name='adb_enabled';

So here goes...

/system/bin # ./sqlite3 /data/data/

sqlite> select * from secure;

Reboot phone.

No good.

I then installed CyanogenMod 7 for Huewei IDEOS 8150.

It supports adb so I should have done this ages ago.

I wrote this bash script to begin phone setup without a touchscreen.


    local -i _a=$1 _k=$2 _v=$3
    printf "$FUNCNAME: _a=%d  _k=%d  _v=%d\n" $_a $_k $_v
    adb shell sendevent "/dev/input/event2" $_a $_k $_v

    local -i _a=$1 _x=$2 _y=$3 _w=$4
    #printf "$FUNCNAME: _a=%d  _x=%d  _y=%d  _w=%d\n" $_a $_x $_y $_w
    # send touch event x y
    adb_sendevent 3 0x39 $_a  # start event?
    adb_sendevent 3 0x35 $_x
    adb_sendevent 3 0x36 $_y
    adb_sendevent 3 0x30 $_w  # finger width?
    adb_sendevent 3 0x31 0  # x moved?
    adb_sendevent 3 0x34 0
    adb_sendevent 3 0x32 0  # y moved?
    adb_sendevent 0 0x02 0  # end event?

    local -i _x=$1 _y=$2 _w=$3
    #adb_sendevent 0 0 0
    adb_touch1 0 $_x $_y   $_w
    adb_touch1 1 0   0x15b 0
    adb_sendevent 0 0 0

    local -i _x=$1 _y=$2
    adb_touch $_x $_y 0x20
    # android icon selected
    adb_touch $_x $_y 0

#1 -->  "KEYCODE_MENU" 
#3 -->  "KEYCODE_HOME" 
#4 -->  "KEYCODE_BACK" 
#5 -->  "KEYCODE_CALL" 
#7 -->  "KEYCODE_0" 
#8 -->  "KEYCODE_1" 
#9 -->  "KEYCODE_2" 
#10 -->  "KEYCODE_3" 
#11 -->  "KEYCODE_4" 
#12 -->  "KEYCODE_5" 
#13 -->  "KEYCODE_6" 
#14 -->  "KEYCODE_7" 
#15 -->  "KEYCODE_8" 
#16 -->  "KEYCODE_9" 
#17 -->  "KEYCODE_STAR" 
#18 -->  "KEYCODE_POUND" 
#19 -->  "KEYCODE_DPAD_UP" 
#26 -->  "KEYCODE_POWER" 
#27 -->  "KEYCODE_CAMERA" 
#28 -->  "KEYCODE_CLEAR" 
#29 -->  "KEYCODE_A" 
#30 -->  "KEYCODE_B" 
#31 -->  "KEYCODE_C" 
#32 -->  "KEYCODE_D" 
#33 -->  "KEYCODE_E" 
#34 -->  "KEYCODE_F" 
#35 -->  "KEYCODE_G" 
#36 -->  "KEYCODE_H" 
#37 -->  "KEYCODE_I" 
#38 -->  "KEYCODE_J" 
#39 -->  "KEYCODE_K" 
#40 -->  "KEYCODE_L" 
#41 -->  "KEYCODE_M" 
#42 -->  "KEYCODE_N" 
#43 -->  "KEYCODE_O" 
#44 -->  "KEYCODE_P" 
#45 -->  "KEYCODE_Q" 
#46 -->  "KEYCODE_R" 
#47 -->  "KEYCODE_S" 
#48 -->  "KEYCODE_T" 
#49 -->  "KEYCODE_U" 
#50 -->  "KEYCODE_V" 
#51 -->  "KEYCODE_W" 
#52 -->  "KEYCODE_X" 
#53 -->  "KEYCODE_Y" 
#54 -->  "KEYCODE_Z" 
#55 -->  "KEYCODE_COMMA" 
#56 -->  "KEYCODE_PERIOD" 
#57 -->  "KEYCODE_ALT_LEFT" 
#61 -->  "KEYCODE_TAB" 
#62 -->  "KEYCODE_SPACE" 
#63 -->  "KEYCODE_SYM" 
#66 -->  "KEYCODE_ENTER" 
#67 -->  "KEYCODE_DEL" 
#68 -->  "KEYCODE_GRAVE" 
#69 -->  "KEYCODE_MINUS" 
#70 -->  "KEYCODE_EQUALS" 
#76 -->  "KEYCODE_SLASH" 
#77 -->  "KEYCODE_AT" 
#78 -->  "KEYCODE_NUM" 
#80 -->  "KEYCODE_FOCUS" 
#81 -->  "KEYCODE_PLUS" 
#82 -->  "KEYCODE_MENU" 
#84 -->  "KEYCODE_SEARCH" 

adb_tap 0x70 0x80  # tap on android icon
adb shell input keyevent 20  # down to 'Create'
adb shell input keyevent 20  # down to 'Sign in'
adb shell input keyevent 23  # enter
adb shell input text ''
adb shell input keyevent 20  # down to 'password'
adb shell input text 'password or 2-factor code'  # 2-factor pw
adb shell input keyevent 23  # enter
adb shell input keyevent 20  # down to 'Sign in'
adb shell input keyevent 23  # enter
My phone is now setup and working.

Now to setup WiFi.

Friday, 31 May 2013

Install Lubuntu 13.04 on PowerBook G4 17" (REV D? 2005)

Get ISO from here

Boot ISO (Option-C) when power on or 'c' if yaboot is already installed.

At the boot: prompt type:
live video=radeonfb:1024x768-32@60


Saturday, 23 February 2013

Howto Telnet into Netgear DG834GVv1

This probably works for any Netgear DG834*

Your default router IP address is unless you have changed it.

Start Telnet Daemon

You may now telnet to your router's IP address.

eg. telnet

NB: This may enable telnet access from any Internet host.
In my case on a DG834GV v1, I could not connect to my router over Internet.

To run any installed program, use this general form.
It will launch program and redirect output to ppp_log.

General Form

View ppp_log

Read a File

eg. to read /etc/hosts

Ignore Ping error message and read ppp_log:

Stop Telnet Daemon

From telnet session


Find PID (first number) for utelnetd daemon


You should see a message on your console like "Connection closed by foreign host.

Via browser

Ensure you can no longer login into your router.

Monday, 28 January 2013

Spell checker and corrector in BASH

Why? Because it can be done.

I have used nothing but BASH.

Sample run:

I tried to make it very feature rich while keeping code to about 100 lines - this version is about 80.

Can you make it smaller?

* Auto-corrects if it can only find 1 suggested correction.
* Lists all words in dictionary that could be corrections and lets user choose or replace word.
* Suggestions only consider words with single letter deletions, additions or changes.
* Spelling errors are highlighted in yellow.
* Corrections are highlighted in green.

* Save result to a file (Currently just displays result on terminal).

I did go a little overboard with processing word case.


[[ -z "$1" ]] && echo "Usage: $0 " && exit 1
ERR=33; COR=32                                   # error and corrected colours
PS3="Select or manually enter a correction: "
L="a-zA-Z'"                                      # these letters are deemed part of words
shopt -s extglob
shopt -u nocasematch
declare -A WORD
while read W; do WORD[${W,,}]=${W,,}; done < /usr/share/dict/words

function checkSuggestion() {
    local p=$1 S=$1 C                            # uses CASE and SUGGEST from caller
    [ -z "${WORD[$p]}" ] && return 1             # matches word in dict!
    [ $CASE = PROP  ] && S=${p^}                 # change case to original word
    [ $CASE = CAP   ] && S=${p^^}   
    [ $CASE = CAPs  ] && { S=${p%%\'*};             S="${S^^}'${p#*\'}"; }   
    [ $CASE = LAT   ] && { S=${p##*\'};             S="${p%\'*}'${S^^}"; }   
    [ $CASE = OPROP ] && { S=${p%%\'*}; C=${p#*\'}; S="${S^^}'${C^}";    }   
    SUGGEST="${SUGGEST/ $S /} $S "               # add to suggestion list

function getSuggestions() {
    local W=$1 t l # p
    [[ $W =~ ^[A-Z][a-z]        ]] && CASE=PROP   # Prop
    [[ $W =~ ^[A-Z][A-Z]        ]] && CASE=CAP    # CAP
    [[ $W =~ ^[A-Z]\'[a-z]      ]] && CASE=PROP   # P'rop
    [[ $W =~  [A-Z]\'[a-z]$     ]] && CASE=CAPs   # CAP's
    [[ $W =~ ^[a-z]\'[A-Z]      ]] && CASE=LAT    # l'At
    [[ $W =~ ^[A-Z]\'[A-Z][A-Z] ]] && CASE=CAP    # C'AP
    [[ $W =~ ^[A-Z]\'[A-Z][a-z] ]] && CASE=OPROP  # O'Prop
    W=${W,,}                                     # lowercase word
    for (( t=0 ; t<=${#W} ; t++ )); do           # for each letter position of word, delete|change|insert a letter
        checkSuggestion ${W:0:t}${W:t+1}         # try deleting letter at position t
        for l in {a..z} "'"; do                  # try changing and inserting letters
            checkSuggestion ${W:0:t}$l${W:t+1}   # try changing letter
            checkSuggestion ${W:0:t}$l${W:t}     # try inserting letter

function correctWord() {                         # correct word and return in RET as well as pattern in PAT
    local W=$1 D1 D2 SUGGEST                     # uses L RESULT
        getSuggestions "$W"
        [[ ! "$RESULT" =~ ([^$L]|^)$W([^$L]|$) ]] && { printf "ERROR: Could not find [%s] in %s\n" "$W" "$LINE"; exit 1; }
        D1="${BASH_REMATCH[1]}"; D2="${BASH_REMATCH[2]}"  # get delimiters around word
        PAT="${D1:-#}$W${D2:-%}"                 # match pattern
        case $SUGGEST in
             '') echo -e "${RESULT/$PAT/$D1\e[${ERR}m$W\e[0m$D2}"   # display line with spelling mistake highlighted
                 read -p "Enter correction [$W]: " RET < /dev/fd/3  # no suggestions - let user correct
            +([$L ])\ +([$L ]))                                     # multiple suggestions
                 echo -e "${RESULT/$PAT/$D1\e[${ERR}m$W\e[0m$D2}"   # display line with spelling mistake highlighted
                 select RET in "(IGNORE)" $SUGGEST; do              # get correction
                     RET=${RET:-$REPLY}                             # user entered a word instead
                     [ "$REPLY" = "1" ] && RET=$W                   # no change
                 done < /dev/fd/3;;
              *) RET=${SUGGEST// /}                                 # get single suggestion
                 printf "%b\n" "\e[31mAuto:\e[0m ${RESULT/$PAT/$D1\e[9;${ERR}m$W\e[0;${COR}m $RET\e[0m$D2}"
        COL=$COR; [ "$RET" = "$W" ] && COL=$ERR   # if unchanged, highlight in error colour
        RESULT="${RESULT/$PAT/$D1\e[${COL}m${RET}\e[0m$D2}"       # correct word

function correctLine(){
    local LINE="$1" W                            # uses RESULT
    while read -d' ' W; do                       # for each word in line
        [[ -z "$W" || -n ${WORD[${W,,}]} ]] 2> /dev/null && continue  # null or word in dict so ignore it
        correctWord $W
        printf ">> %b\n\n" "$RESULT" 
    done <<< "$LINE"

while read LINE; do  # for each line
    correctLine " ${LINE//[^$L ]/ } "            # replace punctuation with spaces
    FINAL+="$RESULT\n"                           # append corrected line to result
done 3<&0 < $1                                   # redirect stdin to /dev/fd/3 for select and read

printf "\nCORRECTED TEXT\n\n%b\n" "$FINAL"

Tuesday, 22 January 2013

Replacing Ford NL Fairlane Power Steering Nut

Based on advice from fordmods, I purchased a BA 3F656B Nut from Ford. $17.

It looks like this one from ebay:

My original one looks very different - like this one:

I cut two grooves on opposite sides into my old nut using a ruby cutting blade and a Dremel.

I cut carefully using nut's internal rubber seal groove as a guide. Once I cut into this groove, I stopped cutting. I didn't cut deep enough to reach the other groove.

With a length of hardwood resting on concrete floor and cut to length, we used a cold chisel to crack nut in half. We were chiselling on hex part rather than on thread.

After a few hits it split.

My original nut had a small white nylon seal. New nut did not have anything like that so I installed a thin rubber o-ring - couldn't hurt I reasoned.

New nut just slides on to hose and clicks in place.

This is my new nut installed. The blue 'cape' is used to keep drips away from alternator.

Friday, 18 January 2013

How to Import Birthdays and Anniversaries into Google Calendar

This is a quick bash script I made that reads a file of events and creates an ical file suitable for importing into Google Calendar.

Date file supports these event formats:

day/month event description
day/month/year event description

Brief Instructions

1. Cut and paste program into a text file.

2. Save file as pc-ssv-to-ical.bash (or whatever you like)

3. In a terminal, chmod +x pc-ssv-to-ical.bash

4. Make an event file (eg. special dates) lile this:
1/1 New Year
26/1 Australia Day
4/4/1914 Someon'es Birthday
5/5/1915 Bill/Jill Wedding (1915)

5. Run ./pc-ssv-to-ical.bash special.dates > cal-import.ics 
6. Import cal-import.ics into a Google Calendar



#    This script takes events from a file and outputs in ical format 
#    suitable for importing into a Google Calendar.
#    Copyright (C) 2013  phil colbourn
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    GNU General Public License for more details.
#    A copy of the GNU General Public License can be obtained from
#    .


shopt -s extglob

# load special dates as day/month[/year] event description
# eg. 1/5/2004 A Person of Interest
# eg. 24/5 Not Sure When Born

# use this to convert SSV to CVS
# cat special-dates.ssv | sed 's/ /,/' > special-dates.csv



while read DATE EVENT; do
    [[ -z $DATE ]] && continue               # ignore null dates
    # D/M[/Y] format
    D="0${DATE%%/*}"                         # get day part
    D="${D: -2}"   
    M="${DATE#*/}"                           # get month part
    M="${M: -2}"
    # M/D[/Y] format
    #M="0${DATE%%/*}"                         # get month part
    #M="${M: -2}"   
    #D="${DATE#*/}"                           # get day part
    #D="${D: -2}"
    Y="${DATE/[0-9]?([0-9])[\/][0-9]?([0-9])/}"  # get year part
    Y=${Y//[\/]/}                            # remove left over /
    [[ -z $Y ]] && Y=$( date +%Y )           # use this year if none given

cat <

done < $SSV

printf "END:VCALENDAR\n"

unset IFS


1. Code could be simplified if a more strict date format was used. eg. DD/MM[/YYYY]
2. Code will need to be changed for M/D[/Y] dates.
3. Space separated (SSV) and CSV formats both work. Quoted and double-quoted events also seem to work.