Skip to content

Instantly share code, notes, and snippets.

(custom-set-variables
'(auto-save-file-name-transforms (quote ((".*" "~/.emacs.d/autosaves/\\1" t))))
'(backup-directory-alist (quote ((".*" . "~/.emacs.d/backups/")))))
;; create the autosave dir if necessary, since emacs won't.
(make-directory "~/.emacs.d/autosaves/" t)
def __set__(self, instance, value):
"""Descriptor for assigning a value to a field in a document.
"""
if isinstance(self.field, EmbeddedDocumentField) and:
list_of_docs = list()
for doc in value:
if isinstance(doc, dict):
doc_obj = self.field.document_type_obj(**doc)
doc = doc_obj
list_of_docs.append(doc)
@gone
gone / gist:1342053
Created November 5, 2011 21:36
PDB bug
Inside of PDB
(Pdb) x = ifilterfalse(lambda field: isinstance(field, int), [1,2])
(Pdb) list(x)
*** Error in argument: '(x)'
In normal repl
>>> x = ifilterfalse(lambda field: isinstance(field, int), [1,2])
@gone
gone / gist:1360901
Created November 12, 2011 18:19
flymake-show-error-at-point
(defun show-fly-err-at-point ()
"If the cursor is sitting on a flymake error, display the
message in the minibuffer"
(interactive)
(let ((line-no (line-number-at-pos)))
(dolist (elem flymake-err-info)
(if (eq (car elem) line-no)
(let ((err (car (second elem))))
(message "%s" (fly-pyflake-determine-message err)))))))
@gone
gone / gist:1367742
Created November 15, 2011 17:40
mongrel2 request object brubeck
if self.headers['METHOD'] == 'JSON':
self.data = json.loads(body)
else:
self.data = {}
# populate arguments with QUERY string
self.arguments = {}
if 'QUERY' in self.headers:
query = self.headers['QUERY']
class APIableMixin(object):
def __init__(self, brubeck=None, queryset=None):
#create class with self as model and queryset to pull them
#register new class to routes
#register itself with brubeck's manafest
class AutoAPIBase(JSONMessageHandler):
def __init__(self, queryset):
#one url to rule them all
url = foo/(P?<item_ids>[\d;]*) # note star - so foo/ matches
class somekindofhandler(handlerthing):
def get(self, item_ids=None):
if ';' in item_ids:
return do_collection_logic
elif item_ids != "":
return do_single_logic
else:
option 1:
url_dicts, url_args = url_check.groupdict(), url_check.groups()
if url_dicts:
do_thing(**url_dicts)
else:
do_thing(*url_args)
option 2:
@gone
gone / gist:2377846
Created April 13, 2012 15:49
dining philsophers
package main
import (
"log"
"os"
"sync"
"time"
)
@gone
gone / gist:2378360
Created April 13, 2012 17:00
working philosophers
package main
import (
"log"
"os"
"sync"
"time"
)
var logger = log.New(os.Stdout, "", 0)