Skip to content

Instantly share code, notes, and snippets.

View cvan's full-sized avatar
🚌
🌊

Christopher Van cvan

🚌
🌊
View GitHub Profile
@cvan
cvan / datauris.js
Created March 29, 2014 00:07
parsing data URIs asynchronously
var _ = require('lodash');
var request = require('request');
var Promise = require('es6-promise').Promise;
var use_data_uris = true;
request('https://marketplace-dev.allizom.org/api/v1/rocketfuel/collections/curated/', function (err, res, body) {
var data = JSON.parse(body).apps;
@cvan
cvan / mozAppsInstalled.js
Created April 2, 2014 04:45
get installed list of navigator.mozApps
function getInstalled() {
return new Promise(function (resolve, reject) {
// Don't call `navigator.mozApps.getInstalled` if the page isn't
// visible or if the `navigator.mozApps` API isn't available.
if (document.hidden || !navigator.mozApps) {
return reject();
}
// Get list of installed apps.
var mozGetInstalled = navigator.mozApps.getInstalled();
var fs = require('fs');
var http = require('http');
var request = require('request');
var zlib = require('zlib');
// res.headers = {
// "Date": "Thu, 03 Apr 2014 00:05:39 GMT",
var fs = require('fs');
var http = require('http');
var request = require('request');
var zlib = require('zlib');
// res.headers = {
// "Date": "Thu, 03 Apr 2014 00:05:39 GMT",
@cvan
cvan / checkOffline.js
Last active August 29, 2015 13:58
because Firefox doesn't really tell you with `navigator.onLine`
function checkOnline() {
// `navigator.onLine` is always accurate in Chrome,
// but of course it's *never* accurate in Firefox
// (bug 654579, bug 756364). Yeah, I know - sad times.
return new Promise(function (resolve, reject) {
var i = new Image();
i.src = document.querySelector('head [rel*=icon]').href + '?' + +new Date();
i.onload = function () {
resolve();
};
@cvan
cvan / checkOfflineDummyGif.js
Last active August 29, 2015 13:58
using a dummy image to test whether we're online
function checkOnline() {
// `navigator.onLine` is always accurate in Chrome,
// but of course it's *never* accurate in Firefox
// (bug 654579, bug 756364). Yeah, I know - sad times.
return new Promise(function (resolve, reject) {
var i = new Image();
i.src = '/dummy.gif?' + +new Date();
i.onload = function () {
resolve();
};
/**
* If you need the string representation, there is a handy
* 'unicode' property you can query on the returned object.
*
* @param {string} from is a HEX code you want to start from.
* @param {string} to is a HEX code you want to end with.
* @return {array} the unicode range from - to.
**/
function unicodeSequence(from, to) {
'use strict';
@cvan
cvan / promiseAll.js
Created April 16, 2014 23:06
promise.all order
var Promise = require('es6-promise').Promise;
var promises = [];
promises.push(new Promise(function(resolve, reject) {
setTimeout(function(){
resolve(1);
}, 5000);
@cvan
cvan / urls.py
Created June 10, 2014 00:23
using lists for django's conf.urls urlpatterns
from django.conf.urls import patterns, url
from django.views.generic import RedirectView
from . import views
def redirect_doc(uri):
return RedirectView.as_view(
url='https://developer.mozilla.org/docs%s' % uri)
@cvan
cvan / sample-output.txt
Created July 1, 2014 23:43
CLI interface for generating and submitting a Firefox webapp to the Firefox Marketplace (WIP)
(driven) %% python submitapp.py /opt/seamission-cli
********************
Create your manifest
********************
Enter app name: Forecast
Enter app description: Real-time weather on your phone
Enter version (default: 1.0): 2.0
Enter developer name: Forecast.io
Enter developer URL: http://forecast.io/