Skip to content

Instantly share code, notes, and snippets.

@gavinsharp
gavinsharp / task.js
Last active August 29, 2015 14:15 — forked from leibovic/task.js
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/**
* This module implements a subset of "Task.js" <http://taskjs.org/>.
@gavinsharp
gavinsharp / gist:1083174
Created July 14, 2011 19:04 — forked from abhinavsharma/gist:1083149
automatically add search engine with jetpack
tabs.on('ready', function(tab) {
reportError("tab activated");
let gBrowser = Svc.Services.wm.getMostRecentWindow("navigator:browser").gBrowser;
let doc = gBrowser.contentDocument;
let browser = gBrowser.getBrowserForDocument(doc);
if (browser.engines) {
reportError(Object.keys(browser.engines[0]));
browser.engines.forEach(function({uri, title, icon}) {
let type = (/xml$/).test(uri) ? Ci.nsISearchEngine.DATA_XML : Ci.nsISearchEngine.DATA_TEXT;
let e = Svc.Services.search.currentEngine;
@gavinsharp
gavinsharp / dominant-color.js
Created June 9, 2011 17:06 — forked from leibovic/dominant-color.js
Dominant Color
function getDominantColor(aImg) {
let canvas = document.createElement("canvas");
canvas.height = aImg.height;
canvas.width = aImg.width;
let context = canvas.getContext("2d");
context.drawImage(aImg, 0, 0);
// keep track of how many times a color appears in the image
let colorCount = {};