Skip to content

Instantly share code, notes, and snippets.

@kingcons
kingcons / gist:1017604
Created June 9, 2011 20:13
interesting snippets
def drop_to_ipy(self, request, qs):
def fixterm():
import os; os.system('reset')
from pprint import pprint; import IPython; IPython.Shell.IPShellEmbed(argv=[])()
def admin_from_model_instance(obj):
admin.site._registry[obj.__class__].__class__
def model_from_admin_obj():
return [[k,v] for k,v in admin.site._registry.items() if v.__class__==self.__class__][0][0]
@kingcons
kingcons / django-bootstrap
Created June 17, 2011 17:56 — forked from RichardBronosky/django-bootstrap
This is my response to a thread on django-developers regarding default project layout http://groups.google.com/group/django-developers/browse_thread/thread/2b88ddc6dd68ed6
#!/usr/bin/env bash
# This script was made by a master bash hacker, hence to following 2 settings
set -o errexit
set -o nounset
cat << EOF
django-bootstrap -- generates a complete django project
usage: django-bootstrap [app_name] [project_name] [virtualenv_path/name] [admin_name (default=admin)] [admin_password (default=admin)]
@kingcons
kingcons / gist:1091320
Created July 19, 2011 04:38
A toy for burke...
;; Adapted from https://github.com/swannodette/enlive-tutorial
;; Install clojure and leiningen, clone the above repo, do lein deps, then lein repl.
;; At that point, you just have to (load "tutorial/scrape1") then (in-ns 'tutorial.scrape1)
;; then (find-mp3s "http://www.aerialnoise.com/") and you're done.
(ns tutorial.scrape1
(:require [net.cgrand.enlive-html :as html])
(:require [clojure.contrib.str-utils2 :as str]))
(defn fetch-url [url]
;; A naive translation of http://citizen428.net/blog/2010/09/04/erlang-bit-syntax-and-id3/
; Tested at the REPL with a file from the ID3V1 test suite: http://www.id3.org/Developer_Information
;; Obviously macrology could give something more akin to Erlang's bit syntax w/error handling, etc.
; See PCL chapters 24 and 25 for example...
; http://www.gigamonkeys.com/book/practical-parsing-binary-files.html
; http://www.gigamonkeys.com/book/practical-an-id3-parser.html
(defpackage :id3
(:use :cl)
(:export #:get-id3
(in-package :quickproject)
(defvar *after-make-project-hooks* nil
"A list of functions to call after MAKE-PROJECT is finished making a
project. It is called with the same arguments passed to
MAKE-PROJECT, except that NAME is canonicalized if necessary.")
;; TODO: Instead of &key docs do (when (stringp docs) ...)?
(defmacro defhook (name (&key docs) &body body)
"Define a function with the given NAME and an appropriate lambda list,
@kingcons
kingcons / gist:3428654
Created August 22, 2012 19:39
dat pubkey
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEApILuZvCHXNtQOXOa2S1X7xpBIFzq4DrndbZc5jLCq/rOm/mUxnvXX3rpSRlJKcU2yTbL258qZKhuAt4BCA9s/4NIieahkoOorPdBh05jf+SA48JFD+DG+Y20LTfJfyzTTadIx4Hhn+81tq0n+fpCX+F7PnEOiAlrcXzR1bcNRvFXFuDJgzV1nT8U9lyep+sGpIYrp06UFEoR6rGCXfFYqY8tWP6/EWGR3nHNf8o2JcnCMaAh+yn9HERy8Eo4fCBrMTZ4Mtt39sI1qwixmyQObCTr7TcTP2CA4vBScFaYQAOaSfXDap9G0AD4a5kWkv64/QpQ9L2M+Mo3bHB9fMNHQQ== redline@redlaptop
@kingcons
kingcons / cpu.lisp
Last active December 14, 2015 02:59
Best of both worlds.
(defmacro defenum (name (&rest keys))
"Define a function named %NAME, that takes an argument KEY. If KEYS are
scalar values, the corresponding index in KEYS is return. Otherwise, the
associated value is returned."
`(defun ,(intern (format nil "%~A" (string-upcase name))) (key)
(let ((enum ',(loop for i = 0 then (1+ i)
for key in keys
collect (typecase key
(list key)
(t (cons key i))))))
git log master | grep -C 1 'Brit Butler' | grep 'commit ' | cut -d ' ' -f 2 | xargs git show > commits.txt
# I almost did this in lisp. Then I thought better of it. Update that resume!
(ql:quickload '(cl-fad cl-ppcre))
(defpackage :sloc
(:use :cl)
(:import-from :cl-fad #:walk-directory))
(in-package :sloc)
(defvar *ext->syntax*
'(("factor" "^!.*"))
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload '(yason closer-mop alexandria)))
;; Turns out cl-json does this just as fast without all the fuss.
;; Just (cl-json:encode-json (romreader:load-rom "foo.nes") stream).
(defpackage #:json-export
(:use :cl)
(:import-from #:closer-mop #:class-slots
#:slot-definition-name)