Skip to content

Instantly share code, notes, and snippets.

View gasolin's full-sized avatar

gasolin gasolin

View GitHub Profile
@gasolin
gasolin / res.py
Last active December 20, 2015 01:59
Gather gaia multiple resolution resources to a web page for easy debuggingUsage: `python res.py [app_name]`ex: `python res.py browser`
import os, glob, sys
from string import Template
import datetime
template = """
<DOCTYPE html>
<html>
<body>
$table
</body>
from random import shuffle
print 'gaia lottery!'
gaia_members = ['Yuren','Arthur','Dominic',
'Rex','Steve','Rudy','Alive',
'Evan','Mark','John','Fred','George','Ian','Greg','Jason']
shuffle(gaia_members)
print gaia_members
//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;
@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);
@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 / 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 / pushtry.sh
Created March 21, 2014 03:36
script helper to push gaia branch to try server
# https://wiki.mozilla.org/ReleaseEngineering/TryServer#Using_a_custom_Gaia
# https://wiki.mozilla.org/Gaia/Team/Taipei/BubbleTea#How_to_push_bubble-tea_to_try
hg qref -m "try: -b o -p emulator,emulator-jb,emulator-kk,linux_gecko,linux64_gecko,macosx64_gecko,win32_gecko -u gaia-unit,gaia-ui-test,gaia-integration -t none"
hg push -f try
@gasolin
gasolin / action_cmd.js
Last active August 29, 2015 13:57
run system execution via nodejs
function action_cmd(cmd) {
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) {sys.puts(stdout)}
exec(cmd, puts);
}
@gasolin
gasolin / probe.js
Last active August 29, 2015 14:00
collecting js function performance
var start = new Date().getTime();
for (var n = 0; n < maxCount; n++) {
/* perform the operation to be measured *//
}
var elapsed = new Date().getTime() - start;
console.log('Measured time: ' + elapsed);
var http = require("http");
var cheerio = require("cheerio");
/**
* Utility function that downloads a URL and invokes
* callback with the data.
*/
function download(url, callback) {
http.get(url, function(res) {
var data = "";