Skip to content

Instantly share code, notes, and snippets.

@harthur
harthur / debug-devtools.js
Last active December 16, 2015 14:19
Open a Firefox devtools window that's debugging the devtools window that's debugging the currently selected tab.
/*
* Running this scratchpad in chrome mode will open a devtools window that's debugging
* the devtools window that's debugging the currently selected tab.
*/
let {devtools} = Components.utils.import("resource:///modules/devtools/gDevTools.jsm", {});
let tabTarget = devtools.TargetFactory.forTab(gBrowser.selectedTab);
let toolbox = gDevTools.getToolbox(tabTarget);
let win = toolbox._host.frame.contentWindow;
@harthur
harthur / debug-chrome.js
Last active December 16, 2015 14:20
Open a Firefox devtools window that's debugging the current browser window.
/*
* Running this scratchpad in chrome mode will open a devtools window that's debugging
* the current browser window
*/
let {devtools} = Components.utils.import("resource:///modules/devtools/gDevTools.jsm", {});
let win = Services.wm.getMostRecentWindow("navigator:browser");
let target = devtools.TargetFactory.forWindow(win);
let toolbox = gDevTools.showToolbox(target, "styleeditor", "window");
@harthur
harthur / orientation-command.js
Last active December 17, 2015 22:09
Add a `deviceorientation` comand to the Firefox command line.
/**
* Running the following code in a Scratchpad running in the 'browser' context
* will add a `deviceorientation` command to the Firefox command line.
*/
Components.utils.import("resource:///modules/devtools/gcli.jsm");
gcli.addCommand({
name: 'deviceorientation',
description: 'Fire a deviceorientation event',
params: [{
@harthur
harthur / devtools-links.md
Last active December 17, 2015 22:09
Links from FluentConf talk on Firefox Developer Tools
@harthur
harthur / orientation.js
Created June 2, 2013 20:59
Firefox scratchpad for simulating `deviceorientation` events
/*
* Run this in a Firefox "Scratchpad" (Tools > Web Developer > Scratchpad)
* With Cmd-R to simulate an orientation event in the current page
*/
function simulateOrientation(alpha, beta, gamma) {
var event = document.createEvent("DeviceOrientationEvent");
event.initDeviceOrientationEvent('deviceorientation',
true, true, alpha, beta, gamma, true);
@harthur
harthur / tix.js
Last active May 21, 2016 15:23
How I got tickets to the Gymnastics finals at the Olympics
/* This node.js script checks the Olympics website for any new Women's
* Gymnastics tickets. Every five minutes it fetches the available tickets
* page for the event, and uses the cheerio (https://npmjs.org/package/cheerio)
* module to parse the page and look for the UI element that indicates there
* are tickets.
*
* If there are any tickets it plays a song using node's built in `exec()`
* function to call OS X's command line utility to play a sound file. It also
* uses the growl module (https://npmjs.org/package/growl) to post a growl
* notification.
@harthur
harthur / gist:992175
Created May 25, 2011 22:46
repos from the first Silicon Valley Hack and Tell meetup
@harthur
harthur / snippet.md
Created September 24, 2012 10:23
Sublime Text keyboard shortcut for inserting dump() for Firefox JS dev.

Go to Sublime Text 2 > Preferences > Key Bindings - User and add this JSON to the file:

[
    { "keys": ["super+shift+o"],
      "command": "insert_snippet",
      "args": {
        "contents": "dump(${1:} + \"\\n\");${0}"
      },
 "description": "insert a dump() call at the cursor, tab once to jump past"
@harthur
harthur / ml-in-js.md
Created May 13, 2014 19:01
Machine Learning JS libraries
@harthur
harthur / renderedfont.js
Created April 18, 2012 16:15
Get rendered font-family
function getRenderedFontFamily(fontFamily) {
var canvas = document.createElement("canvas");
var context = canvas.getContext("2d");
let families = fontFamily.split(/\s*,\s*/);
for each (let family in families) {
if (family == 'inherit') {
return family;
}