Skip to content

Instantly share code, notes, and snippets.

"""
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.
@bulv1ne
bulv1ne / debug.sh
Last active August 29, 2015 14:00
Debugging smtpd
python -m smtpd -n -c DebuggingServer localhost:1025
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)
@bulv1ne
bulv1ne / Gruntfile.js
Created April 16, 2014 14:33
angular html2js grunt
module.exports = function(grunt) {
grunt.initConfig({
html2js: {
options: {
base: ''
},
main: {
src: [ 'partials/*.html' ],
dest: 'js/templates.js'
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])
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
@bulv1ne
bulv1ne / marks
Created February 13, 2014 07:21
Checkmarks
U+2713 ✓ check mark
U+2714 ✔ heavy check mark
U+2717 ✗
U+2718 ✘
@bulv1ne
bulv1ne / client.py
Last active January 1, 2016 20:09
Server/Client using multiprocessing.Pool
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()
from contextlib import contextmanager
@contextmanager
def switch(value):
yield Case(value)
class Case(object):
def __init__(self, value):
self.value = value
@bulv1ne
bulv1ne / hellomodule.c
Created December 4, 2013 14:18
Extening Python with C
#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);