Skip to content

Instantly share code, notes, and snippets.

View tupton's full-sized avatar

Thomas Upton tupton

View GitHub Profile
@tupton
tupton / eventcmd
Created January 16, 2011 21:33
An example eventcmd script for posting pianobar events to Last.fm with Scrobbular.
#!/bin/bash
# create variables
while read L; do
k="`echo "$L" | cut -d '=' -f 1`"
v="`echo "$L" | cut -d '=' -f 2`"
export "$k=$v"
done < <(grep -e '^\(title\|artist\|album\|stationName\|pRet\|pRetStr\|wRet\|wRetStr\|songDuration\|songPlayed\|rating\)=' /dev/stdin) # don't overwrite $1...
username='<YOUR GOOGLE USERNAME>';
@tupton
tupton / scrobbular curl
Last active September 24, 2015 17:17
An example curl script to post song information to Scrobbular
curl -X POST \
--data-urlencode "username=test@example.com" \
--data-urlencode "s=secret" \
--data-urlencode "track=Red Sky" \
--data-urlencode "artist=Thrice" \
--data-urlencode "album=Vheissu" \
--data-urlencode "duration=258" \
http://scrobbular.appspot.com/scrobble
@tupton
tupton / z2mtxR24
Created May 24, 2012 00:54 — forked from anonymous/z2mtxR24
a guest on May 23rd, 2012 - pastebin.com/z2mtxR24
if (type == 'node-down' || type == 'cluster-balance') {
this['thresholdNode'].set('disabled', true);
this['comparatorNode'].set('disabled', true);
}
@tupton
tupton / gist:3145451
Created July 19, 2012 17:21
FIXME and TODO
<?php
function getObject($id) {
$object = null;
// TODO Do we need to validate username?
$objects = $this->db->retrieveForUsername($this->username);
// FIXME Write `retrieveForIdAndUsername` instead of iterating here
foreach ($objects as $o) {
@tupton
tupton / gist:4027889
Created November 6, 2012 22:01
Concise Opscenter Alerts
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DataStax OpsCenter Alerts</title>
<script src="js/dojotoolkit/dojo/dojo.js"></script>
<script>
require([
'dojo/_base/lang',
'dojo/_base/xhr',
javascript:(function(e,t){var n=e.document;setTimeout(function(){function a(e){if(e.data==="destroy_bookmarklet"){var r=n.getElementById(t);if(r){n.body.removeChild(r);r=null}}}var t="DELI_bookmarklet_iframe",r=n.getElementById(t);if(r){return}var i="https://delicious.com/save?",s=n.createElement("iframe");s.id=t;s.src=i+"url="+encodeURIComponent(e.location.href)+"&title="+encodeURIComponent(n.title)+"&note="+encodeURIComponent(""+(e.getSelection?e.getSelection():n.getSelection?n.getSelection():n.selection.createRange().text))+"&v=1.1";s.style.position="fixed";s.style.top="0";s.style.left="0";s.style.height="100%25";s.style.width="100%25";s.style.zIndex="16777270";s.style.border="none";s.style.visibility="hidden";s.onload=function(){this.style.visibility="visible"};n.body.appendChild(s);var o=e.addEventListener?"addEventListener":"attachEvent";var u=o=="attachEvent"?"onmessage":"message";e[o](u,a,false)},1)})(window)
@tupton
tupton / reporter-app-date-formatter.py
Created March 22, 2014 22:04
Formatter for Reporter App dates
import datetime
import pytz
def format_report_date(date_or_nsdate):
formatted = None
if type(date_or_nsdate) is float:
try:
reference_date = datetime.datetime(2001, 1, 1, 0, 0, 0, 0, pytz.utc).strftime('%s')
formatted = datetime.datetime.fromtimestamp(long(reference_date) + date_or_nsdate)
except e:
@tupton
tupton / lastfm-stats-listening-time.py
Last active December 12, 2017 21:28
Example excerpt from jupyter notebook
# get_tracks is an api method to get recent tracks for a user, with paging and caching
# get_track is an api method to get a single track from mbid or artist+name, with caching
import itertools
from operator import itemgetter
def track_to_artist_and_duration(track):
api_track = get_track(track)
return (track.get('artist').get('name'), track.get('name'), api_track.get('duration'))
@tupton
tupton / useSupportSidebar.js
Created October 21, 2019 19:19
hook that provides a jsx component
const useSupportSidebar = () => {
const classes = useStyles();
const [isSidebarOpen, setSidebarOpen] = useState(false);
const toggleSidebar = () => setSidebarOpen(!isSidebarOpen);
const closeSidebar = () => setSidebarOpen(false);
const drawerStateClass = isSidebarOpen ? classes.drawerOpen : classes.drawerClose;
@tupton
tupton / keybase.md
Created March 15, 2020 11:35
keybase.md

Keybase proof

I hereby claim:

  • I am tupton on github.
  • I am tupton (https://keybase.io/tupton) on keybase.
  • I have a public key ASBctvCZaghnMCnQ9DRzjMkcNiKXw9ck0pL4WO3Np3dbGAo

To claim this, I am signing this object: