Most Viewed


sqlite 10 sec guide

Problem

You want to get up and running with sqlite



Solution

Install sqlite3 on linux, via yum: yum install sqlite3

Then just run sqlite dbname



Example


% sqlite3 testdata.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> create table memos(text,priority INTEGER);
sqlite> insert into memos values('deliver project description',10);
sqlite> insert into memos values('lunch with Christine',100);
sqlite> select * from memos;
deliver project description|10
lunch with Christine|100
sqlite>



Reference

  1. sqlite3 linux man page
  2. sqlite official site


starting binary – library file not found

Problem

Getting an error about not being able to find libraries (file not found), when starting up a binary – such as httpd.



Solution

You need to identify the shared libraries required by your binary. Ordinarly we use the ldd command for this and amended LD_LIBRARY_PATH to find the libs – see example below.

You might also want to get the shared libs of a running process – with pldd or need to dig into a lib/binary.



Example

# find dependencies for a binary


% ldd /usr/bin/httpd
libpng.so.2 => /usr/local/lib/libpng.so.2
libcrypt_i.so.1 => /usr/lib/libcrypt_i.so.1
libresolv.so.2 => /usr/lib/libresolv.so.2

# demo of how ldd walks the values in LD_LIBRARY_PATH


% unset LD_LIBRARY_PATH

% ldd /usr/bin/httpd
libpng.so.2 => (file not found)
libcrypt_i.so.1 => /usr/lib/libcrypt_i.so.1
libresolv.so.2 => /usr/lib/libresolv.so.2

# find files installed via a package on Solaris


% grep libpng.so.2 /var/sadm/install/contents | head -1
/usr/sf/lib/libpng.so=libpng.so.2 s none SUNWpng

Another way to see which libraries are being picked up, i.e. if a binary works on one system and not another:


% truss -t'open' -f date
21667: open("/var/ld/ld.config", O_RDONLY) Err#2 ENOENT
21667: open("/usr/lib/libc.so.1", O_RDONLY) = 3
21667: open("/usr/lib/libdl.so.1", O_RDONLY) = 3
...

Getting the dependent shared libraries of a running process (especially where vars might have changed since startup):


% pldd 24832
24832: /usr/bin/httpd
/usr/local/lib/libpng.so.2.1.0.5
/usr/lib/libcrypt_i.so.1
/usr/lib/libresolv.so.2
...

Seeing more detail via the headers within an object file (use objdump on linux):


% elfdump /usr/bin/httpd | grep NEEDED
[0] NEEDED 0x15755 libpng.so.2
[1] NEEDED 0x15761 libcrypt_i.so.1
[2] NEEDED 0x15771 libresolv.so.2
...

See configure parameters passed to a binary during compilation (can also be useful for getting a usage out a binary, that does not appear by default or with –h, etc):



Reference

  1. Linux ldd man pages
  2. Linux objdump man pages
  3. Reverse Engineering Linux Binaries


the fade anything technique

Problem

You want to add something flash to your site.

A color loads, which you then want to change



Solution

Well cool “Fade Anything Technique”!

Really simple implementation, just copy fade anything and then any divs, etc with an id
of fade-xxx will fade from that color. Many more options, check out these highly recommended articles.



Example


<head>
...
<script type="text/javascript" src="/fat.js">
</head>
...
<div style="width: 600px; border:1px dashed #23932B; padding: 10px;" id="fade-23932B" class="fade-23932B">
...
</div>



Reference

Check out the article hosted by axentric, written by Adam Michela

It was inspired by 37 signals



AJAX Specialist

coming soon …

Stripping out newlines from string

Problem

Different versions of UNIX handle the stripping of newlines in a string differently. Obviously if you echo a string, the shell automatically expands newlines “\n”.



Solution

sed and tr don’t appear to like performing these substitutions. But with Perl its a steal. :)



Example


% echo 'hello world\nhello world\ntest it' | perl -ane 's#\\n# #g; print,"";'

hello world hello world test it



Reference

Technorati Tags: ,



Resize image command line – mogrify

Problem

You want to resize images from the command line.



Solution

Use image magik mogrify command.


mogrify -resize "percentage" image_na

Also you can view current sizing – like this:


% identify IMG_3864.JPG
IMG_3864.JPG JPEG 563x422 563x422+0+0 DirectClass 8-bit 32.8887kb



Example


mogrify -resize 20% IMG_3705.JPG



Reference

Technorati Tags:



UNIX Pipes – event triggers action

Problem

You want to listen on a pipe and perform commands, based on the text sent to the pipe.

This could be useful for triggering action based on events;
Running code as different users – i.e. allow root or a functional user to run something – just need to allow access to group of users, via permission to write to the pipe.



Solution


1. mknod /tmp/.restart_crd

2. chmod a+w /tmp/.restart_crd

3. nohup tail -f /tmp/.restart_crd| while read line
do
case "$line" in
'restart') cmd="./stop >> /tmp/restart.log 2>&1; sleep 5; ./start >> /tmp/restart.log 2>&1";;
'stop') cmd="./stop >> /tmp/restart.log 2>&1";;
'start') cmd="./start >> /tmp/restart.log 2>&1";;
*) cmd="no match ${line}.";;
esac

echo "command is $cmd"
eval $cmd

sleep 5

done &

4. disown



Example


$ echo "restart" > /tmp/.restart_crd

$ echo "start" > /tmp/.restart_crd

$ echo "stop" > /tmp/.restart_crd

Watch output in by tail -f /tmp/restart.log



Reference

Technorati Tags: ,



ldapsearch limit returned results

Problem

You want to perform an ldap search but only receive a limited number of records in return.



Solution

Use -z # to restrict the number of records returned.



Example

Search and return only 5 records.


ldapsearch -x -z 5 -v-D"cn=Manager,dc=demo,dc=net"-w secret \
-b"dc=demo,dc=net" "(lastlogin>=99999999)"



Reference

Technorati Tags: ,



ldapsearch greater than

Problem

You want to search for a field greater than a value, in your LDAP search.



Solution

To search for a field with a value greater than a given figure, we use >=. If you try to just use > it chucks out an error.



Example

This is how to perform a greater than LDAP search.


ldapsearch -x -v-D"cn=Manager,dc=demo,dc=net"-w secret \
-b"dc=demo,dc=net" "(lastlogin>=99999999)"



Reference

Technorati Tags: , ,



phpdoc-msg

These pages have been retired, check out php docs