Skip to content

Instantly share code, notes, and snippets.

View jasonmoo's full-sized avatar

Jason Mooberry jasonmoo

View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX_MESSAGE_LENGTH 1024
int main(int argc, char* argv[]) {
if (argc != 2) {
function mitigated_event(f, t) {
var timeout;
return function(e) {
clearTimeout(timeout);
timeout = setTimeout(function() { f(e); }, t);
};
}
@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',
@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 / 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);
}
}
function generate_dom(string) {
var t = document.createElement('div');
t.innerHTML = string;
return t.children.length === 1 ? t.children[0] : t.children;
}
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' }));
@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 &&
@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 / client.go
Created October 15, 2012 18:32
Go rpc client over tcp
package main
import (
"log"
"net"
"net/rpc"
"sync"
"time"
)