Friday, December 10, 2010

How to organize delay with mootools

(function(){ loadContent(isLoaded); }).delay(3000);

Friday, November 19, 2010

How to transpose output/file in bash

for i in {1..100}; do echo $i; done | psc -r | sc -W% -

Random words generator in bash (random line reader)

n=$(cat /usr/share/dict/words | wc -l)
sed $(( ($RANDOM * 32768 + $RANDOM) % n ))"q;d" /usr/share/dict/words

How to replace some text in next line that forwards after matched to current line

#!/bin/sh
sed '/ONE/ {
N
s/TWO//
}' < text.txt > text.txt.tmp

Wednesday, November 10, 2010

SQL for delete duplicates

delete from table where id in (select (select id from table where col82 = x.col82 order by id asc limit 1) from (select count(id) cnt, col82 from table group by col82 order by cnt desc) x where x.cnt > 1);

Friday, November 5, 2010

Mini one page web server by using netcat (nc)

It will be helpful for debugging requests. You need bash and nc.
For some reasons debian and ubuntu have different net cat's version with different syntax:
- debian:
while echo -e "HTTP/1.0 200 OK\nContent-Type: text/html\n\n" | netcat -v -v -q 1 -lp 60000; do echo ""; done

- ubuntu:
while echo -e "HTTP/1.0 200 OK\nContent-Type: text/html\n\n" | netcat -lv 60000; do echo ""; done

To test it use command: netcat localhost 60000

Thursday, October 28, 2010

how to set mootools slider for some elements


Friday, October 22, 2010

Kill only tomcat, java survive

ps auxww | grep tomcat | grep -v grep | awk '{ print $2 }' | xargs kill -9

Monday, September 27, 2010

How to remove all files older than

find . -type f -mtime +4 | while read line ; do rm $line ; done;

Tuesday, August 31, 2010

How to normalize permissions 644 for files 755 for directories

for i in `find . -type d`; do chmod 755 $i; done
for i in `find . -type f`; do chmod 644 $i; done

Thursday, August 19, 2010

How to url encode string/file in bash cmd

echo "sdf sd fs / df"| perl -MURI::Escape -lne 'print uri_escape($_)'

Friday, July 16, 2010

How to backup directory to remote server with rsync

rsync -r -v -e ssh /www/backup jerry@openbsd.nixcraft.in:~

Thursday, June 17, 2010

How to send email from bash with attachment using standard unix utils

mpack -s "Subject" -c application/octet-stream /home/user/file.zip friends@email.com

Wednesday, June 16, 2010

How to extract some file from rar archive under bash

rar x archive.rar archives/sql/file.ext /tmp
rar vb archive.rar | grep file

Exclude lines that contains some data with grep

cat test.csv | grep -v -E "(@test.com|12345678909)"

Tuesday, June 8, 2010

flush squid cache for one site

squidclient -h localhost -p 3128 -m PURGE http://www.example.com

Monday, March 22, 2010

Match all letters (also unicode)

([\x0000-\xFFFF]|[^\x00-\xFF])

Monday, February 15, 2010

How to delete all folders with specific size

du -s * | grep 12776 | awk '{split($0,a," "); print a[2]}' > /tmp/a
while read line; do rm -rf $line; done < /tmp/a