Skip to content

Instantly share code, notes, and snippets.

View sligodave's full-sized avatar

David Higgins sligodave

View GitHub Profile
import sublime
import sublime_plugin
import re
import json
from xml.dom.minidom import *
from os.path import basename
from copy import copy
from xml.sax.saxutils import escape, unescape
@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 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"}
]
@sligodave
sligodave / Default (Linux).sublime-keymap
Last active December 23, 2015 00:28
A simple sublime text plugin to change the syntax of every opened or new file to YAML. Drop the file "SyntaxToYAML.py" into your Sublime Text "Packages/User/" directory. Add the keymaps to the files with the same name in your "Packages/User/" directory too. DON'T overwrite the "Default (XXX).sublime-keymap" files that are already there. Add to t…
[
// Change the syntax of the current file to YAML
{ "keys": ["ctrl+alt+y"], "command": "change_syntax", "args": {"syntax": "Packages/YAML/YAML.tmLanguage"}}
]