Skip to content

Instantly share code, notes, and snippets.

View harleyholt's full-sized avatar

Harley Holt harleyholt

  • Seattle
  • 13:29 (UTC -07:00)
View GitHub Profile
@harleyholt
harleyholt / gist:1133110
Created August 9, 2011 00:13 — forked from splee/gist:1133099
The Soda Algorithm
import random
from imagination import count_soda, restock_soda
available_sodas = ['Sprite', 'Coke', 'Diet Coke', 'Dr. Pepper']
def take_soda(consumer):
soda = random.choice(available_sodas)
if count_soda(soda) < 2 and not consumer.is_dick():
restock_soda(soda)
else:
@harleyholt
harleyholt / gearmand-mysql-init.d
Created September 20, 2011 23:54
gearmand mysql dependency; shows how to make the gearman deamon startup depend on mysql
### BEGIN INIT INFO
# Provides: gearman-job-server
# Required-Start: $network $remote_fs $syslog mysql
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable gearman job server
### END INIT INFO
@harleyholt
harleyholt / gearman-client-example.py
Created September 21, 2011 22:30
Example Python Gearman Client (for python Gearman 2.0)
from gearman import GearmanClient
# create a client that will connect to the Gearman server running on
# localhost. The array allows you to specify a set of job servers.
client = GearmanClient(['127.0.0.1'])
# Submit a synchronous job request to the job server and store the
# result.
# This runs the "echo" job on the argument "foo"
result = client.submit_job('echo', 'foo')
@harleyholt
harleyholt / gearman-worker-example.py
Created September 21, 2011 22:38
Example Python Gearman Worker (for python Gearman 2.0)
from gearman import GearmanWorker
# The function that will do the work
def echoer(worker, job):
print job.data
return job.data
# Establish a connection with the job server on localhost--like the client,
# multiple job servers can be used.
worker = GearmanWorker(['127.0.0.1'])
@harleyholt
harleyholt / data-api-return.js
Created September 23, 2011 01:03
Example Data API Return Object
/**
* One way of specifying the analytic endpoint data.
* In this scheme, we can have multiple parallel time series returned.
* Includes a summary object which allows us to return aggregated data for the series.
* Includes a meta object which has information about the series (such as the units of measurement).
*
* The time series is specified as an array of values. This series can not be missing any values because it is in
* parallel to the generated time values. The API must take care of filling in any missing values of the time
* series before returning it.
*
@harleyholt
harleyholt / data-api-summary-return.js
Created September 26, 2011 17:58
Example Data API Summary Return Object
/**
* Example of a summary only data API return. The returned information contains the aggregate information.
* The site value is the site that we are getting information for (it will not exist if the results are not filtered
* to a specific site)
* The time value contains the start and end of the sampling period while the resolution tells the client what the aggregate
* period is for the client
*/
{
site: example.com,
time: {
@harleyholt
harleyholt / django-stored-procedure.py
Created October 11, 2011 01:59
Django Stored Procedure
from django.db import connections
arguments = ('one', 'two', 'three', '...')
cursor = connections['example-db'].cursor()
try:
cursor.callproc('proc_name', arguments)
results = cursor.fetchall()
finally:
cursor.close()
@harleyholt
harleyholt / msyq-dump-specific-tables.sh
Created October 14, 2011 21:20
MySQL Dump Specific Tables and Stored Procs
mysqldump <database-name> [<table1> ... <tableN>] --routines > output.sql
@harleyholt
harleyholt / example-if-template.html
Created October 20, 2011 22:24
Example of Knockout Conditionally Rendered Template
<!-- Example one shows the most verbose way of specifying a template that is only rendered if someObject is defined in the current view model
This information was culled from https://github.com/SteveSanderson/knockout/blob/1.3/src/binding/defaultBindings.js#L445
-->
<script type="text/html" id="sub-example-one">
<h2 data-bind="text: title"></h2>
<p data-bine="text: description"></p>
</script>
<script type="text/html" id="example-one">
@harleyholt
harleyholt / select-from-redshift.sql
Created March 17, 2014 23:39
Retrieves the data we want to get from RedShift.
select
row_type_cd,
row_sub_type_cd,
date_pst,
publisher_id,
site_id,
case
when user_type_cd = 'C' then 'control'
when user_type_cd = 'T' then 'test'
else 'other'