Skip to content

Instantly share code, notes, and snippets.

@wesalvaro
wesalvaro / .ua.zsh
Last active December 23, 2015 05:29
Track shell stuff with Universal Analytics!
export UA_PROP='UA-XXXXX-Y' # Your UA property ID
export UA_CLIENT='wesalvaro' # A unique client (i.e. user) ID
alias ua_collect="curl www.google-analytics.com/collect -s -o /tmp/ua_collect --data v=1 --data tid=$UA_PROP --data cid=$UA_CLIENT"
# Tracks any "event" type.
function track_evt {
local category=$1
local action=$2
local value=$3 # integer
local label=$4
@wesalvaro
wesalvaro / gist:32d3ce554ea74a7f24f0
Last active August 29, 2015 14:02
Get all dem free songs!
$('a[href*=downloadSong]').each(function() {
$('<iframe />').attr('src', $(this).attr('href')).appendTo('body');
});
@wesalvaro
wesalvaro / gist:5b248f0aa2800e98bedc
Last active August 29, 2015 14:02
Raspberry Pi Emulator Setup
# http://supernintendopi.wordpress.com/
sudo apt-get update
sudo apt-get upgrade -y git
sudo apt-get install -y git dialog
# http://ledgerlabs.us/raspberrypi/xboxdrv-using-xbox-controllers/
sudo apt-get install xboxdrv
sudo cat << EOF >> /etc/rc.local
xboxdrv --daemon --detach --detach-kernel-driver --silent --dbus disabled \
--next-controller --next-controller \
@wesalvaro
wesalvaro / tattler.js
Last active August 29, 2015 14:05
Inbox Zero Tattler
/*
A Google Apps Script for reporting your Inbox Zero progress/procrastination.
https://gist.github.com/wesalvaro/01cc403b92ab91ac622e
Installation:
1. Use this file to create a new Google Apps Script.
2. Run the `checkInboxThreadCount` function in your new app to authorize it.
3. Setup a trigger to run the `checkInboxThreadCount` function however you like.
4. Deploy your script as a web app.
Note: The app should be set to run as _you_.
@wesalvaro
wesalvaro / av.py
Created September 4, 2014 21:30
Alternative Vote Counter
import csv
import re
import sys
import pprint
PRINT_VOTES = False
PRINT_OPTIONS = False
OPTION_PATTERN = r'.*\[(.*?)\].*'
VOTE_TEXTS = {
@wesalvaro
wesalvaro / adk_serial_led_test.c
Created June 30, 2015 22:33
Read a Byte with ADK
#include <Max3421e.h>
#include <Usb.h>
#include <Max3421e_constants.h>
#include <AndroidAccessory.h>
AndroidAccessory acc("Google",
"Light Runner",
"LED Controller.",
"1.0",
@wesalvaro
wesalvaro / wiggle-sort.js
Last active July 5, 2016 06:55
A simple implementation of wiggle sorting.
Array.prototype.wiggleSort = function() {
for (let i = 0; i < this.length - 1; ++i) {
const shouldNotBeLessThan = i % 2;
const isLessThan = this[i] < this[i + 1];
if (shouldNotBeLessThan && isLessThan) {
[this[i], this[i + 1]] = [this[i + 1], this[i]];
}
}
return this;
};
@wesalvaro
wesalvaro / pygraphviz-search.py
Last active July 5, 2016 07:06
BFS and DFS for PyGraphviz
INDEX_BFS = 0
INDEX_DFS = -1
NOOP = lambda x: None
def traverse(graph, nodes, callback, index):
visited = set()
while nodes:
node = nodes.pop(index)
if node not in visited:
@wesalvaro
wesalvaro / chrome-snippet-regex-search.js
Created July 11, 2016 07:54
Simple snippet to do regular expression search in a Chrome Snippet.
reText = prompt('RegExp?');
backgroundColor = 'rgba(255,255,80,0.5)';
outline = `3px solid ${backgroundColor}`;
matchClass = 're-match';
{ // clear old matches
@wesalvaro
wesalvaro / aarray.js
Last active August 15, 2016 04:55
Wraps an Array with generator functions.
const it = function(a) {
return new Aarray(a2g(a));
};
const a2g = function*(a) {
for (let v of a) {
yield v;
}
};