Skip to content

Instantly share code, notes, and snippets.

View nefarioustim's full-sized avatar

Tim Huegdon nefarioustim

View GitHub Profile
from django.conf.urls.defaults import *
from blog.models import Category, Post
post_info_dict = {
'queryset': Post.pub.all(),
'date_field': 'pub_date',
}
urlpatterns = patterns('blog.views',
import urllib
try:
from urlparse import parse_qs
except ImportError:
from cgi import parse_qs
def url_params(url, **kwargs):
bits = url.split('?')
query_vars = {}
if len(bits) > 1:
@nefarioustim
nefarioustim / getUTCDateTime.js
Created April 11, 2011 09:12
Prototype a method onto the Date object that returns a UTCDateTime string.
Date.prototype.getUTCDateTime = function() {
var zf = function(num) {
return ((num + 100) + '').substr(1);
};
return [
this.getUTCFullYear(),
'-',
zf(this.getUTCMonth() + 1),
'-',
@nefarioustim
nefarioustim / project-euler-problem-2.js
Created June 5, 2011 14:55
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
for(
var sum = 0, f1 = 1, f2 = 2, next;
f2 < 4E6;
f2 & 1 || (sum += f2), next = f1 + f2, f2 = (f1 = f2, next)
);
console.log(sum);
@nefarioustim
nefarioustim / throttle.js
Created June 28, 2011 16:01
Throttle a function
function throttle(fn, delay) {
var timer = null;
return function () {
var context = this,
args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
}, delay);
@nefarioustim
nefarioustim / profile-loop.js
Created November 30, 2011 14:57
Homespun JavaScript profiling
for (
var start = new Date().getTime(),
iterationCount = 0,
millisec = 0;
millisec < 1000;
iterationCount++
) {
// Your profiled code
// goes here
@nefarioustim
nefarioustim / memoize.js
Created November 30, 2011 22:41
JavaScript Memoization
function memoize(fn) {
return function() {
var args = Array.prototype.slice.call(arguments),
hash = "",
i = args.length;
currentArg = null;
while (i--) {
currentArg = args[i];
hash += (currentArg === Object(currentArg)) ?
JSON.stringify(currentArg) : currentArg;
@nefarioustim
nefarioustim / world.js
Created April 18, 2012 08:59 — forked from andyhd/world.js
render with one loop
function drawMap(map) {
var x, y,
width = map[0].length,
current_node = map.length * width;
while (current_node--) {
x = current_node % width;
y = ~~(current_node / width);
drawTile({
x: x,
y: y
@nefarioustim
nefarioustim / largest-palindrome.js
Created July 31, 2012 17:19
Find the largest palindrome made from the product of two 3-digit numbers
function getPalindrome() {
var product, y,
x = 999,
largest = 0;
while (x > 99) {
y = x;
while (y > 99) {
product = x * y;
if (product <= largest) break;
@nefarioustim
nefarioustim / wiki.md
Created September 19, 2012 15:34
Wikiman's Creed

This is my wiki. There are many like it, but this one is mine.

My wiki is my best friend. It is my life. I must master it as I must master my life.

My wiki, without me, is useless. Without my wiki, I am useless. I must wiki true. I must wiki better than my enemy who is trying to out wiki me. I must wiki him before he wikis me. I will...

My wiki and myself know that what counts in this war is not the docs we type, the users who read, or the communities we forge. We know that it is the wikis that count. We will hit...

My wiki is human, even as I, because it is my life. Thus, I will learn it as a brother. I will learn its weaknesses, its strength, its parts, its accessories, its widgets and its syntax. I will keep my wiki clean and ready, even as I am clean and ready. We will become part of each other. We will...