Skip to content

Instantly share code, notes, and snippets.

View oz123's full-sized avatar
🎯
Focusing

Oz Tiram oz123

🎯
Focusing
View GitHub Profile
from os import urandom
def random_id():
"""Returns a 20-character random identifier."""
return urandom(15).encode("base64")[:-1]
def parse_cookie(environ):
"""Returns the cookie from the given WSGI environ as dict."""
s = environ.get('HTTP_COOKIE', '')
return dict(map(str.strip, elt.split("=")) for elt in s.split(";")) if s else {}
import argparse
from mock import Mock
m = Mock()
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
query_group = subparsers.add_parser('query')
add_group = subparsers.add_parser('add')
@nitrogenlogic
nitrogenlogic / 00_popen3_moved.md
Last active March 7, 2025 10:07
Two implementations of a popen3() function in POSIX/C providing stdin, stdout, and stderr
@mxswd
mxswd / classdiagram.gv
Created September 21, 2011 01:13
Class Diagram / ERD Graphviz example. Compile with `dot -Tpdf diagram.gv > diagram.pdf`
digraph models_diagram {
graph[overlap=false, splines=true]
"Venue" [shape=record, label="{\
Venue|name :string\l\
}"]
"User" [shape=record, label="{User|\
email :string\l\
password :string\l\
}"]
@j0hn
j0hn / login.py
Created October 4, 2011 03:13
GTK unittest example
#!/usr/bin/env python
# coding: utf-8
import gtk
class LoginWindow(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
self.connect("destroy", gtk.main_quit)
@turicas
turicas / email_utils.py
Last active May 4, 2025 16:44
Send emails easily in Python (with attachments and multipart)
#!/usr/bin/env python
# coding: utf-8
# This little project is hosted at: <https://gist.github.com/1455741>
# Copyright 2011-2020 Álvaro Justen [alvarojusten at gmail dot com]
# License: GPL <http://www.gnu.org/copyleft/gpl.html>
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
@datagrok
datagrok / gist:2199506
Last active December 16, 2024 16:14
Virtualenv's `bin/activate` is Doing It Wrong
@thanos
thanos / kombu_example.py
Created June 14, 2012 23:15
A simple example of a kombu fanout exchange using python generators and coroutines
from kombu import Exchange
from kombu import Queue
from kombu import BrokerConnection
class ProduceConsume(object):
def __init__(self, exchange_name, **options):
exchange = Exchange(exchange_name, type='fanout', durable=False)
queue_name = options.get('queue', exchange_name+'_queue')
self.queue = Queue(queue_name ,exchange)
@sunix
sunix / scantofile.sh
Created August 5, 2012 08:49
My Brother brscan scanner S-KEY tool scan to file script. Scan from ADF, convert to PDF and merge PDFs files into a single one.
#! /bin/sh
set +o noclobber
#
# $1 = scanner device
# $2 = friendly name
#
#
# 100,200,300,400,600
#
@richard-flosi
richard-flosi / bottle-cors.py
Created September 26, 2012 16:55
Bottle with Cross-origin resource sharing (CORS)
"""
Example of setting up CORS with Bottle.py.
"""
from bottle import Bottle, request, response, run
app = Bottle()
@app.hook('after_request')
def enable_cors():
"""