Skip to content

Instantly share code, notes, and snippets.

View starsinmypockets's full-sized avatar

Paul Walker starsinmypockets

View GitHub Profile
""" Imports json in a standard format to Django objects """
import json, re, logging, sqlite3
from redisclg import RedisBayes
logging.basicConfig(filename='/root/py-proj/clg-env/clg_proj/logfile.log',level=logging.DEBUG)
class BaseImporter(object):
# @@TODO add file_path param to init
def __init__(self, src, list_id, db_src="clg_proj.sqlite3"):
self.list_id = list_id
""" Imports json in a standard format to Django objects """
import json, re, logging, sqlite3
from redisclg import RedisBayes
logging.basicConfig(filename='/root/py-proj/clg-env/clg_proj/logfile.log',level=logging.DEBUG)
class BaseImporter(object):
# @@TODO add file_path param to init
def __init__(self, src, list_id, db_src="clg_proj.sqlite3"):
self.list_id = list_id
@starsinmypockets
starsinmypockets / importer.py
Last active December 11, 2015 22:29
Imports json to django objects and creates keyword and bigram sets, by pk, for data mining.
""" Imports json in a standard format to Django objects """
import json, re, logging, sqlite3
from redisclg import RedisBayes
logging.basicConfig(filename='/root/py-proj/clg-env/clg_proj/logfile.log',level=logging.DEBUG)
class BaseImporter(object):
# @@TODO add file_path param to init
def __init__(self, src, list_id, db_src="clg_proj.sqlite3"):
self.list_id = list_id
@starsinmypockets
starsinmypockets / gist:5172904
Created March 15, 2013 20:31
Shell script to initialize theme for drupal 7
#!/bin/bash
function show_usage {
echo "Usage: $0 theme_name"
exit 1
}
if [ $# -ne 1 ]; then
show_usage
fi
@starsinmypockets
starsinmypockets / .gitignore
Created March 18, 2013 17:04
.gitignore for Drupal 6
# Ignore configuration files that may contain sensitive information.
sites/*/settings*.php
# Ignore various other cruft
.DS_Store
.buildpath
.project
.settings
/backup
/tmp
#! /bin/bash
# Installs django into virtual environment with dependencies
# usage: pdjang project-name
# thanks to github/jart whose django-bone forms the basis of this
# Define a bunch of silly variables
proj=$1
projRoot="/root/py-proj"
envName="$1-env"
envDir="$projRoot/$envName"
projName="$1_proj"
@starsinmypockets
starsinmypockets / lazy-properties.py
Last active December 19, 2015 06:19
Lazy pattern for expensive class properties.
# Lazily evaluate class properties in Python.
# Only loads properties if needed.
# Use for expensive operations.
# by Steven Loria https://gist.github.com/sloria
# The slow way -- DON'T DO THIS
class Person:
def __init__(self, name, occupation):
self.name = name
self.occupation = occupation
@starsinmypockets
starsinmypockets / price_validator.py
Last active December 19, 2015 06:19
Evaluate price strings based on regex.
# A regex-based price string validator
# Author: Paul Walker
class PriceValidator(object):
""" Takes a price string and validates price, unit type, and unit value. """
def __init__(self, item_raw):
try:
self.price_string = str(item_raw['price'])
self.description = str(item_raw['description'])
except ValueError, e:
@starsinmypockets
starsinmypockets / dragon.el
Created July 7, 2013 16:44
contains the elisp needed to make Emacs respond correctly to dragon's correction code and to accept non-ASCII characters like ï
;;;
;;; dragon.el: code to smooth out the Dragon NaturallySpeaking/Gnuemacs
;;; interaction
;;;
;;;
;;; This code does not make Gnuemacs fully select-and-say, but you
;;; will be able to select and correct your dictation to Emacs since
;;; you last issued a voice command or clicked the mouse. It also
;;; allows you to correctly dictate text containing non-ASCII
;;; characters like accented letters to Emacs.
@starsinmypockets
starsinmypockets / carousel.js
Created July 8, 2013 21:00
Carousel in js by seanpaul