This file contains hidden or 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
def decorator_function(original_function): | |
# x will not be accessible inside functions decorated by `decorator_function` | |
x = "certified organic and local" | |
def inner(): | |
return original_function() | |
return inner |
This file contains hidden or 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 functools | |
class ArgumentLengthMismatchException(Exception): | |
pass | |
class InvalidParameterTypeException(Exception): | |
pass |
This file contains hidden or 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
def get_user_from_db(username): | |
statement = "SELECT * FROM users WHERE name ='" + username + "';" | |
cursor.execute(statement) | |
return cursor.fetchall()[0] | |
get_user_from_db("'; DROP TABLE users; '") |
This file contains hidden or 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
(function () { | |
jQuery.fn.pushStack = function( elems, name, selector ) { | |
// Build a new jQuery matched element set | |
var ret = this.constructor(); | |
// temporary workaround for chrome issue #125148 | |
// http://code.google.com/p/chromium/issues/detail?id=125148 | |
if (!(ret instanceof jQuery.fn.init)) { |
This file contains hidden or 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
@my_decorator | |
def foo(bar): | |
return bar | |
# IS EXACTLY THE SAME AS | |
def foo(bar): | |
return bar | |
foo = my_decorator(foo) |
This file contains hidden or 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
class Foo | |
class << self | |
def bar | |
"baz" | |
end | |
end | |
end | |
self = Foo.new | |
self.bar |
This file contains hidden or 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
def quine(source) | |
puts source + '%Q{' + source + '}' | |
end | |
quine %Q{def quine(source) | |
puts source + '%Q{' + source + '}' | |
end | |
quine } |
This file contains hidden or 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
function loadScript(src, callback) { | |
var head = document.getElementsByTagName('head')[0]; | |
var new_script = document.createElement('script'); | |
new_script.type = 'text/javascript'; | |
new_script.src = src; | |
// most browsers | |
new_script.onload = callback; | |
// IE 6 & 7 |
This file contains hidden or 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 hashlib | |
def allstrings(alphabet, length): | |
""" Get all strings made of characters from `alphabet` up to length of `length`.""" | |
if length <= 0 or len(alphabet) == 0: return [] | |
alphabet = set([alpha for alpha in alphabet]) | |
allstr = set([ch for ch in alphabet]) |
This file contains hidden or 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
#include <string.h> | |
void reverse(char* str) { | |
int i; | |
int len = strlen(str); | |
for (i = 0; i < len/2 ; ++i){ | |
str[len] = str[i]; | |
str[i] = str[len - i - 1]; | |
str[len - i - 1] = str[len]; |