Thursday, September 03, 2009

wxWidgets - No Image Handler Defined

wxWidgets

Error: No Image Handler Defined

the fix:
wxInitAllImageHandlers();

Friday, August 21, 2009

use array_map to select 1 column out of rowset of php rows

Given a series of rows of data (perhaps rows in a database, copied into memory), we want to extract only 1 field of data and put it into a comma delimited list. (or array to loop through).


$arr = array();
$arr[] = array('first'=>'jack','last'=>'smith');
$arr[] = array('first'=>'john','last'=>'williams');
$arr[] = array('first'=>'mark','last'=>'jesperson');
$arr[] = array('first'=>'vlad','last'=>'shuttleworth');

$f = array_map(create_function('$a', 'return $a["first"];') , $arr);
echo implode(",", $f);
//outputs:
//jack,john,mark,vlad

Friday, July 31, 2009

numbers from 001 to 999

the numbers from 001 to 999

echo "<?php for(\$i=1; \$i<=999; \$i++){ echo sprintf('%03d',\$i).chr(10);} ?>"|php


The \ has to go before the $ character because $i can refer to the command line environment variable $i, so we escape it with \$i in order to pass it straight through to the php parser.

Thursday, July 30, 2009

output formatting like command line sql

--usage1----------

$sql = '';
$sql.="SELECT fieldtype, count(1) as count ";
$sql.="FROM mytable ";
$sql.="GROUP BY fieldtype ";
$sql.="ORDER BY fieldtype ";
echo report_append("summary of data", $sql);

--output1---------
|fieldtype|count|
|0 |9 |
|1 |397 |
|2 |965 |
|3 |554 |
|4 |683 |
|5 |1352 |
|6 |1390 |
|7 |237 |
|8 |1372 |


--usage2----------
$q='';
$q.="SELECT
(case
when fieldtype=1 then 'Apple'
when fieldtype=2 then 'Banana'
when fieldtype=3 then 'Blackberry'
when fieldtype=4 then 'Cherry'
when fieldtype=5 then 'Grape'
when fieldtype=6 then 'Orange'
when fieldtype=7 then 'Peach'
when fieldtype=8 then 'Pear'
else '' end) as typename, fieldtype, count(1) as count
FROM mytable d GROUP BY fieldtype ORDER by fieldtyped;
";
report_append("summary of data", $q);

--output2---------
|typename  |fieldtype|count|
| |0 |9 |
|Apple |1 |397 |
|Banana |2 |965 |
|Blackberry|3 |554 |
|Cherry |4 |683 |
|Grape |5 |1352 |
|Orange |6 |1390 |
|Peach |7 |237 |
|Pear |8 |1372 |

--code------------

function select_all($sql)

{
$rows = array();
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
$rows[] = $row;
return $rows;
}
function report_append($title,$sql)
{

$rows = select_all($sql);

$headersize=array();
$header=array();
foreach($rows[0] as $colname=>$col)
$header[]=$colname;
foreach($rows[0] as $colname=>$col)
$headersize[] = strlen($colname);
foreach($rows as $row)
foreach($headersize as $colnum=>$col)
$headersize[$colnum] = max( $headersize[$colnum] , strlen($row[$header[$colnum]]) );

$h='';
foreach($header as $colnum=>$colname)
$h.="|".sprintf("%-".$headersize[$colnum]."s", $colname);
$h.= "|\n";
foreach($rows as $row)
{
foreach($headersize as $colnum=>$col)
$h.="|".sprintf("%-".$col."s", $row[$header[$colnum]]);
$h.= "|\n";
}

$return='';
$return.="---------------------------------------------------------\n";
$return.="$title\n";
$return.="---------------------------------------------------------\n";
$return.=$h;
return $return;
}

Monday, July 20, 2009

Crontab daily gui app launcher, and taskkill

10 17 * * 1-5 killall pidgin
8 10 * * 1-5 if ! ps -C pidgin > /dev/null; then export DISPLAY=:0 && pidgin; fi

Friday, July 10, 2009

common pitfalls when going from html to xhtml

common pitfalls when going from html to xhtml
-------------------------------------------------
<img /><br /><input /> #good, bad: <img><br><input>
<i><b>hi</b></i> #good, bad: <b><i>hi</b></i>
<a href=""></a> #good, bad: <a href=''></a>
<a href="a=b&amp;c=d"></a> #good, bad: <a href="a=b&c=d"></a>
&#160; #good, bad: &nbsp;

Friday, June 12, 2009

Monday, June 08, 2009

smbfs smbmount are deprecated, use cifs

mount -t cifs -o username=guest \\\\192.168.0.97\\share /home/share-buff/

Friday, June 05, 2009

postgres age function

