Skip to content

Instantly share code, notes, and snippets.

Avatar
🦋

Eric Scrivner etscrivner

🦋
View GitHub Profile
View gist:986adaa563ead197293b
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
View gist:c9810bd8f85800b8d185
class ApiError(Exception): pass
class User(object):
"""Represents an authenticateable user"""
def __init__(self, email, password):
self.email = email
self.password = password
@etscrivner
etscrivner / config.py
Last active Aug 29, 2015
Sample interface for reading configuration files
View config.py
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 / localsettings.sh
Last active Aug 29, 2015
Sample shell script to set environment variables for twelve-factor application
View localsettings.sh
#!/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 / app.py
Last active Aug 29, 2015
Application using the simple config
View app.py
import sys
import config
if __name__ == '__main__':
cfg = config.Config()
print 'Welcome to {}'.format(cfg.get(config.APP_NAME))
print sys.argv
@etscrivner
etscrivner / localsettings-example
Last active Aug 29, 2015
Shell command to run simple script with local settings
View localsettings-example
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']
View gist:4f4e02e98465a7134e8d
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 Sep 17, 2014
Simple redis client in Go
View simple-redis-client.go
package main
import (
"bytes"
"bufio"
"fmt"
"net"
"strconv"
)
@etscrivner
etscrivner / simple-redis-client.rs
Created Sep 17, 2014
Simple redis client in rust
View simple-redis-client.rs
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 Sep 24, 2014
Euler problem 1 in ocaml
View euler1.ml
let result = List.range 1 1000
|> List.filter ~f:(fun n -> (n mod 3) = 0 || (n mod 5) = 0)
|> List.reduce ~f:(+);;