\ backslash ` backtick * asterisk _ underscore {} curly braces [] square brackets () parentheses # hash mark + plus sign
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 math | |
def prime(n): | |
p = [2] | |
x = 3 | |
while len(p) < n: | |
isprime = True | |
for i in p: | |
if i > math.sqrt(x): | |
break |
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
def f_simple_yet_stupid(n): | |
if n == 1 or n == 2: | |
return 1 | |
return f(n - 1) + f(n - 2) | |
def f(n): | |
a = [0, 0, 1] | |
for i in range(n - 1): | |
a[:2] = a[1:] | |
a[2] = a[0] + a[1] |
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
<script src=jquery.js></script> | |
<script src=jquery.infinitescroll.js></script> | |
<div id="content"> | |
<div class=navigation><a href="page1.html">page1</a></div> | |
<div class=post> | |
<p>root:x:0:0:root:/root:/bin/bash | |
<p>daemon:x:1:1:daemon:/usr/sbin:/bin/sh | |
<p>bin:x:2:2:bin:/bin:/bin/sh | |
<p>sys:x:3:3:sys:/dev:/bin/sh |
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
45rt$RFV |
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
#!/usr/bin/env python | |
import cgi | |
import os | |
import sys | |
import Cookie | |
def init_page(user='guest'): | |
return '''Content-Type: text/html |
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
class Unbuffered: | |
def __init__(self, stream): | |
self.stream = stream | |
def write(self, data): | |
self.stream.write(data) | |
self.stream.flush() | |
def __getattr__(self, attr): | |
return getattr(self.stream, attr) | |
import sys |
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 threading | |
def foo(): | |
alive = True | |
c = threading.Condition() | |
def heartbeater(): | |
heartbeat_interval = 60 | |
heartbeat_threshold = 10 | |
c.acquire() | |
while alive: |
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 | |
import re | |
from itertools import product | |
# bx(n) generates all bit strings with length n | |
bx = lambda x: (('{:0%db}' % x).format(i) for i in xrange(2**x)) | |
# bit8s(s) iterates every 8-bit strings from s | |
bit8s = lambda x: (x[i:i+8] for i in range(0, len(x), 8)) |
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
from itertools import product | |
class ConsoleDisplay(object): | |
def __init__(self, win, rows, cols): | |
win.resize(rows, cols) | |
self._win = win | |
self.rows = rows | |
self.cols = cols |
OlderNewer