Skip to content

Instantly share code, notes, and snippets.

View cvan's full-sized avatar
🚌
🌊

Christopher Van cvan

🚌
🌊
View GitHub Profile
@cvan
cvan / snoopy.js
Created January 29, 2014 21:30
record user's history
/*
1. Install dotjs (https://addons.mozilla.org/en-US/firefox/addon/dotjs/ for Firefox or https://github.com/defunkt/dotjs for Chrome)
2. Put the contents of this file at ~/.js/default.js
*/
const API_URL = 'http://localhost:7000/';
function getData(e, comment) {
.throbber {
animation(unquote('.9s spin infinite steps(30)'));
border: 4px solid cyan;
border-left-color: transparent;
border-radius: 150px;
border-top-color: transparent;
bottom: 0;
display: block;
height: 33px;
left: 0;
@cvan
cvan / throbber.css
Created January 30, 2014 23:52
CSS throbber
/*
Usage:
<div class="throbber"><b></b><b></b><b></b></div>
*/
.throbber {
position: absolute;
@cvan
cvan / post.js
Created February 5, 2014 00:33
promise-based, jQuery-like $.post XHR wrapper
function reqResponse(xhr) {
var data = xhr.responseText;
if ((xhr.getResponseHeader('Content-Type') || '').split(';', 1)[0].indexOf('json') !== -1) {
try {
return JSON.parse(data);
} catch(e) {
// Oh well.
return {};
}
}
@cvan
cvan / delegate.js
Last active August 29, 2015 13:56
$ event delegation
function $(sel) {
if (!sel) {
return $.body;
}
var r = document.querySelectorAll(sel);
return r.length == 1 ? r[0] : Array.prototype.slice.call(r);
}
$.doc = document;
$.body = document.body;
@cvan
cvan / install-slimerjs-casperjs.bash
Created February 19, 2014 18:34
install slimerjs and casperjs
#!/usr/bin/env bash
pushd lib/packages
if [ -e "slimerjs" ]
then
echo "Directory 'slimerjs' exists"
else
echo "Creating 'slimerjs' directory"
mkdir slimerjs
@cvan
cvan / install-slimerjs-linux.bash
Created February 27, 2014 00:01
install headless slimerjs (headless gecko) on linux
#!/usr/bin/env bash
sudo apt-get update
sudo apt-get install xvfb
curl -k -O http://download.slimerjs.org/v0.9/0.9.0/slimerjs-0.9.0-linux-x86_64.tar.bz2
tar -xjpvf slimerjs-0.9.0-linux-x86_64.tar.bz2
rm slimerjs-0.9.0-linux-x86_64.tar.bz2
mv slimerjs-0.9.0 slimerjs
echo "console.log('SlimerJS installed OK'); slimer.exit();" > test.js
sudo xvfb-run slimerjs/slimerjs test.js
@cvan
cvan / requests.js
Created March 10, 2014 21:44
patched requests.js for headers
diff --git a/hearth/media/js/requests.js b/hearth/media/js/requests.js
index a959070..f6f6743 100644
--- a/hearth/media/js/requests.js
+++ b/hearth/media/js/requests.js
@@ -26,7 +26,7 @@ define('requests',
}
}
- function _ajax(type, url, data) {
+ function _ajax(type, url, data, headers) {
@cvan
cvan / lru.js
Created March 27, 2014 18:22
snippet for LRU cache for object cache
// Get list of cache keys sorted by timestamp.
var keysAsc = _.sortBy(_.pairs(cache), function (x) {
return x[1].__time; // Timestamp
}).map(function(x) {
return x[0]; // URL
});
// Keep popping off expired keys until we're under the quota.
var i = 0;
while (JSON.stringify(cache).length >= settings.offline_cache_limit_request) {
@cvan
cvan / datauris.js
Created March 28, 2014 23:15
async parsing data URIs remotely (with nested promises)
var request = require('request');
var Promise = require('es6-promise').Promise;
var promisesApps = [];
promisesApps.push(new Promise(function (resolveApp, rejectApp) {
var urls = [
'https://marketplace-dev.mozflare.net/img/uploads/addon_icons/405/405402-64.png?modified=1384390457',
'https://marketplace-dev.mozflare.net/img/uploads/previews/full/81/81268.png?modified=1368635236'
];