Skip to content

Instantly share code, notes, and snippets.

View brent-hoover's full-sized avatar
🏠
Working from home

Brent Hoover brent-hoover

🏠
Working from home
View GitHub Profile
@brent-hoover
brent-hoover / showssh.py
Created March 27, 2013 04:30
A small utility for listing or searching your SSH config file
#!/usr/bin/env python
import os
import argparse
def convert_to_types(configs):
config_list = list()
for i, x in enumerate(configs):
v = x.strip().split(' ')
@brent-hoover
brent-hoover / flake8hook.py
Created March 27, 2013 14:42
Flake8 Git Commit hook
#!/usr/bin/env python
import sys
from flake8.hooks import git_hook
COMPLEXITY = 10
STRICT = False
if __name__ == '__main__':
sys.exit(git_hook(complexity=COMPLEXITY, strict=STRICT, ignore='E501'))
# Alternatively
@brent-hoover
brent-hoover / Get Raw Query
Created March 28, 2013 17:44
How to show the raw query string from a django orm queryset
from django.db import DEFAULT_DB_ALIAS
queryset.query.get_compiler(DEFAULT_DB_ALIAS).as_sql()
# -*- coding: utf-8 -*-
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field
from crispy_forms.bootstrap import AppendedText, PrependedText, FormActions
class MessageForm(forms.Form):
text_input = forms.CharField()
@brent-hoover
brent-hoover / gist:5316753
Created April 5, 2013 05:00
HSTORE Query examples
CREATE TABLE foo (myid int, hdata hstore);
INSERT INTO foo VALUES (10, '"name"=>"fred", "department"=>"IT"');
SELECT hdata->'name' FROM foo WHERE id = 10;
SELECT hdata->'department'
FROM foo

Types of index scans

Indexes

Sequential Scan:

  • Read every row in the table
  • No reading of index. Reading from indexes is also expensive.
# Copyright 2012 Erlware, LLC. All Rights Reserved.
#
# This file is provided to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
-- An audit history is important on most tables. Provide an audit trigger that logs to
-- a dedicated audit table for the major relations.
--
-- This file should be generic and not depend on application roles or structures,
-- as it's being listed here:
--
-- https://wiki.postgresql.org/wiki/Audit_trigger_91plus
--
-- This trigger was originally based on
-- http://wiki.postgresql.org/wiki/Audit_trigger
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best
@brent-hoover
brent-hoover / unordered_nav.html
Created September 22, 2013 03:12
Style unordered list as nav
<html>
<style>
* {
margin: 0;
padding: 0;
}
nav {
margin: 50px;
}