Skip to content

Instantly share code, notes, and snippets.

View mrspeaker's full-sized avatar

Mr Speaker mrspeaker

View GitHub Profile
@mrspeaker
mrspeaker / vispromise.js
Created May 8, 2015 16:14
Vis promises
$.when(
createBaseCharts('.tile-area')
.then(createTicks),
fetchTalkContentData()
.then(parseTalkContentData)
)
.then((charts, data) => {
fadeUnnecessaryTicks(charts)
.then(addWordDensityBubbles)
.then(addCursor)
[10, 2, 1, 4, 5, 33].forEach(n => setTimeout(() => console.log(n), n));
@mrspeaker
mrspeaker / fixQuads.py
Created April 29, 2015 20:58
fixQuads.py: blender script to fix Kenney's 3D objects for Three.js
import glob
import bpy
# Fix Kenney's 3D objects (http://kenney.itch.io/kenney-donation) in Three.js
# Three.js' object loader barfs when object is not made of simple quads.
# This script uses Blender command-line to load each asset, converts to tris,
# then convert to quads (to remove some vertices), and re-saves (overwrites!)
# To run:
@mrspeaker
mrspeaker / gist:324a7512755e7b32fa7f
Created April 3, 2015 21:12
get youtube vid lengths with jquery promises
//Getting length of the youtube vids...
$('#yt_player_container').on("onPlayerReady", (msg) => {
$.when().then(delay(1000)).then(() => {
_.toArray(window.talk_metadata)
.reduce((seq, talk) => seq.then(() => {
return new Promise((res, rej) => {
const cb = ({event}) => {
if (event == YT.PlayerState.PLAYING) {
stopVideo();
@mrspeaker
mrspeaker / val.js
Last active August 29, 2015 14:18
JS immutable identifier binding
/*
A sweet.js macro for adding a JS identifier
binding (`val`) that is the same as a `const` declaration,
that is then frozen with `Object.freeze`.
*/
'use strict';
macro val {
rule {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = 300;
canvas.height = 300;
document.body.appendChild(canvas);
ctx.fillStyle = "#000";
ctx.fillRect(0, 0, canvas.width, canvas.height);
@mrspeaker
mrspeaker / immutableParams
Created March 7, 2015 20:46
Immutable parameters in ES6?
// Is there a way to define immutable parameters in ES6?
const inc = x => {
x++; // Oh no, you modified x!
return x;
}
// Is it better to reassign to const (if it should be constant, of course)?
const inc = x => {
@mrspeaker
mrspeaker / openTermToPath
Created February 21, 2015 17:13
Open iTerm at folder or file path
on run {input, parameters}
tell application "iTerm"
create window with default profile
tell current window
tell current session
set firstInput to (first item of input)
set fullPath to (firstInput as text)
@mrspeaker
mrspeaker / Avg Ping Time
Created December 2, 2014 22:09
Save average ping times
#!/bin/sh
FN="tweetPing$(date +"%T" | sed 's/://g').txt"
echo $FN
while true
do
TIME=$(date +"%T")
# Ping returns:
@mrspeaker
mrspeaker / pinwheel.glsl
Created May 23, 2014 21:56 — forked from glslioadmin/TEMPLATE.glsl
GLSL.io Transition (v1)
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D from, to;
uniform float progress;
uniform vec2 resolution;
void main() {
vec2 p = gl_FragCoord.xy / resolution.xy;