Skip to content

Instantly share code, notes, and snippets.

View bbengfort's full-sized avatar
🎯
Focusing

Benjamin Bengfort bbengfort

🎯
Focusing
View GitHub Profile
@bbengfort
bbengfort / channels.go
Created October 10, 2014 13:06
Example of channel use in Go
package main
import (
"fmt"
"time"
)
func thread(c chan int, i int) {
fmt.Printf("thread %d, val %d\n", i, <-c)
}
@bbengfort
bbengfort / db.py
Created October 11, 2014 12:15
connecting to mongo with chirpy config
from pymongo import MongoClient
from chirpy.config import settings
def connect(**kwargs):
defaults = {
'host': settings.mongo.get('host'),
'port': settings.mongo.get('port')
}
defaults.update(kwargs)
@bbengfort
bbengfort / clock.py
Last active August 29, 2015 14:09
A simple date time string printing program.
#!/usr/bin/env python
# clock
# Prints out the time specially formatted
#
# Author: Benjamin Bengfort <benjamin@bengfort.com>
# Created: Sat Mar 08 15:29:47 2014 -0500
#
# Copyright (C) 2014 Bengfort.com
# For license information, see LICENSE.txt
#
@bbengfort
bbengfort / spark-context.py
Created February 6, 2015 17:29
spark context
from pyspark import SparkConf, SparkContext
conf = SparkConf().setAppName(“MyApp”)
sc = SparkContext(conf=conf)
@bbengfort
bbengfort / states.py
Created February 7, 2015 20:08
Compute sales by state
import csv
from datetime import datetime
from StringIO import StringIO
from collections import namedtuple
from pyspark import SparkConf, SparkContext
## Helper constants
DATE_FMT = "%Y-%m-%d %H:%M:%S" # 2013-09-16 12:23:33
@bbengfort
bbengfort / gendb.py
Created March 3, 2015 01:30
Create a fake database for testing queries.
import sqlite3
import random
def next_string(s):
strip_zs = s.rstrip('z')
if strip_zs:
return strip_zs[:-1] + chr(ord(strip_zs[-1]) + 1) + 'a' * (len(s) - len(strip_zs))
else:
return 'a' * (len(s) + 1)
@bbengfort
bbengfort / websync
Created March 18, 2015 18:56
Use this to sync your repository to the htdocs folder.
#!/bin/bash
USER=bengfort
HTDOCS=/fs/userdata/`$USER`/www
HTREPO=$HOME/repos/www/_site/
rsync -va $HTREPO $HTDOCS
find $HTDOCS -type d -exec chmod 755 {} +
find $HTDOCS -type f -exec chmod 664 {} +
@bbengfort
bbengfort / random_word.py
Created April 7, 2015 16:14
Get a random word from the Wordnik Dictionary
from random import choice
from wordnik import Wordnik
# Wordnik API settings, change these on a per app basis (or per
# server deployment basis). This module is optional, and is used
# to generate random words for the enrollment mechanism. If not
# used/installed then will default to a word list mechanism.
WORDNIK = {
'API_KEY': '16440b1037af310afad6f03fbb00b6cadc7d282a3f8ce2a6a',
'USERNAME': 'tacnetsol',
@bbengfort
bbengfort / fips_fixtures.py
Created April 16, 2015 11:43
Creates INSERT statements for BLS states (fips) and states series data.
#!/usr/bin/env python
from elmr import fips
from datetime import datetime
from elmr.models import Series
print """--
-- Inserts data for states and their related series
-- Created: %s
--