Skip to content

Instantly share code, notes, and snippets.

View sligodave's full-sized avatar

David Higgins sligodave

View GitHub Profile
@sligodave
sligodave / gist:2359553
Created April 11, 2012 14:14
User a list of when all users joined.
from datetime import datetime
#########################################
# Set up the django environment
#########################################
from django.core.management import setup_environ
@sligodave
sligodave / filter_through_command.py
Created May 3, 2012 15:57 — forked from jefftriplett/filter_through_command.py
Sublime Text 2: "Filter Through Command" plugin
# saved from: http://pastie.org/private/bclbdgxzbkb1gs2jfqzehg
import sublime
import sublime_plugin
import subprocess
class RunExternalCommand(sublime_plugin.TextCommand):
"""
Runs an external command with the selected text,
@sligodave
sligodave / five_alive.py
Created June 22, 2012 20:05
Keep five process running at almost all time for one minute.
import multiprocessing
import time
from os import getpid
def worker():
pid = getpid()
print 'START %d' % pid
time.sleep(3)
@sligodave
sligodave / broken_south_migration_bypass_steps.txt
Created September 6, 2012 20:06
Steps to follow when I've broken "south" migrations.
1. Delete DB
2. Create DB
3. Remove south from INSTALLED_APPS
4. syncdb
5. Insert south into INSTALLED_APPS
6. sycndb
7. migrate --fake
8. YAY!
@sligodave
sligodave / gist:3800648
Created September 28, 2012 15:54
Get all logins since 2pm pacific time based on internal saved time of central.
import datetime
# Time is Central!
d = datetime.datetime(2012, 9, 26, 14, 00)
# So we can convert our times to Pacific time
dt = datetime.timedelta(hours=2)
@sligodave
sligodave / gist:3801283
Created September 28, 2012 17:59
Register all models that extend a certain base abstract model.
from django.contrib import admin
from django.db.models import get_models, get_app
from models import BaseModel
app = get_app('app_name')
for model in get_models(app):
if issubclass(model, BaseModel):
try:
import firebirdsql
conn = firebirdsql.connect(
dsn='localhost/3050:PATH_TO_DB.fdb',
user='sysdba',
password='masterkey'
)
cur = conn.cursor()
# Get all rows from a table
@sligodave
sligodave / Default (Linux).sublime-keymap
Last active November 20, 2023 17:29
Sublime Text 3, Goto Symbol In Index Command. This brings you to the definition of the symbol currently highlighted or under the cursor in Sublime Text 3. It there are more than one options you will be presented with them to choose from. Just as with the "Goto Symbol" and "Goto Symbol in Project" commands. You must have a project defined and ope…
[
// Goto Symbol
{ "keys": ["ctrl+alt+r"], "command": "goto_symbol_in_index"}
]
@sligodave
sligodave / gist:6539531
Last active November 23, 2023 07:29
Quick example of creating, using and deleting a temp file in python
import os
import tempfile
file_descriptor, file_path = tempfile.mkstemp(suffix='.tmp')
# You can convert the low level file_descriptor to a normal open file using fdopen
with os.fdopen(file_descriptor, 'w') as open_file:
open_file.write('hello')
@sligodave
sligodave / Default (Linux).sublime-keymap
Last active December 22, 2015 22:39
A sublime text command to reload the current file and bring cursor back to current position.
[
// Reload currently active view key shortcut.
{ "keys": ["ctrl+alt+o"], "command": "reload_view"}
]