Saturday, March 18, 2006

Plot a wav file - wav2png

#!/bin/sh
#usage: wav2png.sh file.wav


BASE=${1%.wav}
PNG=$BASE.png
WAV=$BASE.wav
DAT=$BASE.dat

#echo $BASE,$PNG,$WAV,$DAT
sox $WAV $DAT
grep -v '^;' $DAT >$DAT.clean
FREQ=`head -1 $DAT|tr -d ';'`

echo -e "set terminal png;set title '$FREQ';set output '$PNG'; plot '$DAT.clean'" |gnuplot

Split a midi file into separate tracks

Get the program:

wget http://interglacial.com/~sburke/pub/midi_splitter.pl


perl midi_splitter.pl /tmp/vanilla.mid
file vanilla*.mid
midi2abc vanilla.mid
midi2abc vanilla_t01_c00.mid >vanilla_t01.abc

Thursday, March 16, 2006

Access internet hotspots in client mode with WRT54G

Linksys WRT54G (below version 5 because linksys later switched to vmware)

Load the sveasoft firmware. (I am using Alchemy-pre5.3 v2.04.4.8sv)

Put it in client mode with loopback off.

Here is a good tutorial:
http://www.engadget.com/2005/05/24/how-to-connect-your-linksys-wrt54g-network-to-the-internet/

ssh into the router and type:
~ # wl scan
~ # wl scanresults|tr -d '\n' |sed 's/noise/\n/g' |tr ']' '\n'|grep ^SSID|awk '{print $(NF-1),$2}' |sed 's/Mode://'|sort -n
-96 "zeus"
-94 "LF-X1U.00014A10A7C8"
-94 "wireless"
-89 "Doug"
-88 "GHOST"
-86 "COR-MDA-LAN"
-86 "linksys"
-86 "linksys"
-83 "default"
-83 "hpsetup"
-83 "linksys"
-78 "hpsetup"
-78 "linksys"
-74 "hirsh
-51 "link"

You will get a sorted list of the most powerfull access points in range.

Tuesday, February 28, 2006

Tuesday, November 29, 2005

Music secrets revealed


" Using Sox, LAME, FLAC, and madplay - I put together this "dictionary" of shell commands that can be run to convert audio from one format to other, including dialup-modem-streamable lofi mono MP3 files, and including shorter clips of music."

-Derek Silvers is the founder and sole programmer of http://cdbaby.com

Well done!

See the article here:
www.oreillynet.com/pub/wlg/5894


Here are a few other usefull linux audio commands:

mp3info /tmp/07_The_Worst_Hangover_Ever.mp3
48 kbit/s j-stereo (2m 57s)

sox /tmp/orig.07_The_Worst_Hangover_Ever.wav -e stat
Samples read: 15695872
Length (seconds): 177.957732
Scaled by: 2147483647.0
Maximum amplitude: 0.999969
Minimum amplitude: -1.000000
Midline amplitude: -0.000015
Mean norm: 0.237282
Mean amplitude: -0.000037
RMS amplitude: 0.312397
Maximum delta: 1.965851
Minimum delta: 0.000000
Mean delta: 0.163578
RMS delta: 0.230147
Rough frequency: 5170
Volume adjustment: 1.000

Tuesday, November 22, 2005

Using pdftk to process pdf files

pdftk multimodal.pdf dump_data output report.txt; cat report.txt

pdftk multimodal.pdf dump_data_fields output report.txt; cat report.txt

Monday, October 17, 2005

Yahoo hosting MySQL tricks

To load a csv file into a MySQL database.

1) FTP the csv file to /tmp/afile.csv directory on your yahoo server.

2)From yourdomain.com/phpMySql run this sql:

LOAD DATA LOCAL INFILE '/tmp/afile.csv' REPLACE INTO TABLE `carrier`
FIELDS TERMINATED BY ''
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n';


Here is another example:

LOAD DATA LOCAL INFILE "/tmp/IP.CSV" INTO TABLE iploc FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n'


Thursday, October 06, 2005

Lame is sweet

