Skip to content

Instantly share code, notes, and snippets.

@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,
@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 / 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 / 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 / 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]
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 / 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
def retry_on_connection_error(retries=2, sleep=0.1):
""" Retries on Autoreconnect errors. Wrap functions you want to ensure they
retry if there's a connection failure, giving the chance to mongo to failover.
params:
retries: the number of retries
sleep: seconds to sleep between retries
>>> @retry_on_connection_error(retries=1)
... def super_sensitive_function(data=2)
Avocarrot.config({
auth: 'api_key',
api_key: '1234'
});
Avocarrot.getRandomReward(function(err, reward) {
// todo
});
@alexmic
alexmic / hackcyprus.md
Created March 11, 2013 12:00
Hack Cyprus

What is Hack Cyprus

Hack Cyprus aspires to start a much-lacking innovation wave in Cyprus by bringing programmers, designers and technologists together. It is mainly represented by a Facebook group with ~400 members which ignites interesting discussions around technology on a daily basis and serves as a mechanism for people to find talent or projects to work on.

Hackathons

Hackathons are a central part of the culture embodied in Hack Cyprus. We believe that such events are ideal for creating environments where ideation and creation can thrive. Our first hackathon, and indeed the first ever in Cyprus, took place in September 2012 at the Cyprus University of Technology. The event amassed more than 70 participants with more than 10 teams presenting their projects in the end. Given the current situation with technology in Cyprus, we consider this to be a big win.