Skip to content

Instantly share code, notes, and snippets.

@puneetlakhina
puneetlakhina / makengram.py
Created November 30, 2011 10:09
Make n grams from a list of words
def ngram(words,n):
return ["_".join(words[i:i+n]) for i in range(0,len(words)-n+1)]
@puneetlakhina
puneetlakhina / useful.sh
Created November 8, 2011 17:53
Useful command lines
netstat -tuanp | grep LISTEN | grep (port number) #listening ports using netstat #use -p to list process id also
@puneetlakhina
puneetlakhina / toutc.pl
Created November 7, 2011 22:32
Convert localtime to unix timestamp
#!/usr/bin/perl
#Format of ip Month/Year/DateThour:minute:seconds
use Time::Local;
my ($date,$time) = split 'T' , $ARGV[$1];
#print $date."\n".$time."\n";
my ($month, $day, $year) = split '/', $date;
$month = $month - 1; #this is because timelocal wants the month to be zero indexed
#print $month."\n";
my ($hr, $
@puneetlakhina
puneetlakhina / reversestraltupper.py
Created October 20, 2011 07:33
Python reverse a string with alternate letter capitalization
#!/usr/bin/python
import sys
s = sys.argv[1]
n=len(s)
print ''.join([s[i] if i%2 == 0 else s[i].upper() for i in range(n-1,-1,-1)])
@puneetlakhina
puneetlakhina / reversestr.py
Created October 20, 2011 07:31
Python reverse a string
#!/usr/bin/python
import sys
s = sys.argv[1]
n=len(s)
print ''.join([s[i] for i in range(n-1,-1,-1)])