Skip to content

Instantly share code, notes, and snippets.

View Dowwie's full-sized avatar

Darin Gordon Dowwie

View GitHub Profile
@Ficik
Ficik / monokai.sh
Created November 30, 2013 22:48
Monokai theme (colors as in sublime-text-2) for guake and gnome-terminal. Just copypaste to terminal
# Guake:
COLORS="#272728282222:#ffff29292929:#a6a6e2e22e2e:#e6e6dbdb7474:#6666d9d9efef:#f9f926267272:#bebe8484ffff:#fefefffffefe:#757571715e5e:#ffff29292929:#a6a6e2e22e2e:#fdfd97971f1f:#6666d9d9efef:#f9f926267272:#aeae8181ffff:#fefefffffefe"
FOREGROUND="#F6F6F5F5EEEE"
BACKGROUND="#232325252626"
gconftool-2 -s -t string /apps/guake/style/background/color $BACKGROUND
gconftool-2 -s -t string /apps/guake/style/font/palette $COLORS
gconftool-2 -s -t string /apps/guake/style/font/color $FOREGROUND
from sqlalchemy import (
Column,
Index,
Integer,
Text,
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import engine_from_config
SELECT
sum(view_homepage) AS viewed_homepage,
sum(use_demo) AS use_demo,
sum(enter_credit_card) AS entered_credit_card
FROM (
-- Get the first time each user viewed the homepage.
SELECT
user_id,
1 AS view_homepage,
min(time) AS view_homepage_time
# here's a variant that adds a decorator like that of
# https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/BakedQuery
from sqlalchemy.orm.query import QueryContext
class BakedQuery(object):
"""an object that can produce a 'baked' Query, that is one where
its ultimately generated SQL string is cached based on how the query
has been constructed.
SELECT * FROM (
SELECT generate_series('2012-11-20'::date, '2014-01-01'::date,'1 day'::interval)::date AS day)
AS dates
LEFT JOIN (
SELECT date_trunc('day', donations_donation.created) as day,
SUM(donations_donation.amount) as amount_raised
FROM donations_donation
WHERE created >= '2012-11-20' AND created <= '2014-01-01' group by 1 ) t
USING(day)
ORDER BY 1;
@mmerickel
mmerickel / Procfile
Last active May 4, 2017 23:33
pyramid on heroku
release: ./entrypoint.sh run alembic -c site.ini upgrade head
web: ./entrypoint.sh run pserve site.ini
SELECT
sum(view_homepage) AS viewed_homepage,
sum(enter_credit_card) AS entered_credit_card
FROM (
-- Get the first time each user viewed the homepage.
SELECT
user_id,
1 AS view_homepage,
min(time) AS view_homepage_time
FROM event
@gavinwahl
gavinwahl / python_implementation
Last active April 24, 2020 23:23
Triggers to enforce referential integrity for foreign keys, if postgres didn't support them natively.
CREATE OR REPLACE FUNCTION check_fk_child() RETURNS trigger AS $$
DECLARE
fk_local TEXT := TG_ARGV[0];
parent_table TEXT := TG_ARGV[1];
fk_val INT;
is_valid BOOLEAN;
query TEXT;
BEGIN
-- fk_val = getattr(NEW, fk_local)
EXECUTE format('SELECT $1.%I', fk_local) USING NEW INTO fk_val;
@dannguyen
dannguyen / EXAMPLE_WATSON_API_README.md
Last active November 23, 2020 13:32
Transcribing ProPublica podcast with Python and Watson Speech to Text API

Using IBM Watson Speech to Text API to translate a ProPublica podcast

An example of using the Watson Speech to Text API to translate a podcast from ProPublica: How a Reporter Pierced the Hype Behind Theranos

This is just a simpler demo of the same technique I demonstrate to make automated video supercuts in this repo: https://github.com/dannguyen/watson-word-watcher

The transcription takes just a few minutes (less if you parallelize the requests to IBM) and is free...but it isn't perfect by any means. It doesn't fare super well on proper nouns:

  • Charles Ornstein's last name is transcribed as Orenstein
  • John Carreyrou's last name becomes John Kerry Roo
@mmerickel
mmerickel / cors.py
Last active December 6, 2022 14:13
cors in pyramid
from pyramid.security import NO_PERMISSION_REQUIRED
def includeme(config):
config.add_directive(
'add_cors_preflight_handler', add_cors_preflight_handler)
config.add_route_predicate('cors_preflight', CorsPreflightPredicate)
config.add_subscriber(add_cors_to_response, 'pyramid.events.NewResponse')
class CorsPreflightPredicate(object):