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
""" | |
usage 'pinhole port host [newport]' | |
Pinhole forwards the port to the host specified. | |
The optional newport parameter may be used to | |
redirect to a different port. | |
eg. pinhole 80 webserver | |
Forward all incoming WWW sessions to webserver. |
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
python -m smtpd -n -c DebuggingServer localhost:1025 |
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
from collections import namedtuple | |
Node = namedtuple('Node', 'value next') | |
class Stack(object): | |
def __init__(self): | |
self.top = None | |
def push(self, value): | |
n = Node(value, self.top) |
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
module.exports = function(grunt) { | |
grunt.initConfig({ | |
html2js: { | |
options: { | |
base: '' | |
}, | |
main: { | |
src: [ 'partials/*.html' ], | |
dest: 'js/templates.js' |
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
numbers = map(int, open("num.txt").readlines()) | |
filtered_list = [] | |
for i in numbers: | |
# Check against last element of last list | |
if filtered_list and filtered_list[-1][-1] < i: | |
# Append element to last list | |
filtered_list[-1].append(i) | |
else: | |
# Create a new list | |
filtered_list.append([i]) |
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 Photo(models.Model): | |
photo = models.ImageField(upload_to='photos') | |
@set_attributes(short_description='Image', allow_tags=True) | |
def image_tag(self): | |
if not self.photo: | |
return u'' | |
return u'<img width="100" src="/media/%s" />' % self.photo |
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
U+2713 ✓ check mark | |
U+2714 ✔ heavy check mark | |
U+2717 ✗ | |
U+2718 ✘ |
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 socket | |
if __name__ == "__main__": | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect(("localhost", 9012)) | |
data = "some data" | |
sock.sendall(data) | |
result = sock.recv(1024) | |
print result | |
sock.close() |
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
from contextlib import contextmanager | |
@contextmanager | |
def switch(value): | |
yield Case(value) | |
class Case(object): | |
def __init__(self, value): | |
self.value = value | |
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 <Python.h> | |
static PyObject* say_hello(PyObject* self, PyObject* args) | |
{ | |
const char* name; | |
if (!PyArg_ParseTuple(args, "s", &name)) | |
return NULL; | |
printf("Hello %s!\n", name); |