select dob,extract(year from AGE(dob                  )) from dob_table limit 1;
select dob,extract(year from AGE(now(), dob )) from dob_table limit 1;
select dob,extract(year from AGE(current_timestamp,dob)) from dob_table limit 1;
select dob,extract(year from AGE('2009-09-10', dob )) from dob_table limit 1;
select dob,to_char(AGE(dob),'YYYY')::integer from dob_table limit 1;
select dob,substr(AGE(dob)::text,1,3) from dob_table limit 1;

Tuesday, June 02, 2009

Cross Browser Compatible Javascript DOMelement function

In the past... you had to do
//------------
var a = document.createElement('div');
a.setAttribute('class','myclass');
a.setAttribute('id','id_mydiv');
document.getElementById('otherdiv').appendChild(a);

//------------
to create a dom element... and it only worked in firefox. to get one that works in internet explorer you have to do:
//------------
var a;
try {
  a = document.createElement('<div class=myclass id=id_mydiv>');
}
catch(e) {
  a = document.createElement('div');
  a.setAttribute('class','myclass');
  a.setAttribute('id','id_mydiv');
}
document.getElementById('otherdiv').appendChild(a);

//------------
include the function below, and it will work in both browsers:
//------------
var a = DOMelement('div','class':'myclass','id':'id_mydiv');
document.getElementById('otherdiv').appendChild(a);

//------------

function DOMelement(elementname,attributes)
{
  var htmlspecial = function(tmp_str){
    var histogram = {"&":"&amp;","'":"&#39;", "\"":"&#34;","<":"&lt;",">":"&gt;"};
    for (symbol in histogram)
      tmp_str = tmp_str.split(symbol).join(histogram[symbol]);
    return tmp_str;
  }
  var element;
  try{
    var attribute_str = '';
    for(attribute_name in attributes)
      if (attribute_name!='text')
        attribute_str+= attribute_name+"='"+htmlspecial(o.attributes[attribute_name])+"'";
    element = document.createElement("<"+elementname+" "+attribute_str + ">");//IE
  }catch (e){
    element = document.createElement( elementname );
    for(attribute_name in attributes)
      if (attribute_name!='text')
        element.setAttribute( attribute_name , attributes[attribute_name] );
  }
  if (attributes && attributes['text'])
    element.innerHTML = attributes['text'];
  return element;
}

Thursday, May 28, 2009

iPod Touch

For the economically minded consumer who doesn't need the phone, cell phone camera or gps, but has wi-fi and just needs a solid pda get the ipod touch 8GB 2nd generation. I got a refurbished one for $179.00, and for my chinese work, it is amazing. It does chinese stroke recognition, there are free chinese dictionary apps, skype is came out with a free app as well.



Accessories:

However to use skype you need a microphone for your ipod touch. The charger that comes with it charges off of your computer so if you go on vacation you will need a wall and/or car charger. You will also want to get an audio/video cable set so you can project videos onto your tv set.

JVC Everio

