Skip to content

Instantly share code, notes, and snippets.

View etscrivner's full-sized avatar
🦋

Eric Scrivner etscrivner

🦋
View GitHub Profile
class ListedProduct(object):
def __init__(self, listed_product_tuple):
"""Takes a KeyedTuple and transforms it into a listed product.
:param listed_product_tuple: A KeyedTuple
:type listed_product_tuple: sqlalchemy.KeyedTuple
"""
self.listed_product_tuple
class ApiError(Exception): pass
class User(object):
"""Represents an authenticateable user"""
def __init__(self, email, password):
self.email = email
self.password = password
@etscrivner
etscrivner / localsettings.sh
Last active August 29, 2015 14:02
Sample shell script to set environment variables for twelve-factor application
#!/bin/sh
export MY_APP_NAME=superslice
export MY_APP_AWS_KEY=super-secret
export MY_APP_AWS_SECRET_KEY=super-super-secret
# Finally, call whatever command comes after this
$*
@etscrivner
etscrivner / localsettings-example
Last active August 29, 2015 14:02
Shell command to run simple script with local settings
user@computer:~/app$ ./localsettings.sh bin/app.py --app-arg1 arg1-val --app-arg2
Welcome to superslice
['bin/app.py', '--app-arg1', 'arg1-val', '--app-arg2']
@etscrivner
etscrivner / config.py
Last active August 29, 2015 14:02
Sample interface for reading configuration files
import os
# Configuration variable names as constants
APP_NAME = 'MY_APP_NAME'
APP_AWS_KEY = 'MY_APP_AWS_KEY'
APP_AWS_SECRET_KEY = 'MY_APP_AWS_SECRET_KEY'
class Config(object):
@etscrivner
etscrivner / app.py
Last active August 29, 2015 14:02
Application using the simple config
import sys
import config
if __name__ == '__main__':
cfg = config.Config()
print 'Welcome to {}'.format(cfg.get(config.APP_NAME))
print sys.argv
@etscrivner
etscrivner / gist:4f4e02e98465a7134e8d
Created July 31, 2014 00:43
Shame ban name generator
import random
adjectives = [
'awkward', 'ginger', 'babyfaced', 'sloppy', 'hairy', 'sweaty',
'gangly', 'ugly', 'neckbeard', 'angry', 'constipated', 'wrinkly',
'porous', 'oozy', 'cuddly'
]
nouns = [
@etscrivner
etscrivner / simple-redis-client.go
Created September 17, 2014 01:16
Simple redis client in Go
package main
import (
"bytes"
"bufio"
"fmt"
"net"
"strconv"
)
@etscrivner
etscrivner / simple-redis-client.rs
Created September 17, 2014 01:16
Simple redis client in rust
use std::io::TcpStream;
use std::str;
fn main() {
let mut client = match TcpStream::connect("127.0.0.1", 6379) {
Ok(c) => c,
Err(e) => fail!("Failed: {}", e)
};
@etscrivner
etscrivner / euler1.ml
Created September 24, 2014 04:32
Euler problem 1 in ocaml
let result = List.range 1 1000
|> List.filter ~f:(fun n -> (n mod 3) = 0 || (n mod 5) = 0)
|> List.reduce ~f:(+);;