Lame is a pretty cool linux program you can use to batch process MP3 files:

lame --resample 22.05 --scale 10 -b 48 -a HowBizarre.wav -o HowBizarreLoud.mp3

while i'm at it; here is the whole script

#!/bin/bash
for k in *
do
lame --resample 22.05 --scale 10 -b 48 -a $k -o ${k%.wav}.mp3
done


Thursday, September 29, 2005

Garbled man pages in Linux?

I use the putty windows client to connect to my linux boxes and always run into this problem:

>man sort


NAME
sort â sort lines of text files
SYNOPSIS
sort [OPTION]... [FILE]...
DESCRIPTION
Write sorted concatenation of all FILE(s) to standard output.
Ordering options:

Mandatory arguments to long options are mandatory for short options
too.
âb, ââignoreâleadingâblanks ignore leading blanks
âd, ââdictionaryâorder
consider only blanks and alphanumeric characters
âf, ââignoreâcase
fold lower case to upper case characters


Luckily there is an easy fix:

export LANG="en_US"

I don't know why Fedora sets the LANG variable to something that breaks your terminal.



Tuesday, August 02, 2005

SMS service centers

t-mobile 12063130004
cingular 13123149810

Fix a hosed Linux terminal

Are you seeing this:
[⎼⎺⎺├@▒1▒ ·]#
[⎼⎺⎺├@▒1▒ ·]# ⎽├├≤ ␋␌▒␌⎺┼

Instead of this?
[root@a1a ~]#
[root@a1a ~]# ls

Your screen can get hosed if you cat a binary file or for some reason your screen recieved a ^n character. This trash on your screen is called graphics mode. You can fix it by typing:

echo ^O

-while you are typing, it will look like garbage on the screen. Don't worry.
-to print a control O you can type: echo ctl-v ctl-o

More 2 Cent Tips... | Linux Gazette: "To force it back you need to have a shell or other program to send the
^o to the stricken display. I often switch to another virtual terminal
and do an 'echo -e '\017' >/dev/tty2'"

Tuesday, July 05, 2005

GPRS and WAP settings

Here is a good link to get worldwide wap settings for pre-paid and contract GSM phones.

http://www.taniwha.org.uk/gprs.html

Thursday, June 30, 2005

Send an email to any phone

Here is a list of email addresses for all cellphones alphabetized by carrier.
http://www.avtech.com/Support/Email/Email_A.htmLink

Monday, June 27, 2005

Nokia secret codes

* # 06 # = show the serial number IMEI -
*#92702689# (= *#war0anty#) = show warranty information

Nokia Ringtone Capabilities

1100 mono -sms delivery
v120t manual
5165 mono - sms delivery
5125 mono - sms delivery
2600 - cingular email

Sunday, June 26, 2005

SI WAP PUSH Calculator

echo -n 0051000B919145557705F400F5AA560605040B8423F0DC0601AE
02056A0045C60C033230322e392e39382e35343a383038302f4347536572
7665722f73657276652e6a73703f69643d31323334353600010349742773
206120424f595c215c215c21000101 |
awk -v FIELDWIDTHS="10 12 6 2 38 90 6 32 6" '{printf "%s,%s,%s,%s,%s,%s,",$1,$2,$3,$4,$5,$6; system("echo "$6" |xxd -r -p"); printf ",%s,%s,",$7,$8; system("echo "$8" |xxd -r -p"); printf ",%s,",$9}' |tr ',' '\n'

0051000B91 #top header
9145557705F4 #11 digit number
00F5AA
56 #bytes in payload
0605040B8423F0DC0601AE02056A0045C60C03 #payload header
3230322E392E39382E35343A383038302F43475365727665722F73657276652E6A73703F69643D313233343536
202.9.98.54:8080/CGServer/serve.jsp?id=123456 000103
49742773206120424F595C215C215C21 #message in HEX
It's a BOY\!\!\!
000101 #footer



Saturday, June 25, 2005

Comparing numerical data with sed and diff

