Skip to content

Instantly share code, notes, and snippets.

View ryonsherman's full-sized avatar

Ryon Sherman ryonsherman

View GitHub Profile
@ryonsherman
ryonsherman / underscore_camelcase.js
Last active October 8, 2015 15:18
Various Underscore/CamelCase methods.
function underscoreToCamelCase(value) {
return value.split('_').map(function(value) { return value.charAt(0).toUpperCase() + value.substr(1); }).join('');
}
@ryonsherman
ryonsherman / api-command.php
Created September 16, 2012 19:38
Auto-throttle CGMiner intensity on xscreensaver activiation.
#!/usr/bin/env php
<?php
$address = isset($argv[2]) ? $argv[2] : '127.0.0.1';
$port = isset($argv[3]) ? $argv[3] : 4028;
$command = isset($argv[1]) ? $argv[1] : 'summary';
if (!$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) return;
if (!socket_connect($socket, $address, $port)) return socket_close($socket);
@ryonsherman
ryonsherman / pushover.sh
Created October 10, 2012 22:44
Pushover
#!/usr/bin/env sh
URL="https://api.pushover.net/1/messages.json"
API_KEY=""
USER_KEY=""
DEVICE=""
TITLE="${1}"
MESSAGE="${2}"
@ryonsherman
ryonsherman / firefox_profile_path.py
Last active October 12, 2015 04:58
Get Firefox profile path.
import os
path = os.path.expanduser('~/.mozilla/firefox/')
path += filter(lambda file: file.endswith('.default'), os.listdir(path))[0]
@ryonsherman
ryonsherman / youtube_iframe.py
Last active May 19, 2016 17:59
Parse Youtube URL, extract video ID, and provide embed iframe.
from urlparse import urlparse, parse_qs
url = urlparse('https://www.youtube.com/watch?v=XXXXXXXXXXX')
if 'youtube' in url.netloc.lower():
video_id = parse_qs(url.query).get('v', [False])[0]
if video_id:
print '<iframe width="560" height="315" src="http://www.youtube.com/embed/{0}" frameborder="0" allowfullscreen></iframe>'.format(video_id)
@ryonsherman
ryonsherman / app.yaml
Created February 12, 2013 18:39
Simple MVC/Template implementation of the GAE Framework using webapp2/jinja2.
application: webapp2_framework
version: 1
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: jinja2
version: latest
@ryonsherman
ryonsherman / rgb_to_hex.js
Created February 13, 2013 19:31
Convert RGB values to hex.
var hex = (r | (g << 8) | (b << 16)).toString(16).toUpperCase();
@ryonsherman
ryonsherman / irc_bot.py
Created May 10, 2013 17:12
Basic IRC bot boilerplate.
import time
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol, ssl
NETWORK = 'irc.network.com'
PORT = 6697
CHANNEL = 'channel'
NICKNAME = 'bot'
@ryonsherman
ryonsherman / lotto_nums.py
Created May 10, 2013 17:17
One-liner to scrape winning lotto numbers and display most common selection at each position.
import urllib, csv, collections; print ', '.join([collections.Counter(values).most_common(1)[0][0] for values in map(lambda i: [value[0] for value in map(lambda values: [value for index, value in enumerate(values) if index is i], map(lambda row: row[4:10], csv.reader(urllib.urlopen("http://txlottery.org/export/sites/lottery/Games/Lotto_Texas/Winning_Numbers/lottotexas.csv"))))], range(6))])
@ryonsherman
ryonsherman / numsort.py
Last active December 20, 2015 19:49
Sort numerical values regardless of format
#!/usr/bin/env python2
numsort = lambda l: sorted(l, key=lambda x: int(str(x).split('-')[0].split('.')[0].replace('$', '')))