Skip to content

Instantly share code, notes, and snippets.

View jasonmoo's full-sized avatar

Jason Mooberry jasonmoo

View GitHub Profile
@jasonmoo
jasonmoo / PHPFPM.Portfile
Created December 1, 2010 23:31
PHP 5.3.3 MacPorts Portfile with FPM enabled FastCGI variant
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 71588 2010-09-17 05:21:24Z ryandesign@macports.org $
PortSystem 1.0
name php5
conflicts php5-devel php52
# Update revision of php5-eaccelerator when updating version of php5
epoch 1
version 5.3.3
@jasonmoo
jasonmoo / hghookscript.pl
Created January 13, 2011 23:08
A perl script for hooking into a Mercurial hook event. -In it's current form it will make a backup, convert indenting to tabs, and lint check php files. -Allows for anonymous subs to be passed as adhoc filters.
###
### HG Hook script
### - allows filtering and other actions to be
### run at a designated hook.
###
# a copy of each file along with it's directory structure
# is placed here when the script is initially run.
$BACKUP_DIR = "~/_hg_modified";
@jasonmoo
jasonmoo / client.go
Created October 15, 2012 18:32
Go rpc client over tcp
package main
import (
"log"
"net"
"net/rpc"
"sync"
"time"
)
@jasonmoo
jasonmoo / server.go
Created October 15, 2012 18:33
Go rpc server over tcp
package main
import (
"log"
"net"
"net/rpc"
)
type System int
@jasonmoo
jasonmoo / gist:5491260
Last active December 16, 2015 20:19
some bash profile shorties to make golangin easier...
function cd() {
builtin cd $@
if [[ -e .goenv ]]; then
source .goenv
fi
}
function gengo() {
local project=${1?:"Usage: gengo <projectname> [<git origin url>]"}
[ ! -d "$project" ] && mkdir "$project" && builtin cd "$project" && mkdir -p src bin pkg &&
function ctx_to_object_url(ctx) {
var img_bytes = atob(ctx.canvas.toDataURL().substring('data:image/png;base64,'.length)),
ua = new Uint8Array(new ArrayBuffer(img_bytes.length));
for (var i = 0; i <= ua.length; i++) {
ua[i] = img_bytes.charCodeAt(i);
}
return (window.URL || window.webkitURL).createObjectURL(new Blob([ua], { type: 'image/png' }));
function generate_dom(string) {
var t = document.createElement('div');
t.innerHTML = string;
return t.children.length === 1 ? t.children[0] : t.children;
}
@jasonmoo
jasonmoo / Phil
Created January 4, 2014 23:07
recursive fill function
function fill(x,y) {
if (c.getImageData(x,y, 1,1).data[0] !== 0) {
c.fillRect(x,y, 1,1);
fill(x-1, y-1); fill(x, y-1); fill(x+1, y-1);
fill(x-1, y); /* current */ fill(x+1, y);
fill(x-1, y+1); fill(x, y+1); fill(x+1, y+1);
}
}
@jasonmoo
jasonmoo / gist:8464983
Created January 16, 2014 22:46
get a github repo
function gethub() {
cd ~/Code
if [[ ! -d "$1" ]]; then
git clone git@github.com:$1 "$1"
fi
cd "$1" && sub .
}
@jasonmoo
jasonmoo / int_to_constants.php
Last active January 3, 2016 15:19
convert integer http status codes in WriteHeader to http.Status* constants
<?php
// w.WriteHeader(200) -> w.WriteHeader(http.StatusOK) // 200
array_map(function($a) {
$data = file_get_contents($a);
$data = preg_replace_callback("/\.WriteHeader\((\d+)\)/", function($d) {
static $constants = array(
100 => 'http.StatusContinue',
101 => 'http.StatusSwitchingProtocols',