Friday, September 10, 2010

God is Able

"What I do know is that I am clinging to God's power to help me through these days of grief and sorrow. This power is my hope for the future. I am presently weak, but I know that God is strong and is able to carry me through. How do I know? The Bible tells me so. I am supported by God's comforting presence that I experience in loving acts of kindness from God's people."


Janet Huff (Illinois, USA)


Taken from the 9/10/2010 Daily Devotional of the Upper Room.

Music I like to listen

Wednesday, September 8, 2010

Using MySQL temporary table

1. Create temporary table with the settlements table structure:

CREATE TEMPORARY TABLE sett LIKE settlements;

2. Insert into the temporary table the data from the settlements for a certain date:

INSERT INTO sett (date,symbol,contract,price)
SELECT date,symbol,contract,price
FROM pltracker.settlements
WHERE date = '2010-09-03';

2a. You can do the previous two steps in only one:

CREATE TEMPORARY TABLE sett
SELECT date,symbol,contract,price
FROM settlements
WHERE date = '2010-09-03';

3. Update the date of the data at the temporary table for the specific date of the settlements:

UPDATE sett
SET date = '2010-09-06'
WHERE date = '2010-09-03';

3a. Since you are updating all the data in the table you can use this SQL statement instead:

UPDATE sett
SET date = '2010-09-06';

4. Insert data back into the settlements table:

INSERT INTO settlements (date,symbol,contract,price)
SELECT *
FROM sett;

5. Check that the new data is in place at the settlements table:

SELECT * FROM settlements
WHERE date = '2010-09-06';

6. The temporary table will be automatically drop when you close the session or you can drop it as any other table:

DROP TABLE sett;

Thursday, September 2, 2010

Listing Multicast group memberships

In Windows XP:

C:\>netsh interface ip show joins


Interface Addr   Multicast Group
---------------  ---------------
172.17.17.223    224.0.0.1
172.17.17.223    239.255.255.250

In Solaris and other UNIXes:


$ netstat -gn
IPv6/IPv4 Group Memberships
Interface       RefCnt Group
--------------- ------ ---------------------
lo              1      224.0.0.1
eth0            1      224.0.0.1
lo              1      ff02::1
eth0            1      ff02::1:ff09:ac30
eth0            1      ff02::1

Monday, August 30, 2010

The Three UNIX File Times

access time - cat myfile # read
ls -Elu

modification time - echo "Hello, World!" > myfile # writing
ls -El

change time - chmod a+w myfile # inode's update
ls -Elc

Friday, August 27, 2010

Counting lines in a file (61960627 lines)

sed -n '$=' file.txt

real    1m9.237s
user    1m8.602s
sys     0m0.631s

perl -ne 'END { print $NR }' file.txt

real    0m13.876s
user    0m13.245s
sys     0m0.630s

awk 'END { print NR }' file.txt

real    0m8.866s
user    0m8.257s
sys     0m0.608s

wc -l file.txt

real    0m2.550s
user    0m1.677s
sys     0m0.873s

wc file.txt

real    3m4.875s
user    3m3.970s
sys     0m0.895s

Friday, August 6, 2010

Padding a number to the right with zeros in Perl

#!/usr/bin/perl

use strict;
use warnings;

while (<>) {

chomp;

if (/^[a-zA-Z]/) {
print "$_\n";
next;
}

my ($Date, $Time, $Price, $Volume, $Index) =
split /,/;

$Time = sprintf("%0*d", 6, $Time);

print "$Date,$Time,$Price,$Volume,$Index\n";

}

__END_