Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Lewis mikelikespie

View GitHub Profile
@mikelikespie
mikelikespie / NSData+PIOAdditions.h
Created February 14, 2013 06:35
Zero-Copy bridging between dispatch_data_t and NSData
View NSData+PIOAdditions.h
//
// NSData+PIOAdditions.h
// PonyExpress
//
// Created by Michael Lewis on 2/13/13.
//
//
#import <Foundation/Foundation.h>
@mikelikespie
mikelikespie / nginx.conf
Created December 31, 2011 00:14
using nginx as a websocket reverse proxy
View nginx.conf
location / {
chunked_transfer_encoding off;
proxy_http_version 1.1;
proxy_pass http://localhost:9001;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host:9001;
proxy_set_header Connection "Upgrade";
proxy_set_header Upgrade websocket;
}
@mikelikespie
mikelikespie / colors.js
Created October 22, 2010 23:01
Quick code to convert sRGB to CIE L*a*b* and back.
View colors.js
/*
* To try it:
* c = $c.sRGB8(23,58,32);
* c.Lab();
* c.Lab().sRGB8();
*/
var $c = {};
(
function () {
@mikelikespie
mikelikespie / redis_hot_standby.py
Created March 10, 2011 00:50
A subclass of Redis client redis-py that will deal with hot standbys. Each transaction should WATCH MASSTER_SERVER_KEY and if an exception is raised it should trigger _determine_master
View redis_hot_standby.py
import redis
import time
from contextlib import contextmanager
class _LockFailedError(Exception): pass
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
@mikelikespie
mikelikespie / memoizer.m
Created April 2, 2011 19:08
Fun way to memoize with blocks. It would be sweet if objc had decorators.
View memoizer.m
#define _MEMO(iVarName, block) ^{if (!iVarName) {iVarName = (block)();} return iVarName;}
- (UIButton *)eatCheeseButton;
{
return _MEMO(eatCheeseButton, ^{
return [[UIButton alloc] init];
})();
}
@mikelikespie
mikelikespie / argbase.py
Created July 28, 2012 05:34
Interface for Argparse Similar to Declarative base
View argbase.py
import abc
import re
import argparse
class ArgBaseError(Exception): pass
def _inject_vals(name, bases, dict):
expected_args = {}
@mikelikespie
mikelikespie / graceful_http_server.py
Created March 4, 2011 22:19
Graceful tornado http server shutdown
View graceful_http_server.py
class MyHTTPServer(tornado.httpserver.HTTPServer):
_stopped = False
def _quit_if_ioloop_is_empty(self):
ioloop = tornado.ioloop.IOLoop.instance()
if len(ioloop._handlers) <= 1:
logger.info("Graceful shutdown complete. Exiting!")
exit(0)
else:
logger.info("Waiting for ioloop to be empty. has %d handlers left" % len(ioloop._handlers))
@mikelikespie
mikelikespie / BUILD.RxSwift
Created October 4, 2016 20:30
RxSwift buiild file
View BUILD.RxSwift
objc_library(
name = "RxSwift",
srcs = glob([
"RxSwift/**/*.swift",
]),
clang_module_name = "RxSwift",
enable_modules = True,
visibility = ["//visibility:public"],
)
View Storyboard_DI_Example.swift
/// Does something special that ViewController_A wants
struct Service_A {
func doSomething() {
}
}
/// Does something special that ViewController_B wants
struct Service_B {
func doSomething() {
}
@mikelikespie
mikelikespie / chrome.crashreport
Created October 23, 2012 03:55
Chrome Crashing
View chrome.crashreport
Process: Google Chrome [95295]
Path: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
Identifier: com.google.Chrome
Version: 24.0.1297.0 (1297.0)
Code Type: X86 (Native)
Parent Process: launchd [128]
User ID: 501
Date/Time: 2012-10-22 20:55:37.493 -0700
OS Version: Mac OS X 10.8.2 (12C54)