Skip to content

Instantly share code, notes, and snippets.

View gregtatum's full-sized avatar

Greg Tatum gregtatum

View GitHub Profile
@gregtatum
gregtatum / 1-script.js
Last active August 29, 2015 14:14
JS1k 2015 - Hype Train
w=b.offsetWidth
h=b.offsetHeight
wh=Math.sqrt(w*w+h*h)
s=b.style
s.background='#222'
q=Math.random
n=30
i=n
r=[] //rectangles
@gregtatum
gregtatum / car.js
Last active August 29, 2015 14:15
Module Pattern - Killing this
var internals = {
revEngine : function rev( state, engine ) {
state.timesRevved++
switch( engine ) {
case "v8":
console.log("vrooooooooom!")
break
@gregtatum
gregtatum / e.js
Last active August 29, 2015 14:16
Calculate e constant
var e = function( iterations ) {
var aggregator = 1
for( var i=1; i < iterations; i++ ) {
var value=1;
for( var j=2; j <= i; j++ ) {
value *= 1 / j
@gregtatum
gregtatum / sine.js
Created March 4, 2015 21:22
Sine wave in the URL bar
//Copy/paste into your console
(function() {
var t = 0
var values = []
var msg = []
function loop() {
t++
@gregtatum
gregtatum / arrow.js
Last active August 29, 2015 14:16
State and config in a function
function logger( state, msg ) {
state.count++
console.log( state.count, this.msg )
}
var log = () => logger( {count:0}, "Calling from an arrow function" )
log()
log()
log()
@gregtatum
gregtatum / automatic semicolon insertion.md
Last active August 29, 2015 14:16
What led me to use automatic semi-colon insertion

What led me to use automatic semi-colon insertion (aside from not having to hit the semi-colon button);

function createNamedObject( fn, obj ) {
return _.extend(new fn(), obj)
}
var api = {
get: function() {},
set: function() {},
save: function() {}
}
@gregtatum
gregtatum / gif.sh
Created April 23, 2015 21:07
gif.sh
#Run: gif.sh file.mov 320
#Outputs a file.gif at 320px wide
OUT=$(echo $1 | sed -e 's/\.[a-zA-Z0-9]*$/.gif/')
ffmpeg -i "$1" -vf scale=${2:-640}:-1 -r 30 -f image2pipe -vcodec ppm - | convert -delay 5 -layers Optimize -loop 0 - "$OUT"
//Use gl.POINTS to draw a dot
uniform vec3 color;
void main() {
// Map ( [0,0] , [1,1] ) => ( [-1,-1], [1,1] )
vec2 coord = ( gl_PointCoord - vec2(0.5, 0.5) ) * 2.0;
// Step it so that it's a hard transition
@gregtatum
gregtatum / 01-WP_Query.md
Last active August 29, 2015 14:23
WP_Query.md

WP_Query

WP_Query is the best way to grab posts in Wordpress, and it's a beast to configure. I created a few snippets in my text editor to help me create them quickly without having to navigate the difficult to read documentation. I've shared them here.