Skip to content

Instantly share code, notes, and snippets.

View zstumgoren's full-sized avatar

Serdar Tumgoren zstumgoren

View GitHub Profile
@zstumgoren
zstumgoren / simple_file_processing.py
Created April 9, 2011 17:24
Read in some data. Skip
#!/usr/bin/env python
"""
A simple script showing how to read data from a specified
file, do some basic processing, and then print out processed
lines to the shell. The input file is hard-coded in the text.
USAGE from command line
python simple_file_processing.py
@zstumgoren
zstumgoren / process_csv.py
Created April 9, 2011 18:02
Sample script on how to use Python's csv DictReader class to process tabular data.
#!/usr/bin/env python
import csv
source_file = open('/path/to/Testfile.txt','rb')
# Use the DictReader class to read in your data. This class allows you to access
# field names by name. It assumes the first line in the file contains the field names
for line in csv.DictReader(source_file, delimiter='\t'):
base_query = Casualty.safe_objects.all()
def build_chart(base_query, field_name, order_by):
'''
This is a function to make building our charts a little DRYer. Beats the pants off of lambdas.
'''
return base_query.values(field_name).annotate(Count(field_name)).order_by(order_by)
extra_context_dict = {
'theater_chart':build_chart(base_query, 'theater__name', '-theater__name__count'),
"""
A few notes:
* Lines starting with "#" signs are standard Python code comments
* Multi-line comments can be wrapped in triple-quotes (""")
"""
from itertools import islice, product
import calendar
from BeautifulSoup import BeautifulSoup
import requests
@zstumgoren
zstumgoren / georgia_leg_calendar.py
Created June 8, 2012 16:26
Scrape Georgia state leg calendar site
from BeautifulSoup import BeautifulSoup
import re
import urllib2
def main():
base_url = "http://webmail.legis.ga.gov/Calendar/"
program_url = base_url + "?Chamber=house"
html = urllib2.urlopen(program_url).read()
soup = BeautifulSoup(html)
@zstumgoren
zstumgoren / georgia_leg_calendar.py
Created June 8, 2012 16:27
Scrape Georgia state leg calendar site
import re
import urllib2
from BeautifulSoup import BeautifulSoup
def main():
base_url = "http://webmail.legis.ga.gov/Calendar/"
program_url = base_url + "?Chamber=house"
html = urllib2.urlopen(program_url).read()
soup = BeautifulSoup(html)
1 (function($) {
2 $(document).ready(function() {
3 //$.fn.opelec_inline = function() {
4 /*
5 return this.each(function(elemIndex) {
6 var inline = $(this);
7 var copy_anchor = inline.find("a.grp-copy-handler");
8 copyButtonHandler(copy_anchor);
9 console.log(elemIndex);
10 });
/**
* Copy Button modeled on Add button features from Django admin and Grappelli inlines.js
*/
var OPELEC = OPELEC || function() {};
OPELEC.inlines = {
copy: function(copy_anchor) {
// Get stacked inline container from copy button that was clicked
@zstumgoren
zstumgoren / gist:5817465
Last active December 18, 2015 17:19 — forked from sc0ttman/gist:1145418
Rails3 - CheatSheet - CommandLine
rails new ApplicationName – Create a new application
rails _3.0.9_ new ApplicationName – Create a new application with a specific version of rails
rails generate/g model ModelName – Creates a model with the specified model_name
rails generate/g controller ControllerName – Creates a controller with the specified controller_name
rails generate/g migration MigrationName – Creates a migration with the specified migration_name
rails generate/g scaffold ModelName ControllerName – A shortcut for creating your controller, model and view files etc.
rails destroy controller ControllerName – Destroys the created controller and its related file.
rails destroy model - Destroys the created model and its related file.
@zstumgoren
zstumgoren / gist:fecc7672540d757c53c1
Created August 7, 2014 18:57
nginx sample setup
server {
listen 80;
server_name watusi.inside.ap.org;
root /mnt/share_STG/rack_apps/watusi/current/public;
passenger_ruby /home/interact/.rvm/wrappers/ruby-1.9.3-p448/ruby;
passenger_enabled on;
rails_env production;
access_log /var/log/nginx/watsui.access.log;