Skip to content

Instantly share code, notes, and snippets.

View benhosmer's full-sized avatar

Ben Hosmer benhosmer

View GitHub Profile
@benhosmer
benhosmer / Drush on OS X
Last active December 10, 2015 02:38
Drush on OS X with MAMP
# Use Homebrew to install drush
$ brew install drush
# Mysql Command Line and PHP to .bash_profile
export PATH=/Applications/MAMP/bin/php/php5.3.6/bin:$PATH
$ sudo mkdir /var/mysql
$ sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
@benhosmer
benhosmer / natural-scroll.sh
Created December 24, 2012 12:01
"natrual" scrolling for linux
echo "pointer = 1 2 3 5 4 7 6 8 9 10 11 12" > ~/.Xmodmap && xmodmap ~/.Xmodmap
@benhosmer
benhosmer / upload-json-solr.py
Created December 11, 2012 02:02
This python script sends a json file to SOLR 4
#!/usr/bin/env python
import urllib2
import json
import string
jsonfile = open('single-geojson-sample.json', 'r')
entry = jsonfile.readlines()
req = urllib2.Request('http://localhost:8983/solr/omar/update/json?commit=true')
@benhosmer
benhosmer / single-solr-geojson.json
Created December 5, 2012 20:57
An example json file for polygons in apache solr
[{ "id": 101,
"coordinates": "POLYGON (( 100.0 0.0, 101.0 0.0, 101.0 1.0, 100.0 1.0, 100.0 0.0 ))"
}]
@benhosmer
benhosmer / sample.py
Created November 12, 2012 11:41
Using python doctests.
"""
An example of using doctest to automatically test.
One function that adds items together.
>>> adder(1,2)
3
"""
def adder(x,y):
@benhosmer
benhosmer / unit-test.py
Created November 7, 2012 15:26
Python Unit Test Notes
import unittest
# Here's our "unit".
def IsOdd(n):
return n % 2 == 1
def IsaString(text):
#text = "Hello"
text = ['apples', 'bananas']
return type(text)
@benhosmer
benhosmer / Vagrantfile
Created October 24, 2012 12:17
My Sample Salty-Vagrant Vagrantfile.
Vagrant::Config.run do |config|
config.vm.box = "bensprecise64"
config.vm.network :hostonly, "192.168.33.19"
## Use all the defaults:
config.vm.provision :salt do |salt|
salt.run_highstate = true
## Optional Settings:
salt.minion_config = "salt/minion.conf"
@benhosmer
benhosmer / app.py
Created October 23, 2012 22:34
Python Flask notes
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return "Hello World!"
@app.route('/hello/')
@app.route('/hello/<name>')
def hello(name=None):
@benhosmer
benhosmer / app.py
Created October 22, 2012 11:00
bottle.py notes
from bottle import route, run, static_file, request, abort, redirect, view, template
import re
# Serve a static html with templates
# Create an index.tpl and save it in /views
'''
#Sample index.tpl
<html>
<head>
<link rel="stylesheet" type="text/css" href="/static/styles.css" />
@benhosmer
benhosmer / wsgi.py
Created October 21, 2012 11:21
Using bottle with appfog
import os
from bottle import Bottle, route, run
application = app = Bottle()
@app.route('/')
def index(name=['hello', 'World', 'from <a href="http://appfog.com">Appfog!</a>']):
return '<br>'.join(name)