Skip to content

Instantly share code, notes, and snippets.

View ewr's full-sized avatar

Eric Richardson ewr

View GitHub Profile
@ewr
ewr / gist:5e79dda66d630ed44e04
Last active August 29, 2015 14:24
ES Podcast Metrics Query
{
"query":{
"constant_score":{
"filter":{
"and":[
{"term":{
"nginx_host.raw":"media.scpr.org"
}},
{"terms":{
"qvia":["podcast"]
@ewr
ewr / nginx_filter
Created July 10, 2015 16:40
KPCC Logstash Config for Podcasts
filter {
if [type] == "nginx" {
grok {
match => ["message", "%{NGINXACCESS}" ]
}
grok {
match => ["request","%{URIPATH:request_path}(?:%{URIPARAM:request_params})?"]
}
date {
match => [ "timestamp", "dd/MMM/yyyy:HH:mm:ss Z", "dd/MMM/yyyy:HH:mm:ss" ]
@ewr
ewr / download.rb
Created February 27, 2013 22:45
Backup and upload scripts for migrating from one Chef server to another.
# disable JSON inflation
JSON.create_id = "no_thanks"
out_dir = "BACKUP"
Dir.mkdir(out_dir)
["nodes","clients","roles"].each do |t|
Dir.mkdir( File.join( out_dir, t) )
names = api.get(t).keys
names.each do |name|
@ewr
ewr / session_store.rb
Created March 13, 2012 15:27
Rails-compatible Django Cookie Sessions. More explanation at http://ericrichardson.com/2012/03/1786-making-django-and-rails-play-nice-part-2
# Be sure to restart your server when you modify this file.
class JSONVerifier < ActiveSupport::MessageVerifier
def verify(signed_message)
raise InvalidSignature if signed_message.blank?
data, digest = signed_message.split("--")
if data.present? && digest.present? && secure_compare(digest, generate_digest(data))
ActiveSupport::JSON.decode(Base64.decode64(data.gsub('%3D','=')))
@ewr
ewr / view.py
Created November 2, 2011 03:26
Interleave multiple content types by timestamp
# -- find content by bylines -- #
# HACK -- This is hardcoded to news stories, blog entries and show segments for now
finder = ContentByline.objects.raw("""
select
contentbase_contentbyline.id,
contentbase_contentbyline.object_id,
contentbase_contentbyline.content_type_id,
COALESCE(news_story.published_at,shows_segment.created_at,blogs_entry.published_at) as pub_date
from
@ewr
ewr / cache.py
Created August 4, 2011 21:57
Object-Aware Cache
from django.core.cache import cache
DEFAULT_TIMEOUT = 0
SET_PREFIX = "obj:"
FSET_PREFIX = "sobj:"
def set(key,val,timeout = DEFAULT_TIMEOUT,objects = []):
"""
Unlike the normal django / redis cache, ContentCache takes a collection
of objects that this cache depends on. This allows the cache to be