Skip to content

Instantly share code, notes, and snippets.

View aboekhoff's full-sized avatar

Andrew Boekhoff aboekhoff

  • DemandingBear
  • San Francisco
View GitHub Profile
// allows any component to respond to keyboard events
// currently only keydown but could be any depending on requirements
export default function keyboardable(WrappedComponent) {
class KeyboardableComponent extends WrappedComponent {
keyboardableOnKeyUp = (e) => {
this.onKeyUp(e)
}
onKeyUp(e) {
export function withWindowEvents(events) {
return function withWindowEventsFactory(Component) {
return class WithWindowEvents extends Component {
componentDidMount(...args) {
Object.keys(events).forEach(event => {
window.addEventListener(event, events[event])
})
super(...args)
}
import { getAccessToken } from './session';
// quick and dirty serializer
function serializeObjectToQueryString(obj) {
if (!obj) { return ""; }
const str = [];
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
str.push(encodeURIComponent(prop) + "=" + encodeURIComponent(obj[prop]));
const h1 = {
a: {
b: {
c: {
foo: "bar"
}
}
}
}
;; SFML/System.h
;; ////////////////////////////////////////////////////////////
;; #ifndef SFML_SYSTEM_H
;; #define SFML_SYSTEM_H
;; ////////////////////////////////////////////////////////////
;; // Headers
;; ////////////////////////////////////////////////////////////
;;;; structural types + pattern matching in Clojure
;;;; with the obligatory unbalanced binary tree example
(define-struct leaf value)
(define-struct node left elt right)
(define insert
nil x -> (leaf x)
(leaf a) x -> (cond (or (nil? a) (= a x)) (leaf a)
(< x a) (node (leaf x) a nil)
;;;; red-black-trees, based on the Functional Pearls article:
;;;; 'Red-Black Trees in a Functional Setting' by Chris Okasaki, 1993
(define-type R | B) ;; red black
(define-type T color left elt right) ;; tree
(define rbt:insert
x t -> (match (rbt:insert* x t)
(T _ a y b) -> (T B a y b)))
;;;; pairs
(define-type Pair a b)
(define-type Empty)
(define Pair:foldl
f x (Pair a b) -> (foldl f (f x a) b))
(define Pair:first
(Pair a _) -> (Some a))
space_283 = (function (ST_729) {
var rtn734_, v_440_;
v_440_ = re_267("\\s");
rtn734_ = v_440_(ST_729);
return rtn734_;
});
spaces_284 = (function (ST_730) {
var v_441_, rtn735_;
v_441_ = many_261(space_283);
rtn735_ = v_441_(ST_730);
(ns poet.prelude)
(def prelude
'[(syntax-rule if ()
(_ X Y Z) (if* (op* === X true) Y
(if* (op* === X false) Z
(throw "if requires a boolean value"))))
(syntax-rule if-not ()
(_ X Y Z) (if X Z Y))