Skip to content

Instantly share code, notes, and snippets.

View lambdaman2's full-sized avatar

Lambdaman lambdaman2

View GitHub Profile
@lambdaman2
lambdaman2 / Snipplr-25270.py
Created October 1, 2012 12:48
Python: Zip function
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> zipped
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zipped)
>>> x == x2, y == y2
True
@lambdaman2
lambdaman2 / Snipplr-53250.py
Created October 1, 2012 12:48
Python: Ways to Move up and Down the dir structure in Python
#Moving up/down dir structure
print os.listdir('.') # current level
print os.listdir('..') # one level up
print os.listdir('../..') # two levels up
# more complex example:
# This will walk the file system beginning in the directory the script is run from. It
# deletes the empty directories at each level
@lambdaman2
lambdaman2 / Snipplr-27238.py
Created October 1, 2012 12:48
Python: Wait function - python
from time import sleep
sleep(5) #sleeps for 5 seconds
@lambdaman2
lambdaman2 / Snipplr-42632.js
Created October 1, 2012 12:48
JavaScript: Verify if an html element is empty
if ($('#keks').html()) {
// Do something to remedy the situation
}
@lambdaman2
lambdaman2 / Snipplr-25278.bash
Created October 1, 2012 12:48
Bash: use curl to share code/text from terminal
# weird way to represent \' // exit using ctrl-D
alias sharecode='curl -si -F '\''content=<-'\'' http://dpaste.com/api/v1/ | grep ^Location: | colrm 1 10'
@lambdaman2
lambdaman2 / Snipplr-28264.bash
Created October 1, 2012 12:48
Bash: Updating Textmate Getbundles
cd ~/Library/Application\ Support/TextMate/Bundles
svn co http://svn.textmate.org/trunk/Review/Bundles/GetBundles.tmbundle/
@lambdaman2
lambdaman2 / Snipplr-25235.bash
Created October 1, 2012 12:48
Bash: UNIX: remove all files with certain characteristics
find . -name \*.pyc -ok rm {} \;
@lambdaman2
lambdaman2 / Snipplr-50835.py
Created October 1, 2012 12:48
Django: Strip/Remove HTML tags (django utils)
# To strip/remove HTML tags from an existing string we can use the strip_tags function.
# import the strip_tags
from django.utils.html import strip_tags
# simple string with html inside.
html = '<p>paragraph</p>'
print html # will produce: <p>paragraph</p>
stripped = strip_tags(html)
@lambdaman2
lambdaman2 / Snipplr-40571.py
Created October 1, 2012 12:48
Python: String literals that span multiple lines
# Continuation lines can be used, with a backslash as the last character on the
# line indicating that the next line is a logical continuation of the line:
hello = "This is a rather long string containing\n\
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
significant."
print hello
@lambdaman2
lambdaman2 / Snipplr-57051.py
Created October 1, 2012 12:48
Python: Statistical String Comparison
>>> import difflib
>>> difflib.SequenceMatcher(None, 'abcde', 'abcde').ratio()
1.0
>>> difflib.SequenceMatcher(None, 'abcde', 'zbcde').ratio()
0.80000000000000004
>>> difflib.SequenceMatcher(None, 'abcde', 'zyzzy').ratio()
0.0