Skip to content

Instantly share code, notes, and snippets.

View kennethreitz's full-sized avatar
🐍

Kenneth Reitz kennethreitz

🐍
View GitHub Profile
class APIRequest(Request):
want_form_data_parsed = False
data = property()
@pvh
pvh / gist:4634543
Last active December 11, 2015 17:28
Postgres: The Bits You Haven't Found talk
A Beastiary of Badassery
-
SQLisms
--
WITH
arrays and unnest
window functions
JSON
row types
@rsms
rsms / gist:3564654
Created September 1, 2012 05:33
Life is purposeless. And it is beautiful that it is purposeless

Life is purposeless. And it is beautiful that it is purposeless

It is very difficult, particularly for the Western mind, to understand that life is purposeless. And it is beautiful that it is purposeless. If it is purposeful then the whole thing becomes absurd – then who will decide the purpose? Then some God has to be conceived who decides the purpose, and then human beings become just puppets; then no freedom is possible. And if there is some purpose then life becomes businesslike, it cannot be ecstatic.

The West has been thinking in terms of purpose, but the East has been thinking in terms of purposelessness. The East says life is not a business, it is a play. And a play has no purpose really, it is nonpurposeful. Or you can say play is its own purpose, to play is enough. Life is not reaching towards some goal, life itself is the goal. It is not evolving towards some ultimate; this very moment, here and now, life is ultimate.

Life as it is, is accepted in the East. It is not moving towards some end, b

@squarism
squarism / watch_queue
Created August 4, 2012 04:47
Netflix Watch Queue
# all are on instant streaming
# from Eric Macks http://ericmackattacks.wordpress.com/2011/01/06/100-good-movies-available-to-watch-instantly-on-netflix-january-edition/
The Battleship Potemkin (1925, Sergei M. Eisenstein)
The Gold Rush (1925, Charles Chaplin)
The General (1926, Clyde Bruckman/Buster Keaton)
Man with the Movie Camera (1929, Dziga Vertov)
The Rules of the Game (1939, Jean Renoir)
Stagecoach (1939, John Ford)
The Pride of the Yankees (1942, Sam Wood)
@daltonmatos
daltonmatos / download.py
Created July 27, 2012 01:49
Simple download function with progress bar
# Requires clint (https://github.com/kennethreitz/clint) from the develop branch, because of the expected_size argument.
def download(url, to_file, chunk_size=8192):
r = requests.get(url)
size = int(r.headers['Content-Length'])
expected_size = size / chunk_size
with open(to_file, 'w') as f:
for chunk in progress.bar(r.iter_content(chunk_size=chunk_size), expected_size=expected_size):
@rtwomey
rtwomey / Heroku DB Migration.mdown
Created July 23, 2012 18:47
How to migrate a DB on heroku to another plan

Recently, I had a staging database on Heroku that was running on the Ronin database (which was originally the lowest-sized DB you could get at Heroku). Since they added two new options, Crane and Kappa, we wanted to take advantage of the cost savings. Here's how you can migrate your Ronin DB to Crane (or any other plan).

The old database was named BROWN while the new one is CRIMSON. You can determine this by running:

heroku pg:info --app myapp-staging
  1. Add Crane database

     heroku addons:add heroku-postgresql:crane --app myapp-staging
    

heroku pg:wait --app myapp-staging

@catawbasam
catawbasam / pandas_dbms.py
Last active May 26, 2024 05:32
Python PANDAS : load and save Dataframes to sqlite, MySQL, Oracle, Postgres
# -*- coding: utf-8 -*-
"""
LICENSE: BSD (same as pandas)
example use of pandas with oracle mysql postgresql sqlite
- updated 9/18/2012 with better column name handling; couple of bug fixes.
- used ~20 times for various ETL jobs. Mostly MySQL, but some Oracle.
to do:
save/restore index (how to check table existence? just do select count(*)?),
finish odbc,
#!/bin/bash
# ./clone-db COLOR from-app to-app plan
#
# example:
# ./clone-db COBALT my-production-app my-staging-app crane
#
# The COLOR is used for a grep on your config var output, so make sure it's unique.
color=$1
src=$2
@kennethreitz
kennethreitz / hstore.py
Created July 6, 2012 08:41
PostgreSQL hstore + SQLAlchemy
import collections
import sqlalchemy.types
class Hstore(sqlalchemy.types.UserDefinedType, sqlalchemy.types.MutableType):
"""The ``hstore`` type that stores a dictionary. It can take an any
instance of :class:`collections.Mapping`.
It can be extended to store other types than string e.g.::
@ielshareef
ielshareef / site_id_djangononrel_mongodb.md.md
Created June 25, 2012 04:13
Error on Django-nonrel and MongoDB: AutoField (default primary key) values must be strings representing an ObjectId on MongoDB (got u'1' instead). Please make sure your SITE_ID contains a valid ObjectId string.

Fixing SITE_ID for Django-nonrel and MongoDB

by Ismail Elshareef

Django's database setting are by default set to work with relational databases. Therefore, certain issues start popping up when you work with noSQL databases, like MongoDB.

Problem

If you're running Django-nonrel with Mongodb, you will run into an issue when you execute the following command: