Skip to content

Instantly share code, notes, and snippets.

View SegFaultAX's full-sized avatar

Michael-Keith Bernard SegFaultAX

View GitHub Profile
@SegFaultAX
SegFaultAX / gist:9303938
Last active August 29, 2015 13:56
functional.js
function argList(args) {
return Array.prototype.slice.call(args);
}
function reduce0(fn, l, init) {
for(var i = 0; i < l.length; i++) {
init = fn(init, l[i]);
}
return init;
}
@SegFaultAX
SegFaultAX / Function.java
Last active March 23, 2022 05:14
Functional programming Java
package com.segfaultax;
public interface Function<Param, Result> {
public Result apply(Param in);
}
@SegFaultAX
SegFaultAX / gist:9493633
Last active November 9, 2015 14:42
Pivotal Changelog (from git)
#!/usr/bin/env python
# Copyright (c) 2014 Michael-Keith Bernard
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
@SegFaultAX
SegFaultAX / gist:9615203
Created March 18, 2014 07:34
processing.js - simple grid test
"use strict";
var H_PADDING = 10;
var V_PADDING = 10;
var ROWS = 20, COLUMNS = 20;
function app(processing) {
var midX, midY, colWidth, rowHeight;
var colors = {
@SegFaultAX
SegFaultAX / gist:9615583
Created March 18, 2014 08:10
Functional sets in Javascript
function empty() {
return function() {
return false;
};
}
function singleton(e0) {
return function(e) {
return e0 === e;
};
@SegFaultAX
SegFaultAX / gist:9732254
Last active August 29, 2015 13:57
Almost snake.js...
"use strict";
var H_PADDING = 10;
var V_PADDING = 10;
var ROWS = 20,
COLUMNS = 20;
var KEYCODES = {
37: "left",
38: "up",
@SegFaultAX
SegFaultAX / gist:9826029
Created March 28, 2014 05:32
Force Omegle to only search for interests
window.COMETBackend.prototype.stopLookingForCommonLikes = function(){};
#!/usr/bin/env python
import sys
import yaml
import json
def convert(data):
y = yaml.load(data)
return json.dumps(y,
indent=4,
@SegFaultAX
SegFaultAX / gist:10507478
Last active August 22, 2021 02:40
Dotted path expansion for Python dictionary keys
import operator
from pprint import pprint
def is_dict(d):
return isinstance(d, dict)
def get(c, k, default=None):
try:
return c[k]
except (IndexError, KeyError, TypeError):
@SegFaultAX
SegFaultAX / gist:10921677
Last active August 29, 2015 13:59
General purpose tuple parser for Python
from decimal import Decimal
def _wrap_converter(fn):
def _wrapper(elem):
try:
return fn(elem)
except Exception as e:
msg = "Failed to convert value {0}: {1}".format(
elem, e)
raise ValueError(msg)