The JVC Everio offers several models. Probably one of the most appealing thing about the everio is that it records to MPEG2 (uncompressed DVD) instead of MPEG4 (highly compressed like a digital camera's video). Its resolution is also DVD resolution 720x480, however it is more like tv quality (interlaced video) and less like digital HD.

It is offering a JVC Everio GZ-MS100 model right now for $180, which is really nice, considering that flash memory will continue to get cheaper. So instead of paying $350 for a hard drive camcorder... get a flash based one, and get a 2GB SD card. In a few years 8GB and 16GB SDHC cards will be cheap, and you can just use that for your camcorder.


For accessories it might be a good idea to get an extra JVC Everio battery. Because even if you have space to record 4 hours of video on your SD card, it doesn't mean your video camera battery will last that long

Tuesday, May 26, 2009

nohup command

nohup ./myscript.sh>log_myscript.log 2>&1 &
tail -f log_myscript.log

nohup ./myscript.sh>log_myscript_`date +%Y%m%d`.log 2>&1 &
tail -f log_myscript_`date +%Y%m%d`.log

`date +%Y%m%d` - grabs current date, inserts it into filename
nohup - script run even after terminal/ssh session ends
>log_myscri... - captures output to log file named log_myscr..
2>&1 - outputs stderr to stdout
& - makes it run in the background
tail -f - watches log, CTRL-C will not stop script

Sunday, May 24, 2009

rsync windows to linux

Scenario: windows has your user data and linux is your backup server.

1. compile cygwin... use the following, place them in your path
(c:\windows\system32 or c:\server\bin\)
rsync.exe
ssh.exe
ssh-keygen.exe
cygcrypto-0.9.8.dll
cygiconv-2.dll
cygintl-8.dll
cygminires.dll
cygpopt-0.dll
cygwin1.dll
cygz.dll

2. on the windows machine, run ssh-keygen at the command promptit will create a file
C:\Documents and Settings\user\.ssh\id_dsa.pub

3. copy C:\Documents and Settings\user\.ssh\id_dsa.pub to the linux machine... then authorize it:
mkdir ~/.ssh
cat id_dsa.pub >>~/.ssh/authorized_keys2
mkdir ~/backups

4. If you want to rsync F:\apps\myfolder then save the following as... backup.bat
-----------
F:
cd \apps
"c:\server\bin\rsync.exe" -arv -e "c:\server\bin\ssh.exe" myfolder user@linux:/home/user/backups/
-----------

Tuesday, May 19, 2009

gpg crontab

1. executing in crontab provides a different set of environment variables, so the --homedir is needed to specify which keyring to use. In the example below, we use root's keyring.
2. --batch is necessary for crontabs because it tells gpg there is no user to interact with
3. 2>&1 is useful because it redirects stderr to stdout so you can better debug any errors you may be having
4. -d is for decrypt. in this case we are decrypting on a cron job

/usr/bin/gpg --batch --homedir /root/.gnupg --passphrase mypassphrase -o /home/output.csv -d /home/input.csv.gpg 2>&1

Monday, April 20, 2009

Curl HTTP Authentication

// HTTP authentication
$url = "http://www.example.com/protected/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>



source(s): http://devzone.zend.com/article/1081-Using-cURL-and-libcurl-with-PHP

Sunday, April 19, 2009

FLTK in Visual C++ Express 2008

FLTK in Visual C++ Express 2008

1. Download fltk-1.1.9-source.zip
2. Unzip to C:\Server\fltk-1.1.9\
3. Your include folder is C:\Server\fltk-1.1.9\FL\
4. Your lib folder is C:\Server\fltk-1.1.9\include\
5. Go into C:\Server\fltk-1.1.9\vc2005\
6. Open fltk.sln
7. Compile as Debug
8. Compile as Release


9. Build your hello world.
(http://www.fltk.org/documentation.php/doc-1.1/basics.html)

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>

int main(int argc, char **argv) {
  Fl_Window *window = new Fl_Window(300,180);
  Fl_Box *box = new Fl_Box(20,40,260,100,"Hello, World!");
  box->box(FL_UP_BOX);
  box->labelsize(36);
  box->labelfont(FL_BOLD+FL_ITALIC);
  box->labeltype(FL_SHADOW_LABEL);
  window->end();
  window->show(argc, argv);
  return Fl::run();
}


10. Configure the following in your project in Visual C++ Express 2008:

Tools > Options > Projects and Solutions > VC++ Directories >
  INCLUDE: C:\Server\fltk-1.1.9
  LIB: C:\Server\fltk-1.1.9\lib

Project > Project Properties > [Debug and Release] > Linker
    > Input > Additional Dependencies
  wsock32.lib fltk.lib comctl32.lib

Thursday, April 02, 2009

setup vnc server on fedora


# assume we are setting it up to vnc as bsmith
su -

# as root: verify current ip address
ifconfig

# as root: install if needed
yum install vnc-server

# as root: uncomment out 2 lines, replace myusername with bsmith
vim /etc/sysconfig/vncservers

# as bsmith: set vnc password
vncpasswd

# as root: generates ~/.vnc/xstartup
service vncserver start

# as root: sets service to startup with machine
chkconfig vncserver on

# as root: uncomment out line 4 and 5
vim /bsmith/.vnc/xstartup

# as root: applies settings
service vncserver start

# as root: open up port in firewall, note vnc is insecure by protocol
vim /etc/sysconfig/iptables

# as root: apply firewall changes, vnc=insecure so better to use over lan
service iptables restart

Thursday, March 26, 2009

C/C++ win32 programming tutorials and open source projects

http://sourceforge.net/projects/sonne/
http://sourceforge.net/projects/cinputbox/
http://sourceforge.net/projects/win32net/
http://sourceforge.net/projects/notepad-plus/
http://sourceforge.net/projects/smartwin/
http://sourceforge.net/projects/radcpp/
http://sourceforge.net/projects/pwrgrid/
http://sourceforge.net/projects/gettext/
http://sourceforge.net/projects/gqview-win/
http://sourceforge.net/projects/win32gui/
http://sourceforge.net/projects/big3dsol/
http://sourceforge.net/projects/bhwindow/
http://sourceforge.net/projects/mancalacpp/
http://sourceforge.net/projects/win32-framework/

http://winprog.org/tutorial/
http://www.winprog.org/tutorial/msvc.html
http://www.relisoft.com/win32/index.htm
http://www.suite101.com/blog/leckyt/win32_programming_tutorial
http://www.functionx.com/win32/index.htm
http://www.functionx.com/win32/Lesson01.htm
http://www.nullterminator.net/opengl32.html
http://www.zetcode.com/tutorials/winapi/
http://www.vczx.com/tutorial/win32-tutorial/index.html
http://www.tenouk.com/cnwin32tutorials.html
http://www.sgi.com/products/software/opengl/examples/win32_tutorial/
http://www.geocities.com/Heartland/Meadows/9818/win32tut/index.html
http://www.relisoft.com/Win32/winnie.html