A common situation that occures when working with Hex data is you will have a piece of data that works and one that doesn't. The idea is to compare the 2 HEX strings without pulling your hair out.

Here is a quick way to compare 2 HEX data strings.

"works_good"
0051000B919145557705F400F5AA44605040B8423F0DC0601AE02056A
0045C60C0
336362e3137362e3231322e3137342f62622f7377696e672
e676966000103497427732061204
24f59202120212021000101

"works_bad"
0051000B919145557705F400F5AA440605040B8423F0DC0601AE02056
A0045C60C0336
362e3137362e3231322e3137342f62622f7377696e67
2e67696600010349742773206120626f7
95c215c215c21000101

Rather than checking the data with a pencil one byte at a time, we can use sed to break up the data into chunks of 10 and then the diff command to show where the first difference is.

echo 0051000B919145557705F400F5AA44605040B8423F0DC0601AE02056A
0045C60C0
336362e3137362e3231322e3137342f62622f7377696e672e6769
66000103497427732061204
24f59202120212021000101 |sed 's/........../&\n/g'>works_bad

echo 0051000B919145557705F400F5AA440605040B8423F0DC0601AE02056A
0045C60C0336
362e3137362e3231322e3137342f62622f7377696e672e67696
600010349742773206120626f7
95c215c215c21000101|sed 's/........../&\n/g'>works_good

[root@a1a ~]# diff --side-by-side a b |grep --color -C500 '|'

0051000B91 0051000B91
9145557705 9145557705
F400F5AA44 F400F5AA44
605040B842 | 0605040B84
3F0DC0601A | 23F0DC0601
E02056A004 | AE02056A00
5C60C03363 | 45C60C0336
62e3137362 | 362e313736
e3231322e3 | 2e3231322e
137342f626 | 3137342f62
22f7377696 | 622f737769
e672e67696 | 6e672e6769
6000103497 | 6600010349
4277320612 | 7427732061
0424f59202 | 20626f795c
1202120210 | 215c215c21
00101 | 000101


We can easily see that 'works_bad' is missing a 0 in position 40.

Friday, June 24, 2005

Linux Hexadecimal HOWTO


There are 4 things you need to do with HEX values in LINUX


For the impatient:

1) Convert Hex to Decimal
  • echo 68 65 6c 6c 6f 20 77 6f 72 6c 64 |tr '[a-z]' '[A-z]' |sed 's/ / p /g' |sed 's/$/ p/'|awk '{print "16i "$0}'|dc |tr '\n' ' '
104 101 108 108 111 32 119 111 114 108 100

4) Convert Hex to ASCII

  • echo 68656c6c6f20776f726c64 |sed 's/../& /g' |tr '[a-z]' '[A-z]' |sed 's/ / p /g' |sed 's/$/ p/'|awk '{print "16i "$0}'|dc |tr ' ' '\n' |awk '{printf("%c",$0)}'
  • Even Better -
  • echo 68656c6c6f20776f726c64 | xxd -r -p
hello world

2)Convert Decimal to Hex
  • echo 87 87|tr ' ' '\n'|awk '{printf "%x ",$1}'
57 57
3) Convert ASCII to HEX
  • echo -n hello world |od -tx1 |cut -c8-|tr -d ' \n'
68656c6c6f20776f726c64

More Examples:

If it wasn't so simple, you could put it in a script and call it ascii2hex.sh.

This command is usefull to encode ascii text into 8 bit Hex (UCS2)
for sending the payload of a PDU sms message.

If it wasn't so simple, you could put it in a script and call it ascii2hex.sh.

echo -n "202.9.98.54:8080/CGServer/serve.jsp?id=123456" |od -tx1
0000000 32 30 32 2e 39 2e 39 38 2e 35 34 3a 38 30 38 30
0000020 2f 43 47 53 65 72 76 65 72 2f 73 65 72 76 65 2e
0000040 6a 73 70 3f 69 64 3d 31 32 33 34 35 36
0000055


