Skip to content

Instantly share code, notes, and snippets.

@alexmic
alexmic / gist:4050955
Created November 10, 2012 12:33
ssh daemon listen to port 443 on EC2
#!/bin/bash -ex
perl -pi -e 's/^#?Port 22$/Port 443/' /etc/ssh/sshd_config
service sshd restart || service ssh restart
from datetime import datetime
import math
def friendly_ago_string(d):
"""
Returns a friendly string like "8 minutes ago" representing the
differences between now and d.
"""
if not d or not isinstance(d, datetime):
return None
@alexmic
alexmic / mtmap_usage.py
Created March 2, 2012 00:30
Using mtmap()
def worker(n):
return n**2
squared = mtmap(worker, [2, 3, 4, 5])
#= [4, 9, 16, 25]
@alexmic
alexmic / mtmap.py
Created March 2, 2012 00:26
Multi-threaded map()
def mtmap(fn, iterable):
""" A multi-threaded map(). Must be used with care - large
iterables might cause a machine to crash from too many
threads. If an exception is thrown in a thread,
the iteration stops and that exception is thrown.
"""
result = {}
threads = []
exception_q = Queue.Queue()
@alexmic
alexmic / gist:1223918
Created September 17, 2011 13:00
FB Login
/**
* @fileOverview Signup page JS code.
* @author <a href="mailto:hi@alexmic.com"> Alex Michael </a>
* @requires PK.js, facebox.js
*/
PK.onPageLoad(function(){
// Once the register page is loaded, make
// a request to FB and fill in user fields.
@alexmic
alexmic / gist:1223906
Last active September 27, 2015 06:08
Python Upload
#!/usr/bin/env python
import string
import os
import uuid
import mimetypes
class Uploader:
def __init__(self, request = None):
@alexmic
alexmic / example.py
Last active August 29, 2015 13:56
Sketch for how I'd like a simple REST service framework to work
from swiss import Api
from swiss.resources import Resource, Group
from swiss.auth import BasicAuth, noauth
from swiss.fields import parse, serialize, parselize
from swiss.fields import String, Int, Boolean
# simple dicts for schemas and serialization
schema = {
'name': String,