Skip to content

Instantly share code, notes, and snippets.

View richleland's full-sized avatar

Rich Leland richleland

View GitHub Profile
@richleland
richleland / gist:1560608
Created January 4, 2012 15:41
knife ec2 randomness
rleland ~/SYSTEMS/vm-testing/chef-repo [git:master]: knife ec2 server create -r "role[intranet]" --flavor m1.small --image ami-e358958a --availability-zone us-east-1b --node-name intranet --ssh-key aws-thdev -x ubuntu --groups web --identity-file ~/.ec2/aws-thdev.pem
Instance ID: i-14c7ab76
Flavor: m1.small
Image: ami-e358958a
Region: us-east-1
Availability Zone: us-east-1b
Security Groups: web
SSH Key: aws-thdev
Waiting for server........................
@richleland
richleland / bog.html
Created December 23, 2011 03:44
bog html
<<<image:138750>>>
<h3>2011 Categories</h3>
<ul class="categories">
<li><a href="http://cnn.com/">category one</a></li>
<li><a href="http://cnn.com/">category two</a></li>
<li><a href="http://cnn.com/">category three</a></li>
<li><a href="http://cnn.com/">category four</a></li>
<li><a href="http://cnn.com/">category five</a></li>
</ul>
@richleland
richleland / apt-pgsql-chef.rb
Created December 12, 2011 16:18
apt repo setup for postgres 9
# add the postgresql 9 apt sources
# see https://launchpad.net/~pitti/+archive/postgresql for more info
# deb http://ppa.launchpad.net/pitti/postgresql/ubuntu lucid main
# deb-src http://ppa.launchpad.net/pitti/postgresql/ubuntu lucid main
apt_repository "postgres" do
uri "http://ppa.launchpad.net/pitti/postgresql/ubuntu"
components ["main"]
distribution "natty"
keyserver "keyserver.ubuntu.com"
key "8683D8A2"
import os
import random
import time
import requests
class Transaction(object):
def __init__(self):
self.custom_timers = {}
2011-11-15 13:43:43 UTC LOG: duration: 351.323 ms statement: SELECT DISTINCT "cms_contentitem"."id", "cms_contentitem"."creation_date", "cms_contentitem"."publication_date", "cms_contentitem"."modification_date", "cms_contentitem"."status", "cms_contentitem"."title", "cms_contentitem"."basename", "cms_contentitem"."description", "cms_contentitem"."category_id", "cms_contentitem"."promo_image_id", "cms_contentitem"."author_id", "cms_category"."id", "cms_category"."label", "cms_category"."basename", "cms_category"."parent_id", "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined", "cms_entry"."contentitem_ptr_id", "cms_entry"."body", "cms_entry"."_body_rendered", "cms_slideshow"."contentitem_ptr_id" FROM "cms_contentitem" INNER JOIN "cms_contentitem_tags" ON ("cms_contentitem"."id" = "cms_contentitem
<sessions>
<session name="http-example" probability="70" type="ts_http">
<request> <http url="/" method="GET" version="1.1">
</http> </request>
<request> <http url="/images/logo.gif"
method="GET" version="1.1"
if_modified_since="Fri, 14 Nov 2003 02:43:31 GMT">
</http></request>
class Chef
class Resource
class Template
# grab the internal IPs for requested nodes
def get_ec2_ips(search_criteria)
results = search(:node, search_criteria)
ips = []
results.each do |result|
nodes.push result[:ec2][:local_ipv4]
end
@richleland
richleland / settings.py
Created October 29, 2011 11:00
S3BotoStorage subclass for media and static buckets
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_STORAGE = 'path.to.storage.S3StaticStorage'
THUMBNAIL_DEFAULT_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = 'YOUR KEY'
AWS_SECRET_ACCESS_KEY = 'YOUR KEY'
AWS_STORAGE_BUCKET_NAME = 'media.YOURSITE.com'
AWS_STATIC_BUCKET_NAME = 'static.YOURSITE.com'
AWS_S3_CUSTOM_DOMAIN = AWS_STORAGE_BUCKET_NAME
AWS_STATIC_CUSTOM_DOMAIN = AWS_STATIC_BUCKET_NAME
STATIC_URL = 'http://%s/' % AWS_STATIC_BUCKET_NAME
def get_filename(self, basename):
# first try to find it with staticfiles (in debug mode)
filename = None
if self.storage.exists(basename):
try:
filename = self.storage.path(basename)
except NotImplementedError:
local_storage = get_storage_class('compressor.storage.CompressorFileStorage')()
filename = local_storage.path(basename)
# secondly try finding the file in the root
@richleland
richleland / urlpattern.py
Created September 7, 2011 14:06
urlpattern
# in urls.py
(r'^(?P<taxonomy>[-/\w]+)/', include('myapp.urls'))
# in myapp/urls.py
url(r'^articles/(?P<slug>[\w-]+)/$', ContentView.as_view(model=Article), name='content-article')
# why doesn't the url /foo/bar/baz/articles/my-article/ resolve?