Skip to content

Instantly share code, notes, and snippets.

View cchurch's full-sized avatar
🤖
I'm not a robot.

Chris Church cchurch

🤖
I'm not a robot.
View GitHub Profile
@cchurch
cchurch / ko_options.html
Created August 24, 2014 21:28
BeautifulSoup4 example to parse Yahoo finance page
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>KO Options | Coca-Cola Company (The) Common Stock - Yahoo! Finance</title><script type="text/javascript" src="http://l.yimg.com/a/i/us/fi/03rd/yg_csstare_nobgcolor.js"></script><link rel="stylesheet" href="http://l.yimg.com/zz/combo?kx/yucs/uh3/uh/1075/css//uh_non_mail-min.css&amp;kx/yucs/uh_common/meta/3/css/meta-min.css&amp;kx/yucs/uh3/top_bar/317/css/no_icons-min.css&amp;kx/yucs/uh3/search/css/588/blue_border-min.css&amp;kx/yucs/uh3/breakingnews/css/1/breaking_news-min.css&amp;kx/yucs/uh3/get_the_app/145/css/get_the_app-min.css&amp;kx/yucs/uhc/alert/134/css/alert-min.css&amp;bm/lib/fi/common/p/d/static/css/2.0.356945/2.0.0/mini/yfi_yoda_legacy_lego_concat.css&amp;bm/lib/fi/common/p/d/static/css/2.0.356945/2.0.0/mini/yfi_symbol_suggest.css&amp;bm/lib/fi/common/p/d/static/css/2.0.356945/2.0.0/mini/yui_helper.css&amp;bm/lib/fi/common/
@cchurch
cchurch / hosts
Created August 13, 2014 13:08
Sample executable inventory script to read an INI and output in JSON for Ansible.
# Sample hosts file in INI format.
[webservers]
web1.example.com ansible_ssh_host=w1.example.net
web2.example.com ansible_ssh_port=1022
[webservers:vars] # Comment on a section
webvar=blah # Comment on an option
[dbservers]
@cchurch
cchurch / ansible.cow
Created April 18, 2014 17:33
Custom Cowsay file with (A) for Ansible
$the_cow = <<"EOC";
$thoughts ^__^
$thoughts ($eyes)\\_______
(__)\\ (A) )\\/\\
$tongue ||----w.|
|| ||
EOC
@cchurch
cchurch / custom_aggregate.py
Created November 26, 2013 03:42
Custom Django aggregate function for replacing average value of NULL with 0.
import django.db.models.sql.aggregates
import django.db.models.aggregates
class AvgWithZeroForNull(django.db.models.sql.aggregates.Avg):
sql_template = 'COALESCE(%(function)s(%(field)s), 0)'
django.db.models.sql.aggregates.AvgWithZeroForNull = AvgWithZeroForNull
class AvgWithZeroForNull(django.db.models.aggregates.Avg):
name = 'AvgWithZeroForNull'
django.db.models.aggregates.AvgWithZeroForNull = AvgWithZeroForNull
@cchurch
cchurch / test.yml
Created November 4, 2013 18:52
Simple test Ansible playbook.
---
- hosts: all
connection: local
tasks:
- name: ping
action: ping
@cchurch
cchurch / generate_sortable_version.py
Created October 31, 2013 17:33
Generate sortable version number...
from pkg_resources import parse_version
def generate_sortable_version(version):
'''
Generate a flat string from a version number than can be sorted with normal
string comparisons.
'''
return '|'.join(['%-8s' % x for x in parse_version(version)])
@cchurch
cchurch / manage.py
Created July 24, 2013 02:46
Django manage.py example to support .pyc files.
#!/usr/bin/env python
import os
import sys
def find_commands(management_dir):
# Modified version of function from django/core/management/__init__.py.
command_dir = os.path.join(management_dir, 'commands')
commands = []
try:
for f in os.listdir(command_dir):