Wednesday, February 27, 2008

Some UNIX CLI tips

# Make complex directory stucture with one command
mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}

# Extract to a particular directory that you're not currently in
tar xvf -C tmp/a/b/c newarc.tar.gz

# Use 'grep -c' instead of 'wc -l' to count lines
grep -c blah

# Matching a pattern in a particular field in a file
ls -l | awk '{print $6}' | grep Dec # BAD
ls -l | awk '$6 == "Dec"' # GOOD



50 Proprietary Apps and Their Open Source Counterparts

http://whdb.com/2008/the-top-50-proprietary-programs-that-drive-you-crazy-and-their-open-source-alternatives/

Thursday, February 14, 2008

Simple ruby set_trace_func() call

This is a very simple and pre-formatted set_trace_func() call. Quite handy!

set_trace_func proc { |event, file, line, id, binding, classname| printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname }

Friday, February 01, 2008

Manully configure OpenWRT to block outgoing connections

  • Login to your router from the web with your favorite webrowser ( the default address is http://192.168.1.1 )
  • Select the "System" tab then then "File Editor" sub tab.
  • the file you want to edit is in /etc/firewall.user
  • click the "Edit" button near the firewall.user file
  • scroll to the end of this file and paste the following:
    • for blocking from the entire LAN ("-i $LAN" part selects all interfaces on the LAN side)
iptables -A forwarding_rule -p udp -i $LAN --dport 5121 -j DROP
    • if we are using wifi split from the bridge, we can add this rule:
[ -n "$WIFI" ] && iptables -A forwarding_rule -p udp -i $WIFI --dport 5121 -j DROP
    • to block a port from one machine on the LAN (example is 192.168.1.101) from reaching outside the router:
iptables -A forwarding_rule -p udp -s 192.168.1.101 --dport 5121 -j DROP
  • save changes
  • apply changes