Skip to content

Instantly share code, notes, and snippets.

@qwtel
qwtel / WebGLRenderingContext.js
Last active August 29, 2015 14:03
Outline and JSDoc of the WebGLRenderingContext. Based on the WebGL 1.0 API Quick Reference Card http://www.khronos.org/files/webgl/webgl-reference-card-1_0.pdf. Can be used for autocompletion in WebStorm / IntelliJ.
/**
* @constructor
*/
function WebGLRenderingContext() {
}
WebGLRenderingContext.prototype = {
ACTIVE_ATTRIBUTES: 35721,
ACTIVE_TEXTURE: 34016,
ACTIVE_UNIFORMS: 35718,
define([
'promise'
], function (Promise) {
/**
* @param urlWithoutExtension {String} - the path to the sound file without a particular extension.
* @param audioContext {AudioContext} - the audio context of the sound file, used for decoding.
* @returns {Promise} - a promise containing the decoded audio data.
*/
function getSoundBuffer(urlWithoutExtension, audioContext) {
trtht (tritheite)
jwstn (Jewstone)
hwkng (hawking)
plrdr (Pleurodira, pleurodire)
drsnz (deresinize)
nlwry (inlawry)
nrckn (unreckon)
bdlmc (Bedlamic)
mrmps (Mormoops)
clvry (Calvary, clovery)
(ns usrnames)
(require '[clojure.string :as str])
(def file (slurp "/usr/share/dict/words" :encoding "ASCII"))
(def words (str/split-lines file))
(defn remove-vowels [word]
(->>
word
(ns markov-usrnames)
(require '[clojure.string :as str])
(def file (slurp "/usr/share/dict/words" :encoding "ASCII"))
(def words (str/split-lines file))
(defn generate-markov-nodes
[words]
(->>
@qwtel
qwtel / connectContext.js
Last active September 17, 2015 16:34
Enhanced version of redux' connect, that puts all action creators into the child context of the component.
import {PropTypes} from 'react';
import {connect} from 'react-redux';
/**
* Enhanced version of redux' connect, that puts all action creators
* into the child context of the component.
*
* @param mapStateToProps {Function}
* @param mapDispatchToProps {Function} Must be free of side effects!
* @returns {Function}
@qwtel
qwtel / clojure.js
Last active September 29, 2015 09:46
If JavaScript was written like Clojure...
function cost(state) {
return mul(
b,
Math.log(
reduce(
add,
map(
function(x) {return Math.pow(Math.E, div(x, b))},
vals(x)))))}
(defn generate-markov-nodes
[words]
(->>
words
(map str/lower-case)
(str/join " ")
(partition 3 1)
(map #(list (take 2 %1) (nth %1 2)))
(reduce
(fn [acc [l next-l]] (update-in acc [l next-l] (fnil inc 0)))
@qwtel
qwtel / separator.cljc
Last active December 7, 2015 11:54
Valid Clojure
(defn <> [] <>)
(((((((((((((((((((((((((((((((((((((((<>)))))))))))))))))))))))))))))))))))))))
class BresenhamLineDrawer implements LineDrawer {
private PixelSetter buffer;
public BresenhamLineDrawer(PixelSetter buffer) {
this.buffer = buffer;
}
@Override
public void drawLine(int x1, int y1, int x2, int y2) {
int deltaX = Math.abs(x2 - x1);
int deltaY = Math.abs(y2 - y1);