Skip to content

Instantly share code, notes, and snippets.

View danielstocks's full-sized avatar
🏠
Working from home

Daniel Stocks danielstocks

🏠
Working from home
View GitHub Profile
@danielstocks
danielstocks / Django Devolopment URLS
Created May 5, 2010 14:04
Serving static media with the Django development server
if settings.DEBUG:
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
'show_indexes': True}
),
(r'(.*\.html)$', 'django.views.generic.simple.direct_to_template'),
)
@danielstocks
danielstocks / gist:390818
Created May 5, 2010 14:10
A few things that almost always goes into my settings.py
from os.path import abspath, dirname, join as pjoin
PROJ_ROOT = abspath(dirname(__file__))
DEFAULT_EMAIL_FROM = '[email protected]'
ORDER_EMAIL_TO = '[email protected]'
MEDIA_ROOT = pjoin(PROJ_ROOT, 'media')
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/admin/'
TEMPLATE_DIRS = (
@danielstocks
danielstocks / page-nav.html
Created June 17, 2010 12:53
Django Template pagination for a generic object_list view
{% if page_range|length > 1 %}
<div id="pagination">
Page
{% for range in page_range %}
{% ifequal page range %}
{{ range }}
{% else %}
<a href="?page={{ range }}">{{ range }}</a>
{% endifequal %}
{% endfor %}
@danielstocks
danielstocks / konami.js
Created June 20, 2010 07:35
コナミコマンド ↑ ↑ ↓ ↓ ← → ← → B A
if ( window.addEventListener ) {
var k = [], konami = "38,38,40,40,37,39,37,39,66,65";
window.addEventListener("keydown", function(e){
k.push( e.keyCode );
if ( k.toString().indexOf( konami ) >= 0 ) window.location = "http://www.youtube.com/watch?v=GuIBj0R2ui4";
}, true);
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>IE input value</title>
</head>
<body>
<form action="">
<input id="test" type="text" name="username">
</form>
find -name "*.py" | xargs perl -p -i -e 's/\s+\n/\n/g'
@danielstocks
danielstocks / gist:827322
Created February 15, 2011 09:46
css3 paper
<!doctype html>
<html>
<head>
<style>
.theme {
width:400px;
margin:0 2px;
padding: 10px;
// dust.js template pre-compilation
var template = dust.compile("Hello {name}!");
// compiles to this string:
//
// '(function() {
// dust.register("demo", body_0);
//
// function body_0(chk, ctx) {
@danielstocks
danielstocks / gist:2490995
Created April 25, 2012 16:13
Testing multiple HTTP status codes
/*
* Disregard the fact that I'm using Array.forEach here
*/
TestCase("ReadyStateHandlerTest", {
"test should call failure handler for 404, 400, 500": function() {
var _this = this;
[400, 404, 500].forEach(function(status) {
var request = forceStatusAndReadyState(_this.xhr, status, 4)
assert(request.failure);
@danielstocks
danielstocks / gist:5da83982d3b4c7b503a0
Created October 17, 2014 11:38
Pretty print a JavaScript Tree Data Structure
// Example implementation: http://jsfiddle.net/2f7w2fpn/
var indent = 1;
function walk(tree) {
tree.forEach(function(node) {
console.log('--' + Array(indent).join('--'), node.key);
if(node.children) {
indent ++;
walk(node.children);
}