Skip to content

Instantly share code, notes, and snippets.

View gregglind's full-sized avatar

Gregg Lind gregglind

View GitHub Profile
@gregglind
gregglind / gist:44344c1da126b72a3b06
Created May 5, 2014 17:09
Exploring Lift and Relative Risk
# lift: p(x,y) / ( p(x)*p(y) == ratio of 'overage' compared to independence
# rr = relative risk == p(x+|y+) / p(x-|y-)
rr_more <- function(n){
m <- matrix(rmultinom(1,n,c(1,2,3,4)),c(2,2))
rownames(m) <- colnames(m) <- c(T,F)
R <- rowSums(m)
C <- colSums(m)
lift <- m[1,1] / (R[1] * C[1] / n)
@gregglind
gregglind / amo.sh
Last active August 29, 2015 14:04
Accessing The Mozilla Addons (AMO) API examples.
# https://developer.mozilla.org/en-US/docs/addons.mozilla.org_%28AMO%29_API_Developers%27_Guide/The_generic_AMO_API
# by search
curl 'https://services.addons.mozilla.org/en-US/firefox/api/1.5/search/guid:firefox-hotfix@mozilla.org' | xmllint --format - | grep '<icon'
# by id
curl 'https://services.addons.mozilla.org/en-US/firefox/api/1.5/addon/1-click-youtube-video-downl?format=json' | python -m json.tool | grep '"icon":'
# by amo id
curl -s https://services.addons.mozilla.org/en-US/firefox/api/1.5/addon/1865 | xmllint --format - | grep icon
@gregglind
gregglind / gist:1642f26521bd470e7a07
Last active August 29, 2015 14:04
Eval, Exec, Safeguarding in python
# from: http://effbot.org/zone/librarybook-core-eval.htm
print eval("__import__('os').remove('file')", {"__builtins__": {}}) # in particular, one has to kill or safeguard __import__
# PyRun_SimpleStringFlags
https://github.com/python-git/python/blob/715a6e5035bb21ac49382772076ec4c630d6e960/Modules/main.c#L284
https://github.com/python-git/python/blob/715a6e5035bb21ac49382772076ec4c630d6e960/Python/pythonrun.c#L949
https://github.com/python-git/python/blob/715a6e5035bb21ac49382772076ec4c630d6e960/Python/pythonrun.c#L1286
"""
from fileinput or stdin, decorate lines with userid, ts for later sort.
Full usage:
hadoop dfs -text /bagheera/testpilot_contextfeaturerecommender/*/* | python dsu.py | sort -k 1,2 | cut -f 3- | less -S
(decorate-sort-undecorate pattern sorting)
"""
@gregglind
gregglind / no-authohide.js
Created September 3, 2014 19:13
code to change sdk panels to no autohide.
let xulWindow = WindowUtils.getMostRecentBrowserWindow()
let mainWindow = xulWindow.document.children["main-window"]
let xulPanel = Array.from(mainWindow.querySelectorAll("popupset#mainPopupSet panel")).find(p => p.backgroundFrame && p.backgroundFrame.getAttribute("src") == this.panelUri)
xulPanel.setAttribute("noautohide", true)

One Tab, One Window Utility Function

Usage

cfx test -v

background

New style done() in jetpack test library testing assumes that the ui is 'clean', which means:

@gregglind
gregglind / para.tags.all.ids.txt
Last active August 29, 2015 14:08
Idea for making all ids on a reports page have a para link.
/** js **/
/** or this could be in the page template, if adding an 'a' there is easier **/
/* 'after' was chosen for laziness/simplicity of styling. */
/* if you to get *all things with ids
$(".content").find("p, ul, ol, pre, h1, h2, h3, h4, h5, h6") # more restrictive
*/
$(".content").find("*").each( function (k, v) {
var id = v.id;
@gregglind
gregglind / heartbeat-widgets.jsm
Last active August 29, 2015 14:09
Example of Heartbeat widgets, using new an old style notifications
/* jshint forin:true, noarg:false, noempty:true, eqeqeq:true, bitwise:true,
strict:true, undef:true, curly:false, browser:true,
unused:true,
indent:2, maxerr:50, devel:true, node:true, boss:true, white:true,
globalstrict:true, nomen:false, newcap:true, esnext: true, moz: true */
/*global exports, require */
// "use strict";
"""
ENV:
ONEPERCENT - use the 1% sample
JOB_* - these will go to the JOB enivornment, and are viewable from the map functions
RUN - to run from cli. (gross, sorry!)
Examples:
rm -rf driver.jar /tmp/output;
ONEPERCENT=1 JOB_SUBSAMPLE=.02 make ARGS="scripts/whatever.py /tmp/output" hadoop # implied 1 pct location
@gregglind
gregglind / gist:b9889d557b8ca5fa80d8
Created December 4, 2014 23:10
Servo build errors
36423 glind ~/gits/servo [git:master]$ ./mach build
Submodule 'tests/wpt/web-platform-tests' (https://github.com/servo/web-platform-tests.git) registered for path 'tests/wpt/web-platform-tests'
Cloning into 'tests/wpt/web-platform-tests'...
remote: Counting objects: 73149, done.
remote: Compressing objects: 100% (23005/23005), done.
remote: Total 73149 (delta 47863), reused 73139 (delta 47855)
Receiving objects: 100% (73149/73149), 53.81 MiB | 590 KiB/s, done.
Resolving deltas: 100% (47863/47863), done.
Submodule path 'tests/wpt/web-platform-tests': checked out 'a467a3312ae3730e9e1ce0fd1cc200a2dbeadbe6'
Submodule 'resources' (https://github.com/servo/testharness.js.git) registered for path 'resources'