Skip to content

Instantly share code, notes, and snippets.

View lukasklein's full-sized avatar
👀
Facebook is it you?

Lukas Klein lukasklein

👀
Facebook is it you?
View GitHub Profile
@lukasklein
lukasklein / gist:3963854
Created October 27, 2012 09:56
Toggle password field
$(function() {
$('input[type="password"]')
.each(function() {
var that = this;
$(this).after($('<input>')
.attr('type', 'checkbox')
.click(function() {
that.type = (that.type === 'password' ? 'text' : 'password');
})
.after($('<span>'))
@lukasklein
lukasklein / gist:3957868
Created October 26, 2012 09:40
Django change request.POST
def index(request):
if request.method == 'POST':
post_mutable = request.post.copy()
# Now you can change values:
post_mutable['answer'] = 42
def generate(code):
code_obj = compile(code, '<string>', 'exec')
code_ = code_obj.co_code
code = ''
for char in code_:
code += 'chr(' + str(hex(ord(char))) + ')+'
code = code[:-1]
return "type(make_secure)(code=type(make_secure.__code__)(%d,%d,%d,%d,%s,%s,%s,%s,'%s','%s',%d,'%s'),globals={})()" % (code_obj.co_argcount, code_obj.co_nlocals, code_obj.co_stacksize, code_obj.co_flags, code, str(code_obj.co_consts).replace(' ', ''), str(code_obj.co_names).replace(' ', ''), str(code_obj.co_varnames).replace(' ', ''), code_obj.co_filename, code_obj.co_name, code_obj.co_firstlineno, str(code_obj.co_lnotab))
if __name__ == "__main__":
@lukasklein
lukasklein / analyze.py
Created October 12, 2012 18:52
Subsitution cipher helper
import json
english_json = open('english.json', 'r').read()
frequencies_english = json.loads(english_json)
frequencies_english_sorted = []
for char in sorted(frequencies_english, key=frequencies_english.get, reverse=True):
frequencies_english_sorted.append({'char': char, 'frq': frequencies_english[char]})