the fade anything technique

[problem]

You want to add something flash to your site.
A color loads, which you then want to change

[/problem]

[solution]

Well cool “Fade Anything Technique”!

Really simple implementation, just copy fade anything>%20fade%20anything%20fat.js%20< 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.

[/solution]

[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>

[/example]

[reference]

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

It was inspired by 37 signals

[/reference]

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”.

[/problem]

[solution]

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

[/solution]

[example]


% echo 'hello worldnhello worldntest it' | perl -ane 's#\n# #g; print,"";'

hello world hello world test it

[/example]

[reference]

[tags], Unix Coding School[/tags]

[/reference]

Resize image command line – mogrify

[problem]

You want to resize images from the command line.

[/problem]

[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

[/solution]

[example]


mogrify -resize 20% IMG_3705.JPG

[/example]

[reference]

[tags]mogrify[/tags]

[/reference]

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.

[/problem]

[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

[/solution]

[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

[/example]

[reference]

[tags], Unix Coding School[/tags]

[/reference]

ldapsearch limit returned results

[problem]

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

[/problem]

[solution]

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

[/solution]

[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)"

[/example]

[reference]

[tags], LDAP Training School[/tags]

[/reference]

ldapsearch greater than

[problem]

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

[/problem]

[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.

[/solution]

[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)"

[/example]

[reference]

[tags]ldapsearch syntax, openldap ldapsearch, LDAP Training School[/tags]

[/reference]

receive notification when file arrives

[problem]

You want to get notified when a file arrives. Maybe it is coming in from somewhere else, or just is the result of some processing.

What ever the case, never sit there waiting for a file to arrive again! 🙂

[/problem]

[solution]

Put the code under example tab, in a cron entry. See reference for more detail about cron.

Change the minutes, hour, filename and mail address! 🙂 You may need to use mail instead of mailx and ksh, etc instead of bash. But the basic syntax is the same. 🙂

[/solution]

[example]


0-59 12 * * * bash -c "([ -f $HOME/test-touch ] &&
mailx -s "test-touch found at `date`" [email protected]

[/example]

[reference]

[tags]cron, UNIX Batch, UNIX Scripts, Unix Coding School[/tags]

[/reference]

UNIX debugging

[problem]

  1. You want to debug a running process on Solaris?
  2. You want to debug running process on Linux?

[/problem]

[solution]

See the example for debugging processes on Solaris or Linux – the syntax shows all system executes and reads.

[/solution]

[example]

  1. truss -xall -vall -rall -t'read' -p PID #

    To run a command and have it produce debug info, run it prefix with the truss syntax:

    truss -xall -vall -rall -t'read' your command #

    Another good option when debugging, is to run truss and look at the opens. Or more specifically the failures – as this often highlights missing libraries or permissions issues.

    truss -t'open' -p PID #

  2. On Linux use strace, which takes basically the same options. You just use -e, like this:

    strace -e'open' ls
    open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/etc/ld.so.cache", O_RDONLY) = 3
    open("/lib/tls/librt.so.1", O_RDONLY) = 3
    open("/lib/libtermcap.so.2", O_RDONLY) = 3
    open("/lib/libacl.so.1", O_RDONLY) = 3
    open("/lib/tls/libc.so.6", O_RDONLY) = 3
    open("/lib/tls/libpthread.so.0", O_RDONLY) = 3
    open("/lib/libattr.so.1", O_RDONLY) = 3
    open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3
    open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
    open("/etc/mtab", O_RDONLY) = 3
    open("/proc/meminfo", O_RDONLY) = 3

[/example]

[reference]

[tags]UNIX Debugging, Solaris Debugging, Linux Debugging, truss, strace, Unix Coding School[/tags]

[/reference]