Skip to content

Instantly share code, notes, and snippets.

@weisjohn
weisjohn / test.sh
Created May 15, 2014
PhantomJS JSON.parse() fails on array
View test.sh
$ phantomjs
phantomjs> a = '[{"foo":"bar"},{"foo":"cat"}]'
"[{\"foo\":\"bar\"},{\"foo\":\"cat\"}]"
phantomjs> JSON.parse(a)
{
"0": {
"foo": "bar"
},
"1": {
View keybase.md

Keybase proof

I hereby claim:

  • I am weisjohn on github.
  • I am weisjohn (https://keybase.io/weisjohn) on keybase.
  • I have a public key whose fingerprint is 1499 7B49 6AD9 35B2 AF3D 2780 A5B1 A295 C05D CF30

To claim this, I am signing this object:

@weisjohn
weisjohn / get.js
Created Jan 9, 2014
a simple err-first callback function to make a GET request with jQuery, XHR, or Node.js
View get.js
function get(url, cb) {
// use jQuery if you can, if not, XHR, or try to node
if (typeof $ !== "undefined" && !!$().jquery) {
$.ajax(url).then(function(data) {
cb(null, data);
}, function(j, t, e) {
cb(e);
});
} else if (typeof XMLHttpRequest !== "undefined") {
// simple XHR attempt
@weisjohn
weisjohn / README.md
Last active Jan 1, 2016
how to turn a keyframe animation into an animated png using phantomjs, imagemagick, and apngasm
View README.md

jumping through hoops

A wonderfully warm winter day. Everything was perfect. Lofty visions of CSS3 animations dazzled my eyes. Nay, what's this? A browser from years ago appears. What's that you say? It doesn't support keyframes? Ghast. Make an animated gif! Oh, wait, we need transparency? Make an animated png!

This is the final outcome (sans history) of half a day spent to ensure experience parity on a super old (Opera 9.8) browser that we absolutely have to support.

It took hours, and it wasn't probably worth it, but I learned so much, and in the end it works pretty well.

technique

View CertificateGeneration.sh
###
#Step 1 - Generate server certificates etc... (most of this code is horribly ripped off from nodejs docs currently -> http://nodejs.org/docs/latest/api/tls.html)
###
#Assuming your starting from a clean directory
mkdir server
cd server
#generate private key
View brode.js
var chirp = require('twitter')
, _ = require('lodash') // cause underscore is so 2009..
;
module.exports = function(app) {
// bro shortcuts for getting the tweets
app.get('/mah/chirps', function(req, res) {
// closures, like a pro javascript dude
function hollaback(fail, party) {
@weisjohn
weisjohn / ga-part.js
Created Sep 5, 2013
Google Analytics beforeunload inpsection
View ga-part.js
// this code isn't intended to work:
if (J.body) {
a = aa(a);
try {
var c = J[qa]('<iframe name="' + a + '"></iframe>')
} catch (d) {
c = J[qa]("iframe"), ha(c, a)
}
c.height = "0";
View rotate_logs.sh
#!/bin/bash
# rotates logs for all services on this box
# the services for which we should rotate logs
SERVICE_DIR=~/mysrc
services=$(ls $SERVICE_DIR)
function rotate {
logfile=$SERVICE_DIR/$1/logs/$2.log
@weisjohn
weisjohn / gist:5861939
Created Jun 25, 2013
rwd iframes bookmarklet
View gist:5861939
javascript:document.write('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Responsive Design Testing</title><style>body %7B margin: 20px; font-family: sans-serif; overflow-x: scroll; %7D.wrapper %7B width: 6000px; %7D.frame %7B float: left; %7Dh2 %7B margin: 0 0 5px 0; %7Diframe %7B margin: 0 20px 20px 0; border: 1px solid %23666; %7D</style></head><body><div class="wrapper"><div class="frame"><h2>240<span> x 320</span> <small>(mobile)</small></h2><iframe src="' + window.location + '" sandbox="allow-same-origin allow-forms" seamless width="240" height="320"></iframe></div><div class="frame"><h2>320<span> x 480</span> <small>(mobile)</small></h2><iframe src="' + window.location + '" sandbox="allow-same-origin allow-forms" seamless width="320" height="480"></iframe></div><div class="frame"><h2>480<span> x 640</span> <small>(small tablet)</small></h2><iframe src="' + window.location + '" sandbox="allow-same-origin allow-forms" seamless width="480" height="640"></iframe></div><div class="frame"><h2>768<sp
@weisjohn
weisjohn / postponed.js
Created Jun 21, 2013
an example of variable delays in event handlers
View postponed.js
// how long should we wait for a function to fire?
var delay = 0;
// a simple way to wrap functions to be delayed
function postponed(fn) {
return function() {
setTimeout(fn, delay);
}
}
You can’t perform that action at this time.