Skip to content

Instantly share code, notes, and snippets.

View birkin's full-sized avatar

Birkin James Diana birkin

View GitHub Profile
@birkin
birkin / mysql_issue_workaround.py
Last active October 8, 2015 19:58
django mysql test work-around
def _mysql_storage_engine(self):
'''
birkin, 2012-08:
- working around failure on SHOW TABLE STATUS WHERE Name='INTROSPECT_TEST'
- env/lib/python2.7/site-packages/django/db/backends/mysql/base.py
- pip freeze yields Django==1.4.1 & MySQL-python==1.2.3, & mysql is v 4.1.22
'''
"Internal method used in Django tests. Don't rely on this from your code"
if self._storage_engine is None:
cursor = self.connection.cursor()
@birkin
birkin / python_threading.py
Last active October 13, 2015 00:58
python threading experimentation
import Queue, threading, urllib2
from datetime import datetime
'''queue syntax assumes python 2.5 or greater'''
CHARACTERS = 50
timer_list = []
class ThreadUrl(threading.Thread):
@birkin
birkin / django_login_handler.py
Created December 18, 2012 22:03
Handles authN & authZ, with shib & for development, creates user, & assigns permissions. Adding this class to your models.py allows gives your app a login url handled by view code like that shown below.
# -*- coding: utf-8 -*-
import json, logging
log = logging.getLogger(__name__)
class LoginManager( object ):
'''
@birkin
birkin / update_django_app.sh
Last active August 22, 2018 18:43
shell script for easily updating django app code
#!/bin/sh
## shell script for easily updating django app code
## usage, `bash ./this.sh`
## setup
ACTIVATE_FILE=""
GROUP=""
LOG_DIR_PATH=""
@birkin
birkin / views.py
Created February 28, 2013 17:55
django view function that proxys solr instances - usage: url/collection/?q=the-solr-query
def search_custom( request, collection ):
"""
Returns unmodified SELECT solr requests to settings_app.COLLECTION_MAPPER solr urls.
# possible TODO: override max_rows
"""
## check that we're only using GET requests
if request.method != 'GET':
return HttpResponseNotAllowed(['GET'])
## grab request parameter string
logger.debug( u'request.GET: %s' % request.GET )
@birkin
birkin / .gitignore (normal)
Last active December 14, 2015 16:59
tags: gitignore
# comments...
# - project_httpd.conf was often part of django_project_dir -> project_dir -> apache_dir
# now I call my wsgi file from a server .conf included into the main httpd.conf file
# - env is often sibling of project directory
# wsgi.py is usually part of django_project_dir -> project_dir -> apache_dir
*.pyc
*httpd.conf
.DS_Store
.hg
# Ignore everything
*
# But not these files...
!.gitignore
!__init__.py
!manage.py
!READ_ME.txt
@birkin
birkin / sample.html
Last active December 15, 2015 21:39
access json with jquery
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Request json test</title>
<script src="http://code.jquery.com/jquery-1.5.js"></script>
<script type="text/javascript">
$.get(
"http://library.brown.edu/projects/usep/inscription/CA.Berk.UC.HMA.G.8-3898/?format=json", // url, {"q":"some-query"}, data
function(data){
var data_div = $('div#showdata').html( data.writing );
@birkin
birkin / projectx.sublime-project
Last active September 10, 2017 12:29
Sublime_Text_2's project settings options.
{
"settings": {
"translate_tabs_to_spaces": false
},
"folders":
[
{
"path": "/path/to/dir/projectx"
},
{
@birkin
birkin / make_kakadu_jp2.py
Last active December 18, 2015 10:19
Shows how to call the kakadu library with envoy; handles paths with spaces and a source-path with apostrophes.
# -*- coding: utf-8 -*-
""" Shows how to call the kakadu library with envoy.
In particular, shows how to handle paths containing spaces.
Updated to show how to handle apostrophe in source path.
- kakadu is a jpeg2000 library
- envoy is a wrapper around the subprocess module
- kakadu: http://en.wikipedia.org/wiki/Kakadu_(software)
- envoy: https://github.com/kennethreitz/envoy
"""