Skip to content

Instantly share code, notes, and snippets.

query.list <- Init(start.date = "2015-11-03",
end.date = "2015-12-14",
metrics="ga:users,ga:sessions,ga:goal1ConversionRate,ga:goal2ConversionRate,ga:goal3ConversionRate,ga:bounceRate,ga:goal3Completions",
dimensions = "ga:date,ga:browser,ga:browserVersion,ga:eventLabel,ga:eventCategory,ga:source",
max.results = 10000,
sort = "-ga:users",
table.id = table.id)
ga.query <- QueryBuilder(query.list)
return(GetReportData(ga.query, token, split_daywise = T))
@hoosteeno
hoosteeno / core_contrib_analysis.sql
Last active January 14, 2016 23:47
Get number of contribs, number of revisions per contrib, and percentage of contribution for those contribs using last 3 months activity to identify contribs.
SELECT count(username) AS num_contribs,
group_concat(username, ' (', user_total_revisions, ' revisions)' separator ', ') AS contribs,
sum(user_total_revisions) AS revisions_by_these_contribs,
overall_total_revisions,
(sum(user_total_revisions) / overall_total_revisions * 100) AS percentage_revisions_by_these_contribs
FROM (
/* get usernames WITH X revisions IN ANY month OF the last 3, AND Y revisions overall IN the last 3 */
@hoosteeno
hoosteeno / foo.bash
Last active January 13, 2016 16:36
What Python standard library modules can execute as scripts with -m?
export version=2.7.11 && wget -q https://docs.python.org/2/archives/python-$version-docs-text.zip && unzip -qu python-$version-docs-text.zip && egrep -Ihor "python -m \w+" python-$version-docs-text | sort | uniq
@hoosteeno
hoosteeno / scrape_bugs.py
Created January 8, 2014 20:27
Create forms for bug lists required by bug 956777
import re
import requests
from bs4 import BeautifulSoup
from mako.template import Template
urls = [
"http://www.mozilla.com/en-US/firefox/10.0/releasenotes/buglist.html",
"http://www.mozilla.com/en-US/firefox/10.0.1/releasenotes/buglist.html",
"http://www.mozilla.com/en-US/firefox/11.0/releasenotes/buglist.html",
"http://www.mozilla.com/en-US/firefox/12.0/releasenotes/buglist.html",
@hoosteeno
hoosteeno / scrape_bugs.py
Created January 6, 2014 22:30
Get all the bug IDs from some Firefox release pages and make a useless URL with them.
import re
import requests
from bs4 import BeautifulSoup
urls = [
"http://www.mozilla.com/en-US/firefox/10.0/releasenotes/buglist.html",
"http://www.mozilla.com/en-US/firefox/10.0.1/releasenotes/buglist.html",
"http://www.mozilla.com/en-US/firefox/11.0/releasenotes/buglist.html",
"http://www.mozilla.com/en-US/firefox/12.0/releasenotes/buglist.html",
"http://www.mozilla.com/en-US/firefox/13.0/releasenotes/buglist.html",
@hoosteeno
hoosteeno / web_release_numbering.py
Created November 26, 2013 22:50
Output some version numbers using a schema that might fit web products
year = '2014'
for month in range(1, 13):
month = '%02d' % month
for rel in range(1, 7):
print '%s-%s.%s' % (year, str(month), str(rel))
@hoosteeno
hoosteeno / get_country_counts.py
Created October 24, 2013 23:11
Get the number of Mozillians in every country.
import requests
def get_some(offset):
r = requests.get('https://mozillians.org/api/v1/countries/', params = {
'app_name': 'get_your_own',
'app_key': 'get_your_own',
'format': 'json',
'limit': 500,
'offset': offset,
'is_vouched': 'true'
@hoosteeno
hoosteeno / audit_dotcom.bash
Last active December 25, 2015 07:19
Bash script for outputting a CSV with information about the contents of the mozilla.com SVN tree.
#!/bin/bash
# depends on an up-to-date local copy of the mozilla.com svn tree!!
#cd ~/mozilla/mozilla.com; svn update; cd ~/mozilla/legacy
echo "LOCATION, SVN, # FILES, BUG, NEXT STEPS"
for FILE in `find ~/mozilla/mozilla.com/en-US \
-type d -name .svn -prune -o \
-type f -name *.html -print -o \
-type d -print`
@hoosteeno
hoosteeno / get_dialog_sql.py
Last active December 24, 2015 10:09
Python script for creating sql from healthy dialog spreadsheet.
#!/usr/bin/python
"""
* There is no need to run this per location; you can concatenate all input files or all output files.
* Modify line 15 with input filename
* Direct stdout to output filename (a .sql file)
* Work with DBAs (oncall if necessary) to get this done: https://bugzilla.mozilla.org/show_bug.cgi?id=922340
Example output:
UPDATE profile, auth_user SET profile.dialog = '14,7,36' WHERE profile.user_id = auth_user.id AND auth_user.username = 'foo';
@hoosteeno
hoosteeno / get_pix.py
Created September 27, 2013 20:32
Get 250 random mozillians avatars (requires python3)
import re
from random import shuffle
import requests
from PIL import Image
from io import BytesIO
app_name = 'get_your_own'
app_key = 'get_your_own'
api_cache = 'pix.out'