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 / remove_dupes.sql
Created January 20, 2014 14:53
Remove duplicate records from Postgres table
DELETE FROM table USING same_table an_alias
WHERE table.field1 = an_alias.field1 AND table.field2 = an_alias.field2
AND
-- this condition determines which of the duplicates will be eliminated
table.max_field < an_alias.max_field
CREATE OR REPLACE FUNCTION insta5.next_id(OUT result bigint) AS $$
DECLARE
our_epoch bigint := 1314220021721;
seq_id bigint;
now_millis bigint;
shard_id int := 5;
BEGIN
SELECT nextval('insta5.table_id_seq') %% 1024 INTO seq_id;
SELECT FLOOR(EXTRACT(EPOCH FROM clock_timestamp()) * 1000) INTO now_millis;
@brent-hoover
brent-hoover / test_settings_context.py
Created January 20, 2014 13:41
Calling context manager that changes settings while running tests
with self.settings(LOGIN_URL='/other/login/'):
@brent-hoover
brent-hoover / dict_logging.py
Created January 20, 2014 13:39
Dictionary based logging config
import logging
from logging.config import dictConfig
from logsettings import LOG_SETTINGS
dictConfig(LOG_SETTINGS)
logger = logging.getLogger('reservation.requests')
logger.setLevel(logging.DEBUG)
@brent-hoover
brent-hoover / domready.js
Created January 20, 2014 13:37
For some reason I can never remember this syntax
$(document).ready(function() {
// Handler for .ready() called.
});
@brent-hoover
brent-hoover / check_for_dir.sh
Created January 20, 2014 13:35
Check for File
DIR="/etc"
if [ -d $DIR ]; then
echo "Folder ${DIR} exists"
else
echo "Folder ${DIR} does NOT exists"
fi
@brent-hoover
brent-hoover / find_examples.sh
Created January 20, 2014 13:33
Examples of using the find command for various uses
# find files accessed in the last 7 days
find . -type f -atime -7 -print
# file files greater than 2k
find . -type f -size +2k
#File size specifiers
#b 512 byte blocks
#c bytes
#w two byte words
#k Kilobyte
@brent-hoover
brent-hoover / fullscreen.js
Created January 20, 2014 13:27
Full Screen Video Example. This is a cross-browser way to do full-screen browser and accept the ESC key to return to normal.
var videoElement = document.getElementById("myvideo");
function toggleFullScreen() {
if (!document.mozFullScreen && !document.webkitFullScreen) {
if (videoElement.mozRequestFullScreen) {
videoElement.mozRequestFullScreen();
} else {
videoElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
@brent-hoover
brent-hoover / engines.py
Created January 16, 2014 06:53
sql alchemy engine syntax
dialect+driver://user:password@host/dbname[?key=value..]
engine = create_engine('postgresql+psycopg2://scott:tiger@localhost/mydatabase')
engine = create_engine('sqlite:///foo.db')
# Author: Jacob Kristhammar, 2010
#
# Updated version of websocket.py[1] that implements latest[2] stable version
# of the websocket protocol.
#
# NB. It's no longer possible to manually select which callback that should
# be invoked upon message reception. Instead you must override the
# on_message(message) method to handle incoming messsages.
# This also means that you don't have to explicitly invoke
# receive_message, in fact you shouldn't.