This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const h1 = { | |
a: { | |
b: { | |
c: { | |
foo: "bar" | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; SFML/System.h | |
;; //////////////////////////////////////////////////////////// | |
;; #ifndef SFML_SYSTEM_H | |
;; #define SFML_SYSTEM_H | |
;; //////////////////////////////////////////////////////////// | |
;; // Headers | |
;; //////////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; 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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
NewerOlder