codesnips's posterous http://codesnips.posterous.com Most recent posts at codesnips's posterous posterous.com Mon, 27 Jul 2009 05:11:23 -0700 mysqldump http://codesnips.posterous.com/mysqldump-1 http://codesnips.posterous.com/mysqldump-1 mysqldump -u DBUSER -p DBNAME > DBNAME.sql

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Tue, 14 Jul 2009 07:10:18 -0700 [Networking] Watching dhcp traffic http://codesnips.posterous.com/networking-watching-dhcp-traffic http://codesnips.posterous.com/networking-watching-dhcp-traffic tcpdump -i <eth> -n port 67 and port 68

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Sun, 12 Jul 2009 15:03:27 -0700 [Ruby] Splat operator http://codesnips.posterous.com/ruby-splat-operator http://codesnips.posterous.com/ruby-splat-operator expand array items into individual arguments.

>> ar
=> ["a", "b"]
>> ar.class
=> Array

>> def ar_in(*args)
>>    puts args, args.length
>> end

without splat
?> ar_in(ar)
a
b
1

this is what we want
>> ar_in('a', 'b')
a
b
2

which is possible by using the splat operator before the array

>> ar_in(*ar)
a
b
2

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Fri, 03 Jul 2009 18:17:37 -0700 [Ruby] Cut with ruby http://codesnips.posterous.com/ruby-cut-with-ruby http://codesnips.posterous.com/ruby-cut-with-ruby ruby -a -ne 'puts $F[1], $F[2]'

-a will split the input into an array called $F. The above will print the second and the third item of the array (based on 0 index)

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Fri, 03 Jul 2009 18:00:27 -0700 [Ruby] Comment out every line in file http://codesnips.posterous.com/ruby-comment-out-every-line-in-file http://codesnips.posterous.com/ruby-comment-out-every-line-in-file ruby -i.bak -pe '$_ = "#" + $_' *

-i.bak keeps the original file safe by making a backup

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Fri, 03 Jul 2009 17:56:39 -0700 [Ruby] Grep with Ruby http://codesnips.posterous.com/ruby-grep-with-ruby http://codesnips.posterous.com/ruby-grep-with-ruby ruby -ne 'puts $_ if $_ =~ /text/' *

-n places an implicit while gets ... end block

gets(separator=$/)    => string or nil
------------------------------------------------------------------------
     Returns (and assigns to +$_+) the next line from the list of files
     in +ARGV+ (or +$*+), or from standard input if no files are present
     on the command line. Returns +nil+ at end of file. The optional
     argument specifies the record separator. The separator is included
     with the contents of each record. A separator of +nil+ reads the
     entire contents, and a zero-length separator reads the input one
     paragraph at a time, where paragraphs are divided by two
     consecutive newlines. If multiple filenames are present in +ARGV+,
     +gets(nil)+ will read the contents one file at a time.

        ARGV << "testfile"
        print while gets

     _produces:_

        This is line one
        This is line two
        This is line three
        And so on...

     The style of programming using +$_+ as an implicit parameter is
     gradually losing favor in the Ruby community.

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Fri, 03 Jul 2009 14:37:34 -0700 [Networking] Tcpdump capture traffic on port 8773 via eth1 interface http://codesnips.posterous.com/networking-tcpdump-capture-traffic-on-port-87 http://codesnips.posterous.com/networking-tcpdump-capture-traffic-on-port-87 tcpdump -i eth1 -s0 -A -v port 8773

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Fri, 03 Jul 2009 14:36:09 -0700 [Networking] Tcpdump show all interfaces http://codesnips.posterous.com/networking-tcpdump-show-all-interfaces http://codesnips.posterous.com/networking-tcpdump-show-all-interfaces tcpdump -D

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Fri, 03 Jul 2009 14:35:17 -0700 [Ruby] Generate IP addresses http://codesnips.posterous.com/ruby-generate-ip-addresses http://codesnips.posterous.com/ruby-generate-ip-addresses (10..50).each { |n| ips << "10.1.1.#{n} " }

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Fri, 03 Jul 2009 14:34:40 -0700 [Java] jar unpacking and packing http://codesnips.posterous.com/java-jar-unpacking-and-packing http://codesnips.posterous.com/java-jar-unpacking-and-packing

jar xvf ../file.jar

jar cvf ../file.jar.patched 

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Fri, 03 Jul 2009 14:30:54 -0700 [Bash] for loop to check file has CR chars http://codesnips.posterous.com/bash-for-loop-to-check-file-has-cr-chars http://codesnips.posterous.com/bash-for-loop-to-check-file-has-cr-chars for f in find . -maxdepth 1 -type f | grep -v svn; do file -e apptype compress elf fortran soft tar token troff $f | grep CRLF ; done

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Fri, 03 Jul 2009 14:30:14 -0700 [Bash] Disk Usage http://codesnips.posterous.com/bash-disk-usage http://codesnips.posterous.com/bash-disk-usage du -cks --si * | sort -rn

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Fri, 03 Jul 2009 14:29:51 -0700 [RPM] Extract RPM file without installing it http://codesnips.posterous.com/rpm-extract-rpm-file-without-installing-it http://codesnips.posterous.com/rpm-extract-rpm-file-without-installing-it rpm2cpio RPM_FILE | cpio -idmv

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Fri, 03 Jul 2009 14:24:01 -0700 Ruby :: Gives you CPU architecture and removes EOL character http://codesnips.posterous.com/ruby-gives-you-cpu-architecture-and-removes-e http://codesnips.posterous.com/ruby-gives-you-cpu-architecture-and-removes-e ruby -e '%x[uname -i].sub!("\n", "")'

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon
Thu, 02 Jul 2009 15:01:38 -0700 Hello World http://codesnips.posterous.com/hello-world-941 http://codesnips.posterous.com/hello-world-941 Hello World

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEUNoMjESR imon imon