Perl one-liner to check if OS is big endian or littel endian 

perl -MConfig -e '($Config{byteorder} == 1234) ? print "$^O is little endian\n" : print "$^O is big endian\n"

linux are in little endian (right to left)

Network byte order,Darwin is big endian (left to right)
[ add comment ] permalink ( 3 / 108 )
Perl multi pattern grep 

Here is my little Perl multi pattern grep script modifed from <<Advanced Perl Programming>>

#!/usr/bin/perl
use strict;
use warnings;

open my $fh, '<', pop(@ARGV) or die "Could not open $ARGV[-1]:$!";

my $code = 'while (<$fh>) {';
$code .= 'if (/';
$code .= join ('/ && /', @ARGV);
$code .= '/) {print $_;}}';
print $code, "\n";
eval $code; #ahh, finally !
#check if faulty regular expressions given as input patterns
die "Error ---: $@\n Code: \n$code\n" if ($@);

[ add comment ] permalink ( 2.9 / 126 )
mrt to show ip route and packet loss 

Lately, because of Taiwan earth quake, the fabric cable broke between North America and South East Asia, mrt it a good tool to show route and network traffic jam for this case:

# mtr --interval=5 www.chinaunix.net

Host Loss% Snt Last Avg Best Wrst StDev
1. mygw 0.0% 19 0.8 0.8 0.8 0.9 0.0
2. a14-i2.net.ubc.ca 0.0% 19 0.8 0.7 0.6 0.9 0.1
3. 142.103.78.169 0.0% 19 0.4 0.4 0.3 0.4 0.0
4. 207.23.240.54 0.0% 19 0.8 0.8 0.7 1.0 0.1
5. ra1wh-ge4-3-15.vc.bigpipeinc.com 0.0% 19 1.1 5.9 0.9 79.8 18.0
........................................................snip........................................................
8. sl-gw12-sea-1-0.sprintlink.net 0.0% 19 5.5 5.5 5.2 5.8 0.2
14. sl-gw27-stk-8-0.sprintlink.net 0.0% 19 26.2 26.1 25.9 26.5 0.2
15. sl-china7-6-0.sprintlink.net 61.1% 19 525.5 510.7 496.6 525.5 9.0
16. 219.158.3.173 27.8% 19 365.2 391.3 355.9 546.3 56.0
........................................................snip........................................................
22. www84.asd.tj.cn 35.3% 18 510.5 509.6 502.1 518.1 4.6
[ add comment ] permalink ( 3 / 96 )
Perl one-liner caculator 

perl -e 'while (defined ($s = <>)) { $result = eval $s; $@? print "invalid string: \n $s" : print $result, "\n"; }'
[ add comment ] permalink ( 2.9 / 80 )
VLC Command Line to Stream USB Webcam 

The command line interface for VLC seems a little bit comlex, after playing it a bit, I conculded following working command line:

vlc v4l:// :v4l-vdev='/dev/video0' :v4l-adev='/dev/dsp' --sout '#duplicate{dst=display, dst=std{access=http, mux=asf, url=ip:port}}'
[ add comment ] ( 28 views ) permalink ( 3.1 / 88 )

Back Next