Skip to content

Instantly share code, notes, and snippets.

@jvanasco
jvanasco / setup.sql
Created September 24, 2014 18:12
PostgreSQL example - stream events
CREATE TABLE stream_user(
id SERIAL PRIMARY KEY NOT NULL
);
CREATE TABLE resource(
id SERIAL PRIMARY KEY NOT NULL,
condition_1 BOOLEAN,
condition_2 BOOLEAN,
condition_3 BOOLEAN,
condition_4 BOOLEAN,
condition_5 BOOLEAN,
@jvanasco
jvanasco / sqlalchemy_select_problem.py
Created September 26, 2014 01:02
sqlalchemy select problem
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
import sqlalchemy.exc
import pdb
from sqlalchemy.dialects import postgresql
INTERACTIVE = False
@jvanasco
jvanasco / sql.sql
Created October 10, 2014 19:05
show postgres indexes by table
-- modified from http://stackoverflow.com/questions/6777456/get-the-list-all-index-names-its-column-names-and-its-table-name-of-a-postgresq
SELECT
idx.indrelid::regclass as indexed_tabled,
i.relname as index_name,
ARRAY(
SELECT pg_get_indexdef(idx.indexrelid, k + 1, true)
FROM generate_subscripts(idx.indkey, 1) as k
ORDER BY k
) as indkey_names
FROM pg_index as idx
@jvanasco
jvanasco / sqlalchemy_query.py
Created October 24, 2014 23:30
printing sqlalchemy queries
import sqlparse
from sqlalchemy.dialects import postgresql as dialect_postgresql
# ------------------------------------------------------------------------------
def print_query(q):
"""prints a sqlalchemy query"""
print "-" * 30
@jvanasco
jvanasco / test_orm_declarative.py
Created November 6, 2014 15:29
template idea for sqlalchemy sscce
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# Use this file to build your own SSCCE
# SSCCE = Short, Self Contained, Correct (Compatible) Example
# see http://sscce.org/
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@jvanasco
jvanasco / data.py
Created January 14, 2015 16:28
sqlachemy_history
{'0.1.0': {'pypi_file_md5': 'b74ed3d0d824ffaba34fc887784db4f3',
'pypi_file_url': 'https://pypi.python.org/packages/source/S/SQLAlchemy/SQLAlchemy-0.1.0.tar.gz#md5=b74ed3d0d824ffaba34fc887784db4f3',
'pypi_url': 'https://pypi.python.org/pypi/SQLAlchemy/0.1.0',
'release_date': u'2006-02-14'},
'0.1.1': {'pypi_file_md5': 'd88344c2a5628cc05d8d70ac5ddbe8ee',
'pypi_file_url': 'https://pypi.python.org/packages/2.4/S/SQLAlchemy/SQLAlchemy-0.1.1-py2.4.egg#md5=d88344c2a5628cc05d8d70ac5ddbe8ee',
'pypi_url': 'https://pypi.python.org/pypi/SQLAlchemy/0.1.1',
'release_date': u'2006-02-23'},
'0.1.2': {'pypi_file_md5': '74862475a8366f74ccca6ca1ce9b0c99',
'pypi_file_url': 'https://pypi.python.org/packages/2.4/S/SQLAlchemy/SQLAlchemy-0.1.2-py2.4.egg#md5=74862475a8366f74ccca6ca1ce9b0c99',
@jvanasco
jvanasco / app.py
Created January 21, 2015 20:25
pyramid and render_to_resposne
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.renderers import render_to_response, render
def json_bad(request):
return render_to_response('json', {'hello': 'world'})
def json_good(request):
return render_to_response('json', {'hello': 'world'}, request=request)
@jvanasco
jvanasco / example-association_proxy.py
Created February 11, 2015 19:13
association proxy example
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# Use this file to build your own SSCCE
# SSCCE = Short, Self Contained, Correct (Compatible) Example
# see http://sscce.org/
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@jvanasco
jvanasco / 01-jv
Created March 5, 2015 19:32
Tech Support Exchange with Dreamhost, in which they completely ignore the question I ask.
I've been getting A TON of spam hitting my inbox lately. 20+ messages a day.
sometimes more. Usually in the topics of :
- Medicare
- Rewards cards (amazon, home depot)
- Background Checks
- Lawsuits
- EZPass
- Sex offender notification
- Auto Warranty
@jvanasco
jvanasco / view.py
Created March 9, 2015 18:37
pyramid finished_callbacks change
from pyramid.view import view_config
def sample_callback(request):
pass
@view_config(route_name='home', renderer='templates/mytemplate.pt')
def my_view(request):
"""
1.6/master
BEFORE: request.finished_callbacks None