text = open('a_unicode_file.txt', 'r').read()
print text
print 'type:', type(text) # str is a container for binary data
print 'bytes:', len(text) # The number of bytes, not characters!
print ' '.join(repr(b) for b in text)
print 'first byte:', text[:1] # Prints an invalid character!
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
#!/usr/bin/env python | |
import re | |
import sys | |
def rep(sval): | |
return str(int(sval.group()) * 2) | |
if __name__ == '__main__': |
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
#!/bin/bash | |
# To add two items to the current .gitignore file: | |
# gitignore '*.swp' bin | |
# | |
# To sort and de-dupe the current .gitignore file: | |
# gitignore | |
# Append each argument to its own line: | |
for item in "$@"; do | |
echo "$item" >> .gitignore; |
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
var preloadImage = function(url, callback) { | |
var loaded = false, | |
loadHandler = function() { | |
if (!loaded) { | |
callback(url); | |
} | |
loaded = true; | |
}, | |
img = $('<img>') | |
.one('load', loadHandler) |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import re, sys | |
def magic_match(pattern, target): | |
frame = sys._getframe(1) | |
result = re.match(pattern, target) | |
# This is properly, properly evil. Don't do this: |
I hereby claim:
- I am judy2k on github.
- I am judy (https://keybase.io/judy) on keybase.
- I have a public key whose fingerprint is 1F8A C55A EC5F F23B 013A DDD2 F298 5834 FAE5 4325
To claim this, I am signing this object:
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
#!/usr/bin/env python | |
def outer(): | |
i = [0] | |
def inner(): | |
i[0] += 1 | |
print i[0] | |
return inner | |
f = outer() |
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
Traceback (most recent call last): | |
File "./uc.py", line 7, in <module> | |
u += '/' + b | |
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 1: ordinal not in range(128) |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from functools import wraps | |
def test(condition): | |
def test_decorator(f): | |
@wraps(f) | |
def test_wrapper(n): |
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 call_me(names=[]): | |
names.append('Stupid') | |
print ' '.join(names) | |
for _ in range(10): | |
call_me() |