This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
with open(fname) as f: | |
content = f.readlines() | |
f.close() | |
# http://stackoverflow.com/questions/3277503/python-read-file-line-by-line-into-array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
for dirname, dirnames, filenames in os.walk('.'): | |
# print path to all subdirectories first. | |
for subdirname in dirnames: | |
print os.path.join(dirname, subdirname) | |
# print path to all filenames. | |
for filename in filenames: | |
print os.path.join(dirname, filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myString="Hello there !bob@" | |
mySubString=myString[myString.find("!")+1:myString.find("@")] | |
print mySubString | |
## extract text between ! and @ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f = open('myfile.txt') | |
for line in iter(f): | |
print line, | |
f.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ls -d */ | xargs -l basename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
insert | |
into table2 | |
select * | |
from table1 | |
######### | |
insert | |
into table2 | |
( col1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Elapsed time. Usage: | |
# | |
# t=$(timer) | |
# ... # do something | |
# printf 'Elapsed time: %s\n' $(timer $t) | |
# ===> Elapsed time: 0:01:12 | |
# | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
fib () { | |
if [ $1 -le 1 ]; then | |
echo $1 | |
else | |
echo $[$[`fib $[$1 - 1]` + `fib $[$1 - 2]`]] | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Perl trim function to remove whitespace from the start and end of the string | |
sub trim($) | |
{ | |
my $string = shift; | |
$string =~ s/^\s+//; | |
$string =~ s/\s+$//; | |
return $string; | |
} | |
# Left trim function to remove leading whitespace | |
sub ltrim($) |