Skip to content

Instantly share code, notes, and snippets.

@jsantell
jsantell / task-in-sdk.js
Last active August 29, 2015 14:01
Using Task.jsm in SDK
const { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
const { defer, all } = require("sdk/core/promise");
const { setTimeout } = require("sdk/timers");
Task.spawn(function *() {
let item1 = yield getItem(1);
let [item2, item3] = yield all([getItem(2), getItem(3)]);
console.log(item1, item2, item3); // 1, 2, 3
}).then(function () {
console.log('all items processed')
@jsantell
jsantell / webaudioscratchsheet.md
Last active August 29, 2015 14:01
Firefox Developer Tools' Web Audio Editor scratchpad

Originally from etherpad

The Web Audio Editor in Firefox Developer Tools is still a work in progress. A lot of love is needed in its current state, and once the basic features are working, here are some dream features, and future planning.

Milestones

@jsantell
jsantell / contentscript.js
Created March 19, 2014 23:23
example content scripts piping back and forth
const { Panel } = require("sdk/Panel");
const { data } = require("sdk/self");
let panel1 = Panel({
contentURL: data.url("panel1.html")
});
let panel2 = Panel({
contentURL: data.url("panel2.html")
});
@jsantell
jsantell / promised.js
Created March 16, 2014 20:56
Ensure async thenable returns
let { resolve, isPromiseLike } = require('when');
let syncAdd = (x, y) => x + y;
let asyncAdd = (x, y) => resolve(x + y);
promised(syncAdd(5, 10)).then(console.log); // 15
promised(asyncAdd(5, 10)).then(console.log); // 15
function promised (result) {
return isPromiseLike(result) ? result : resolve(result);
@jsantell
jsantell / message-bus.js
Last active June 8, 2016 04:22
message-bus.js
/*
* CONTENT THREAD
*/
let responses = new Map();
let listener = ({ id, response }) => {
let callback = responses.get(id);
if (callback) {
responses.delete(id);
callback(response);
}
@jsantell
jsantell / jpm-command.sh
Created January 13, 2014 21:01
Using `jpm init` to automatically enable node packages, adding to the dependencies and overload routes set up for what `jetpack-node` supports, which is a suite of `jetpack-*` dependencies (`package.json`). User can also add their own custom dependencies and overloads (`package2.json`)
$ jpm init
JPM info Running init on undefined
title: (My Jetpack Addon)
name: (my-jetpack)
version: (0.0.0)
Enable node packages? (yes)
description:
entry point: (index.js)
author:
engines (comma separated): (firefox,fennec)
// Doesn't work
subprocess({
file: 'C:\\Windows\\System32\\cmd.exe',
args: ['/s', '/c', '\"DIR /L\"']
})
// Works
subprocess({
file: 'C:\\Windows\\System32\\cmd.exe',
args: ['/s', '/c', '\"c:\\path\\to\\file.bat\"']
function Type (props) {
for (prop in props)
if (props.hasOwnProperty(prop))
this[prop] = props[prop]
}
Type.prototype.getName = function () { return this.name; }
var data = {
name: "Ted",
@jsantell
jsantell / workertab.js
Created December 11, 2013 21:22
worker.tab test
const pageMod = require("sdk/page-mod");
const tabs = require("sdk/tabs");
var mod = pageMod.PageMod({
include: "*",
contentScript: '(function () { console.log("attached") })();',
onAttach: function(worker) {
if (worker.tab)
console.log('HURRAY');
console.log(worker.tab);
@jsantell
jsantell / declaritive-build.js
Created December 6, 2013 23:57
dreambuilder
var declare = {
// Transpile src stylus/sass and concatenate with vendor CSS into `dist/build.css`
'dist/build.css': ['vendor/**/*.css', 'style/*.styl', 'style/*.sass'],
// Transpile src coffeescript and concatenate with vendor JS into temporary pseudofile `$tmpjs.js`
'$tmpjs.js': ['vendor/**/*.js', 'src/*.coffee'],
// Compile handlebar templates into temporary pseudofile `$tmphbs.js`
'$tmphbs.js': 'templates/*.hbs',
// Concatenate our built JS and templates into `dist/build.js`
'dist/build.js': ['$tmpjs.js', '$tmphbs.js'],
// Also create a minified version