Skip to content

Instantly share code, notes, and snippets.

View bengolder's full-sized avatar

Ben Golder bengolder

  • Binti
  • Oakland, CA, USA
  • 01:55 (UTC -07:00)
View GitHub Profile
@bengolder
bengolder / gist:2668879
Created May 12, 2012 20:44
xls to objs
import xlrd
def xlsToObjs(filePath, headers=True):
'''converts xls rows to a list of dictionaries. first row headers become
the attribute names.'''
wb = xlrd.open_workbook(filePath)
sheet = wb.sheet_by_index(0)
if headers:
# get the first row
@bengolder
bengolder / gist:2709743
Created May 16, 2012 11:42
Quick Git Guide [written in markdown]

Git, used along with Github, is a great way to manage the work of writing code. It allows you to collaborate easily on even very large-scale projects, and provides a great place to quickly host code for sharing it with others. If you're going to write significant amounts of code, I highly recommend using it.

Below is a list of commented Git commands in rough order of probable workflow. I use this as a quick reference for using Git. If you happen to want to add comments or questions, I'm making this blog entry into a Github Gist. You can view it here.

git init #start a repo
git add mynewfile.py #track a file
git rm --cached myoldfile.py #untrack a file
git commit -m 'my commit message' #commit changes with a note 
git push -u origin master # push to the 'master' branch on the 'origin' remote

git branch mynewbranch #create a new branch

@bengolder
bengolder / gist:2777462
Created May 23, 2012 20:10
data_loader
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import codecs
import json
import Rhino
import scriptcontext
@bengolder
bengolder / gist:2794874
Created May 26, 2012 18:33
GhPython import script
import sys
from scriptcontext import sticky
if packages and import_names: # if there are inputs
for package in packages:
# for each package path
if package not in sys.path:
# check to see if the path has already been added
sys.path.append(package)
print '%s appended' % package
@bengolder
bengolder / inverse_weave.py
Created May 30, 2012 10:07
the inverse of the Weave component. A branch histogram builder.
#http://www.grasshopper3d.com/forum/topics/list-dispatching-to-multiple-streams-in-non-regular-pattern?commentId=2985220%3AComment%3A606928
import Rhino
# for accesssing GH classes
import clr
clr.AddReference("Grasshopper")
from Grasshopper.Kernel.Data import GH_Path
from Grasshopper import DataTree
@bengolder
bengolder / gist:2864061
Created June 3, 2012 16:19
sample_data.py
sample_points = [
(9.129418, -9.07691, 2.189499),(9.068806, -9.436312, 2.169872),(7.228482, -12.298646, 1.673529),(6.610804, -13.367169, 1.557802),(6.099671, -13.722883, 1.471599),(6.049771, -14.078394, 1.472765),(5.59068, -14.078394, 1.398627),(4.178113, -14.433717, 1.223469),(1.001489, -15.143864, 1.109816),(-1.466872, -15.143864, 1.312266),(-3.481975, -15.498721, 1.769435),(-5.707033, -15.498721, 2.471486),(-6.428483, -15.498721, 2.740726),(-7.164778, -14.433717, 3.170362),(-6.943609, -13.722883, 3.172027),(-6.832542, -12.298646, 3.358559),(-6.134195, -9.07691, 3.591536),(-4.887777, -5.092828, 3.577759),(-3.647267, -1.037722, 3.48909),(-2.341267, 2.346474, 3.10878),(-1.305361, 3.869542, 2.570286),(-1.191264, 4.251947, 2.555705),(-0.784827, 4.634974, 2.320426),(-0.199808, 4.634974, 1.904199),(0.388818, 4.634974, 1.524931),(1.861104, 3.487776, 0.645111),(5.608429, 1.967427, 0.450671),(8.724817, -0.291138, 1.628727),(10.390653, -0.664819, 2.372696),(12.918046, -1.409862, 3.556802),(13.371179, -1.409862, 3.758
@bengolder
bengolder / gist:3031095
Created July 2, 2012 04:24
SplitCurves
import Rhino
import clr
clr.AddReference("Grasshopper")
from Grasshopper.Kernel.Data import GH_Path
from Grasshopper import DataTree
def boxes_overlap(boxA, boxB):
"""Check if there is any overlap between two bounding boxes.
"""
@bengolder
bengolder / gist:3212071
Created July 30, 2012 23:53
virtualenv aliases
# virtualenv aliases
# http://blog.doughellmann.com/2010/01/virtualenvwrapper-tips-and-tricks.html
alias v='workon'
alias v.deactivate='deactivate'
alias v.mk='mkvirtualenv --no-site-packages'
alias v.mk_withsitepackages='mkvirtualenv'
alias v.rm='rmvirtualenv'
alias v.switch='workon'
alias v.add2pth='add2virtualenv'
alias v.cdsitepackages='cdsitepackages'
@bengolder
bengolder / gist:3212242
Created July 31, 2012 00:21
Some Python Mac Dev shortcuts for .bashrc
# .bashrc for mac
# Some shorcuts useful for navigation and directory listings
alias ll='ls -l -A'
alias la='ls -A'
alias l='ls -CF'
alias .='open .'
alias ..='cd ..'
alias ...='cd .. ; cd ..'
alias ~='cd ~'
@bengolder
bengolder / gist:3278915
Created August 6, 2012 22:13
localcode upload view
def upload(request):
"""A view for uploading new data.
"""
user=User.objects.get(username='carlos')
#print request
if request.method == 'POST':
upload = UploadEvent(user=user)
upload.save()
formset = ZipFormSet(request.POST, request.FILES)
for form in formset: