Instantly share code, notes, and snippets.

@enricofoltran
enricofoltran / main.go
Last active Feb 21, 2019
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
View main.go
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@dabeaz
dabeaz / aecho.py
Last active Oct 28, 2018
Live-coded examples from my PyCon Brasil 2015 Keynote
View aecho.py
# aecho.py
from socket import *
import asyncio
loop = asyncio.get_event_loop()
async def echo_server(address):
sock = socket(AF_INET, SOCK_STREAM)
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
@ipmb
ipmb / ratelimit.nginxconf
Last active Feb 20, 2019
Nginx reverse proxy with rate limiting
View ratelimit.nginxconf
upstream myapp {
server 127.0.0.1:8081;
}
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
server {
listen 443 ssl spdy;
server_name _;
View sqlalchemy-query-stats.py
from sqlalchemy import engine
from sqlalchemy import event
class DbStats():
def __init__(self):
self.clear()
def clear(self):
self.total_queries = 0
self.total_time = 0
@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active Feb 19, 2019
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!
View whiteboardCleaner.md

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

@georgepsarakis
georgepsarakis / extended-list.py
Created Dec 12, 2013
Extended list. Maintains a dictionary for faster lookups (optionally keeps hash of item object representation by marshalling) and with some operator overloading can perform mathematical operations among instances.
View extended-list.py
from collections import MutableSequence
import marshal
from operator import add, div, mul, neg, mod, sub
from operator import ge, gt, le, lt, eq
from itertools import imap
'''
Extended list class
- fast lookups by maintaining a dictionary with the values
- numeric operations between 2 instances are possible (like Octave matrices)
@randyzwitch
randyzwitch / ipython-notebook-ec2.py
Created Nov 21, 2013
Setting up IPython Notebook as a remote server
View ipython-notebook-ec2.py
#### Start IPython, generate SHA1 password to use for IPython Notebook server
$ ipython
Python 2.7.5 |Anaconda 1.8.0 (x86_64)| (default, Oct 24 2013, 07:02:20)
Type "copyright", "credits" or "license" for more information.
IPython 1.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
@georgepsarakis
georgepsarakis / cli.py
Last active Dec 28, 2015
REPL-CLI boilerplate for simple DSLs with built-in help, autocomplete (like Redis-CLI)
View cli.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import argparse
import readline
import rlcompleter
import shlex
import os
import re
try:
@georgepsarakis
georgepsarakis / python-mr.py
Last active Nov 12, 2018
Python MapReduce (itertools, multiprocessing)
View python-mr.py
#!/usr/bin/env python
import os
import itertools
import multiprocessing as mp
from math import ceil
from types import GeneratorType as generator
from functools import partial
from time import time