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 / counts.js
Created June 19, 2014 14:47
Run via mongo cps < counts.js - will extract the active flag issues in Mongo.
print("Starting analysis of active flag on products count");
print("This may take a little while, please wait ....");
var active = db.products.find({active:true}).count();
var inactive = db.products.find({active:false}).count();
var null_flag = db.products.find({active:null}).count();
var products = db.products.find().count();
var has_flag = db.products.find({active:{$exists:true}}).count();
var no_flag = db.products.find({active:{$exists:false}}).count();
@bbengfort
bbengfort / update_categories.js
Created June 26, 2014 00:12
Update categories in Mongo
db.categories.update({slug:"root.v2.tops"}, {$set: {display_name:"All Shirts and Sweaters"}}, {multi:false});
db.categories.update({slug:"root.v2.bottoms"}, {$set: {display_name: "All Pants and Shorts"}}, {multi:false});
db.categories.update({slug:"root.v2.dresses"}, {$set: {display_name: "All Dresses"}}, {multi:false});
db.categories.update({slug:"root.v2.suits"}, {$set: {display_name: "All Suits and Jackets"}}, {multi:false});
db.categories.update({slug:"root.v2.activewear"}, {$set: {display_name:"All Activewear"}}, {multi:false});
db.categories.update({slug:"root.v2.outerwear"}, {$set: {display_name:"All Outerwear"}}, {multi:false});
db.categories.update({slug:"root.v2.underwear"}, {$set: {display_name:"All Underwear"}}, {multi:false});
db.categories.update({slug:"root.v2.shoes"}, {$set: {display_name: "All Shoes"}}, {multi:false});
db.categories.update({slug:"root.v2.accessories"}, {$set: {display_name:"All Accessories"}}, {multi:false});
@bbengfort
bbengfort / emails1.csv
Created August 14, 2014 16:48
A CSV reader that can handle different field lables
first_name last_name email
ben bengfort bbengfort@gmail.com
sean murphy murphsp1@gmail.com
bob jones bob@example.com
@bbengfort
bbengfort / nba.py
Created August 21, 2014 17:53
Graphing NBA data for quick analysis
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
PATH = os.path.abspath('nba_players.csv')
def read_data(path=PATH):
return pd.DataFrame(pd.read_csv(PATH))
@bbengfort
bbengfort / person.py
Created August 28, 2014 17:54
Internal Accessor
class Person(object):
def __init__(self, name, age, profile):
self.name = name
self.age = age
self.profile = profile
def __getattr__(self, key):
if hasattr(self, key):
return getattr(self, key)
@bbengfort
bbengfort / coursenotes.py
Created September 5, 2014 01:08
Needlessly complex course date generation tool.
#!/usr/bin/env python
# coursenotes
# A helper to come up with Course Notes Titles
#
# Author: Benjamin Bengfort <benjamin@bengfort.com>
# Created: Thu Sep 04 15:00:55 2014 -0400
#
# Copyright (C) 2014 Bengfort.com
# For license information, see LICENSE.txt
#
@bbengfort
bbengfort / strunk.py
Last active August 29, 2015 14:06
In class example for Georgetown Data Analytics (Software Engineering) Cohort 2
"""
Code for class
"""
tooshort = ["a", "an", "the", "at", "by", "for", "in", "of", "on", "to",
"up", "and", "as", "but", "it", "or", "nor"]
def apa_title(text):
"""
@bbengfort
bbengfort / weather.py
Created September 13, 2014 17:16
In Class example for Georgetown Data Analytics (Software Engineering) Cohort 2
import json
import requests
weather_url = "http://api.openweathermap.org/data/2.5/weather?q="
def kelvin_to_fahr(temp):
return ((9/5.0) * (temp-273) + 32)
def get_weather(city):
url = weather_url + city
@bbengfort
bbengfort / wordcount.py
Created September 13, 2014 18:34
Afternoon Example for Georgetown Software Engineering Cohort II
def word_count(path):
counts = {
'line': 0,
'word': 0,
'char': 0
}
with open(path, 'r') as f:
for line in f:
@bbengfort
bbengfort / overload.go
Created October 10, 2014 00:35
Demonstration of overloading in Go
package main
import (
"fmt"
)
type A struct{
name string
}