Tuesday, December 16, 2008

to extract any rpm:

to extract any rpm:

rpm2cpio some.rpm | cpio -id

Sunday, December 14, 2008

replace notepad with notepad2

notepad2

replacenotepad2.bat
copy notepad2.exe C:\WINDOWS\notepad.exe
copy notepad2.exe C:\WINDOWS\system32\notepad.exe
copy notepad2.exe C:\WINDOWS\ServicePackFiles\i386\notepad.exe
copy notepad2.exe C:\WINDOWS\system32\dllcache\notepad.exe

Windows XP - how to turn off compressed folders

regsvr32 /u zipfldr.dll

Friday, December 05, 2008

mount a samba fileshare in linux

how to mount a linux samba fileshare back into another linux box

edit /etc/fstab, add the line:
//host/shared/ /home/shar/ cifs username=u,password=p,_netdev,uid=root,gid=users 0 0

replace host with [host]
/shared/ with the folder shared
/home/shar/ with where you want to mount it
u with the samba username
p with the samba password

(when complete, 'mount -a' should apply the fstab changes).

Thursday, November 27, 2008

MySQL: Load CSV into db

DROP TABLE IF EXISTS `digitalsignage`.`tmp_directory`;
CREATE TABLE `digitalsignage`.`tmp_directory` (
`f1` varchar(255) NULL,
`f2` varchar(255) NULL,
`f3` varchar(255) NULL,
`f4` varchar(255) NULL,
`f5` varchar(255) NULL,
`f6` varchar(255) NULL,
`f7` varchar(255) NULL,
`f8` varchar(255) NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

LOAD DATA INFILE 'Book2.csv'
INTO TABLE `tmp_table`
FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;

Thursday, November 20, 2008

pgsql rename table

ALTER TABLE products RENAME TO items;

Wednesday, November 19, 2008

linux disk usage

du -B MB --max-depth=1 |sort -nr

Wednesday, November 12, 2008

linux sort

sort a tab delimited file: on column 2 (where you have column 1,2,3...)

sort -t$'\t' +1 -2 export_1612.txt>sorted.txt

Friday, November 07, 2008

BASH - Time Your Bash Script

#!/bin/bash
time_start=`date +%s`
sleep 63
time_end=`date +%s`
time_elapsed=$((time_end - time_start))
echo $(( time_elapsed / 60 ))m $(( time_elapsed % 60 ))s

Tuesday, November 04, 2008

VMWare on supporting 64 bit guest OSes

I wanted to play with a 64 bit OS once, so I installed VMWare to experiment with it. My box had a 64 bit AMD CPU, and was running a 32 bit linux OS on it. I didn't think I would be able to install a 64 bit VMWare guest OS on it, but it worked fine.

Later I tried this all again but on an intel 32 bit box, and it didn't work.

I just found a link that describes under exactly what conditions 64 bit guest OSes will and won't work:[kb.vmware.com].

Tuesday, October 28, 2008

PgSQL: random notes


postgres, allow localhost with no password
/var/lib/pgsql/pg_hba.conf
on line: with host all all 127.0.0.1/32 md5
change md5 to trust

postgres, set new password
[user@server ~]psql -U postgres -h localhost -d postgres
ALTER USER postgres WITH PASSWORD 'newpass';

#where postgres is the dbname
pgsql -U postgres -d dbname

# (at pgsql prompt) this will give the schema of the table
dbname=# \d tablename

# (at pgsql prompt) view autoincrement expression for field
dbname=# \d tablename

# (at pgsql prompt) how to view next autoincrement number
dbname=# select nextval('tablename_fieldname_seq');

# (at pgsql prompt) how to set autoincrement number
dbname=# select setval('tablename_fieldname_seq', 50);






source(s): http://www.source.com

Thursday, October 16, 2008

Linux - New set of Notes

I just installed Fedora, and I'll be making some notes about setting up and configuring Fedora 8 in this post.

this is a system startup script kind of like the old autoexec.bat
/etc/rc.local

this is a bash startup script for that user, also an .sh
/home/username/.bash_profile

defaults for new users
/etc/skel/.bash_profile

CTRL-ALT-D
show desktop

FC8:
System > Preferences > Personal > Keyboard Shortcuts
CTRL-ALT <arrow> (l,r,u,d) to navigate between desktops





Monday, September 22, 2008

Skype: Belkin Skype Phone

One of the nice things about skype is that you can download it for Mac, Linux or Windows, so you aren't particularly tied down.

Skype is a DIY voip service. They offer a skype out unlimited subscription for canada and the usa (unlimited outgoing calling from your computer to landlines and cellphones) for $30. If you choose you can also get a phone number in whatever USA area code you want for another $30. I am sad that there still are no numbers available in canada. Because skype online numbers are available in over 20 countries at the time of this writing, i wouldn't be surprised if canada has extra red tape, which is preventing this.

So for the cost of $5 computer speakers, $5 computer microphone, an internet connection and $60/year ($5/month) you can scrap your $30/month landline. Don't forget to read the fine print, skype wants you to know that you can't use it for 911 calling, because the 911 operators have no idea where you are calling from. You could be online in europe and still take skype calls at your 801 usa area code through your internet connection. So... it is important to keep an old cell phone around. Even deactivated/non-sim card cell phones are required by law to be able to call 911.

My wife doesn't like using the computer for calling much, plus we don't want to leave it on 24/7 to take calls so we were thinking of getting the belkin skype desktop phone. This phone is a no computer required phone. It seems a little pricey considering it is just a phone... but understood what the skype phone really is, its pretty much an $80 computer with built-in microphone and speakers.

There are a lot of items for sale which replace your microphone and speakers... some usb phones, some cordless phones (comp req'd), other cordless phones (comp not req'd), and even wifi phones. Wifi is great... if you get a wifi hotspot anywhere you can make or take calls. I have heard the battery life on them isn't great yet... because it just like a minilaptop- but you can't turn the wifi network card off for power saving mode!

Thursday, September 11, 2008

C++ : How to Launch a Background in Windows Program

In linux it is easy to launch a background process at the command line with ampersand.

./app_to_launch &

In windows there is no easy command line suffix which will launch your program in the background. However it is relatively easy to code one up. If you install Visual C++ Express 2005, and the Microsoft Platform SDK (see configuration below) just compile this application as BKLAUNCH.exe and you will soon be able launch apps in the background from batch files.

I created an empty win32 project named BKLAUNCH, no precompiled header, and compiled the following code.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include <windows.h>
#include <shellapi.h>
#include <tchar.h>

int _tmain(int argc, _TCHAR* argv[])
{
if (argc!=2)
{
printf("Usage:\n");
printf(" BKLAUNCH.EXE [apptolaunch]\n");
printf(" BKLAUNCH.EXE notepad.exe\n");
exit(0);
}
ShellExecute(NULL, TEXT("open"), argv[1], NULL, NULL, SW_SHOW);
return 0;
}


Once BKLAUNCH has successfully compiled, place it in a folder that is in the PATH. Now, go to Start > Run > cmd.exe [OK], and enter the following:
BKLAUNCH notepad.exe

You will notice notepad.exe is launched in the background, perfect for batch files.

Troubleshooting
If you are like me and use default settings, look under
Project > Project Properties > Linker > Input > Additional Dependencies
it will will have only kernel32.lib. When you compile there will be linker errors.

Because of the #include <windows.h> and #include <shellapi.h>
you need to add the following to your Additional Dependencies
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib in order to resolve the linker errors.

Microsoft Platform SDK Config
In order to use the MS Platform SDK in Visual C++ Express 2005, you have make the platform SDK visible to the compiler.

Go to
Tools > Options > Projects and Solutions > VC++ Directories > Platform=Win32 > Show Directories for=include files
Add to the list,
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include
(or wherever you installed the MS Platform SDK\Include)

Now, go to
Tools > Options > Projects and Solutions > VC++ Directories > Platform=Win32 > Show Directories for=library files
Add to the list,
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib
(or wherever you installed the MS Platform SDK\Lib)

Tuesday, September 09, 2008

BASH: bad interpreter: No such file or directory

-bash: ./execute.sh: /usr/bash^M: bad interpreter: No such file or directory


Dos text files use \r\n (0xD 0xA) as their end of line characters. Unix text files use \n (0xA) as their end of line character. What happened here is I had a file in dos text format, and tried to execute it in bash. the ^M you see above is saying "It wasn't expecting the \r character".

Solution:

use dos2unix
[user@linux1 ~] dos2unix execute.sh
dos2unix: converting files execute.sh to UNIX format...

Monday, September 08, 2008

C++: Simple Makefile Example

I have always been looking for a nice makefile template, that will allow me to have separate include, src, and obj directories. Today I stumbled on addprefix a directive that allows me to add only the filename of each src file I add to my project.

Assuming you have the files
./Makefile
./include/file1.h
./include/file2.h
./include/file3.h
./src/file1.cpp
./src/file2.cpp
./src/file3.cpp
and all obj files go in ./obj/
and your target executable is ./execfile


Makefile
CC        =g++
CFLAGS =-c -Wall
LDFLAGS =
INCLUDE =-I./include
OBJDIR =obj/
OBJLIST = file1.o file2.o file3.o
OBJECTS = $(addprefix $(OBJDIR), $(OBJLIST) )

all:execfile

execfile: $(OBJECTS)
[TAB]$(CC) $(LDFLAGS) $(OBJECTS) -o $@

$(OBJECTS): obj/%.o: src/%.cpp
[TAB]$(CC) $(CFLAGS) $? -o $@ $(INCLUDE)

clean:
[TAB]rm -rf obj/*.o
obviously, replace [TAB] with the actual tab character(\t).

Thursday, June 19, 2008

PHP: Web Bug Script

Somebody wanted hits on their website... so they linked web bug[wikipedia] web bug tracker article to their web bug script[pineapple.vg].

The problem with their web bug script is it requires the php-gd2 extension, it results in 95 byte output, and uses php gd code allocating memory... deallocating memory when its not necessary. This script when scaled up 100,000x has too large a footprint. It can be optimized into 3 lines as follows (with a 43 byte output):

<?php
//saves ip address and timestamp
file_put_contents("ip_list.txt", date("Y-m-d H:i:s") . ": ". $_SERVER['REMOTE_ADDR'] . "\n", FILE_APPEND);

header("content-type: image/gif");

//43byte 1x1 transparent pixel gif
echo base64_decode("R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
?>

Thursday, January 31, 2008

PHP: Calculate PHP Page Load Time

//put this at the start of your php script.
$s_mt = explode(" ",microtime());

//put this at the end of your php script
$e_mt = explode(" ",microtime());
$s = (($e_mt[1] + $e_mt[0]) - ($s_mt[1] + $s_mt[0]));
echo "Page created in ".$s." seconds";

Monday, January 21, 2008

Javascript: Error, Internet Explorer cannot open the internet site

I have built a website that used a lot of javascript code to generate a floating overlay div, appends it to the body, and got this crazy Internet Explorer error in IE 6 AND IE 7.

Internet Explorer cannot open the internet site http://blah.blah.com/

Operation Aborted.


At which point I got redirected to a "The page cannot be displayed" IE error.

I trimmed everything out of the webpage which had nothing to do with the error and I was left with a tiny page which still produced the error:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<
title>pagetitle</title>
<
script language="JavaScript" type="text/JavaScript">
<!--
function creatediv()
{
try
{
document.body.appendChild( document.createElement("<div>") );//IE
}
catch (e)
{
document.body.appendChild( document.createElement("div") );
}
}
//-->
<
/script>
<
/head>
<
body>

<
div>
<
script language="JavaScript" type="text/JavaScript">
<!--
creatediv();
//-->
<
/script>
<
/div>

<
/body>
<
/html>


If you copy and paste the above, and then save it as html, and open the page in IE you will see the error. Then I googled around and played with my page, and realized that if I moved the creatediv() function outside the >div< (or any other html container), that I would no longer get this error. Basically, the problem is that IE 6 and 7 do not create the document.body part of the DOM until after the page has finished loading. In my javascript code I call document.body.appendChild and IE has a hissy fit. Something about calling the javascript from within a div or table makes also contributes to this error.

Workarounds and Solutions:
- moving my javascript function out of the div (see below)
- using <body onload='creatediv()' > instead of calling it within the page
- if using an event handler class like in http://www.dustindiaz.com/rock-solid-addevent/
use: addEvent(window,'load',creatediv);

Code that doesn't produce the error:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<
title>pagetitle</title>
<
script language="JavaScript" type="text/JavaScript">
<!--
function creatediv()
{
try
{
document.body.appendChild( document.createElement("<div>") );//IE
}
catch (e)
{
document.body.appendChild( document.createElement("div") );
}
}
//-->
<
/script>
<
/head>
<
body>

<
div>
<
/div>

<
script language="JavaScript" type="text/JavaScript">
<!--
creatediv();
//-->
<
/script>


<
/body>
<
/html>


source(s): http://tinyurl.com/hvfsw

Sunday, January 20, 2008

FLASH: Mp3 player swf plays chipmunk sounds

Most mp3s are encoded at 128 and 192 kbps, but I was working on a project that used speech recordings, and speech is usually encoded at a lower bitrate than 128. I found every time I played the recording in a flash based mp3 player it played it too fast, making it sound like alvin and the chipmunks.

I went through and made a whole bunch of mp3s at different bitrates using the lame 3.96 encoder to see which were supported and which bitrates were not.
fixed bitrates:
:( 16 kbps
:( 24 kbps
:( 32 kbps
:( 40 kbps
:) 48 kbps
:( 56 kbps
:( 64 kbps
:( 80 kbps
:) 96 kbps
:) 112 kbps
:) 128 kbps
:) 160 kbps
:) 192 kbps
:) 224 kbps
:) 320 kbps

variable bitrates (with lame; 0 is high quality, 9 is low):
:) V0-6
:( V7-9


So the basic synopsis is mp3s encoded as 48kbps work and anything greater or equal to 96kbps also works. Everything else is not supported (is support, but sounds like chipmunks).
[EDITED]
see
http://www.summitsolutions.co.uk/blog/how-to-correct-the-chipmunk-effect-in-the-podpress-flash-player
for another possible explanation of the chipmunk sounds.