Skip to content

Instantly share code, notes, and snippets.

View gasolin's full-sized avatar

gasolin gasolin

View GitHub Profile
var Joi = require('joi-browser');
const VALID_TOURS = ["private", "addons", "customize", "search", "default", "sync", "library", "singlesearch", "performance", "screenshots"];
const baseKeys = {
client_id: Joi.string().required(),
addon_version: Joi.string().required(),
locale: Joi.string().required(),
session_id: Joi.string(),
page: Joi.valid(["about:home", "about:newtab"])

Network Monitor

The Network Monitor(netmonitor) shows you all the network requests Firefox makes (for example, when it loads a page, or due to XMLHttpRequests), how long each request takes, and details of each request.

Prerequisite

@gasolin
gasolin / Vagrantfile
Last active October 12, 2016 02:59
Vagrantfile for elementary OS VM setup
# -*- mode: ruby -*-
# vi: set ft=ruby :
$bootstrap = <<SCRIPT
!/bin/bash
SCRIPT
# To use this script and prepare your build environment, run the following
# command in the same directory as the Vagrantfile.
/* -*- indent-tabs-mode: nil; js-indent-level: 2; fill-column: 80 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/sourceeditor.properties");
@gasolin
gasolin / memorize.js
Created August 28, 2016 04:27
memorize.js
// from https://jigsawye.gitbooks.io/mostly-adequate-guide/content/ch3.html
var memorize = function(f) {
var cache = {};
return function() {
var arg_str = JSON.stringify(arguments);
cache[arg_str] = cache[arg_str] || f.apply(f, arguments)
return cache[arg_str];
}
}
function Shape({ x, y }) {
this._x = x;
this._y = y;
}
Shape.prototype = {
get coords() {
return { x: this._x, y: this._y };
},
}
@gasolin
gasolin / relayout.py
Last active December 30, 2015 05:38
put this file in gaia main folder and run $ python relayout.py to replace layout breakpoint
# put this file in gaia main folder and run
# python relayout.py
# 768 -> 600
originWidth = 768
targetWidth = 600
# find and replace string
import os, fnmatch
def findReplace(directory, find, replace, filePattern):
@gasolin
gasolin / gist:6578631
Created September 16, 2013 09:44
trim string (Levithan version)
function trim(text) {
text.replace(/^\s+/, "");//.replace(/\s+$/, "");
for (var i = text.length - 1; i >= 0; i--) {
if (/\s/.test(text.charAt(i))) {
text = text.substring(0, i + 1);
break;
}
}
return text;
}
@gasolin
gasolin / Script DOM element
Last active December 23, 2015 04:09
async download DOM and allow cross domain JS by Script DOM element
var dom = document.createElement('script');
dom.src = "http://xxx/a.js";
document.head.appendChild(dom);
//shuffles list in-place
//credit http://dtm.livejournal.com/38725.html
function shuffle(list) {
var i, j, t;
for (i = 1; i < list.length; i++) {
j = Math.floor(Math.random()*(1+i)); // choose j in [0..i]
if (j != i) {
t = list[i]; // swap list[i] and list[j]
list[i] = list[j];
list[j] = t;