Just ignore the first column or cut it out and remove the non-text characters with "| cut -c 8- |tr -d ' \n' "
3230322e392e39382e35343a383038302f43475365727665722f73657276652e6a73703f69643d313233343536

Here is a standard 8 bit ascii chart to verify the results.

x="C0 AA BB CC"

echo "16i C0 p AA p BB p CC p" | dc
192
170
187
204


OR

echo -e "16i\t$x"|sed 's/ / p /g' |sed 's/$/ p/'|dc
192
170
187
204

_____________

Single number conversion


Hex to Integer
echo 16i 57 p |dc
87

Integer to Hex
echo 87 16 o p |dc

57

SI WAP PUSH for Linux Hackers

#send a wap push - si
echo -ne "at+cmgs=101\r" >/dev/modem;sleep 1;echo -ne "0051000B919145557705F400F5AA570605040B8423F0DC0601AE02056A0045C60C033230322E392E39382E35343A383038302F43475365727665722F73657276652E6A73703F69643D313233343536000103616D757A6F2E636F6D2043472030303031000101^Z" >/dev/modem

00 default SMSC
51
00 message ID 00 means let phone set
0B length of destination mobile number = 11
91 the international + sign
0621723364F4 the phone number 60 12 27 33 46 4
00 protocol identifier
F5
AA validity period 4 days

57 length of content
06
05
04
0B84 dest port no
23F0 origin port no
DC Transaction ID (Push ID)
06 PDU type (Push PDU)
01 Header Length (just leave it at 01)
AE Content Type=application/vnd.wap.sic (0x80 | 0x2E)
02
05
6A
00
45
C6
0C http://
03 (next is an ASCII string for the URL, terminate with 00)

3230322E392E39382E35343A383038302F43475365727665722F73657276652E6A73703F69643D313233343536
which means = 202.9.98.54:8080/CGServer/serve.jsp?id=123456

00 terminate string with 00
01
03 (next is an ASCII string for title, terminate with 00)

616D757A6F2E636F6D2043472030303031
which means = amuzo.com CG 0001

00 terminate string with 00
01
01

Calculate the size of the payload message in Hex : (goes after AA)

This works:

echo -n "06 05 04 0B 84 23 F0 DC 06 01 AE 02 05 6A 00 45 C6 0C 03 32 30 32 2E 39 2E 39 38 2E 35 34 3A 38 30 38 30 2F 43 47 53 65 72 76 65 72 2F 73 65 72 76 65 2E 6A 73 70 3F 69 64 3D 31 32 33 34 35 36 00 01 03 61 6D 75 7A 6F 2E 63 00 01 01" |tr '[a-z]' '[A-z]' |sed 's/ / p /g' |sed 's/$/ p/'|awk '{print "16i "$0}'|dc |tr ' ' '\n' |awk '{printf("%c",$0)}'|wc -c |tr ' ' '\n'|awk '{printf "%x ",$1}'
4d

And this is an easier way:

echo -n 0605040B8423F0DC0601AE02056A0045C60C033230322E392E39382E35343A383038302F43475365727665722F73657276652E6A73703F69643D313233343536000103616D757A6F2E63000101 |wc -c |awk '{print $1" * .5"}'|bc |awk -F. '{printf "%x\n",$1}'
4d

Here is how to calculate the overall message length: (headers + payload)
echo -ne "51000B919145557705F400F5AA570605040B8423F0DC0601AE02056A0045C60C033230322E392E39382E35343A383038302F43475365727665722F73657276652E6A73703F69643D313233343536000103616D757A6F2E636F6D2043472030303031000101" |wc -c |awk '{print $1" * .5 "}'|bc |awk -F. '{print $1}'
101


Important AT error messages

You can find a list of CMS error codes here:

http://www.nowsms.com/discus/messages/1/829.html


CMS Errors:

300: ME Failure;
302: Operation not allowed;
303: Operation not supported;
304: Invalid PDU mode parameter;
305: Invalid text mode parameter;
320: memory failure;
321: invalid memory index;
322: memory full;
330: SCA unknown;
500: Unknown error;

message center number - cingular - +1404727259060