Skip to content

Instantly share code, notes, and snippets.

@honza
honza / idle_fingers.py
Created February 25, 2011 19:25
IdleFingers Pygments Theme
# -*- coding: utf-8 -*-
"""
Idle-Fingers Colorscheme
~~~~~~~~~~~~~~~~~~~~~~~~
Converted by Vim Colorscheme Converter
"""
from pygments.style import Style
from pygments.token import Token, Comment, Name, Keyword, Generic, Number, Operator, String
@honza
honza / gitchart.py
Created March 1, 2011 02:53
Find out who's been editing some code!
"""
Git Chart - Number of lines changed per author
Auhthor: honza <http://github.com/honza>
Usage: Drop this file into a Git repo and run it!
"""
from commands import getoutput
import os
from commands import getoutput
class Blamer(object):
"""
This script will run through all the files git tracks, and see how many
lines each user has written/edited. You will get a number of lines and
percentage. Throughout the course of a project, you will add lines and your
lines will be deleted. This shows you how much of your code is still in the
project now.
@honza
honza / views.py
Created May 11, 2011 22:59
Google Contacts API OAuth - Django Views
from django.http import HttpResponse, HttpResponseRedirect
from settings import CONSUMER_KEY, CONSUMER_SECRET, SCOPES, URL
import gdata.contacts.client
import gdata
def index(request):
client = gdata.contacts.client.ContactsClient(source='yo')
if 'token' not in request.session:
callback = "%s/callback" % URL
request_token = client.GetOAuthToken(SCOPES, callback, CONSUMER_KEY,
@honza
honza / widget.coffee
Created May 26, 2011 16:08
Widget class example
$ ->
# Widget class example
class Widget
constructor: (@model, @events) ->
_keepThis: (func, obj) ->
args = Array.prototype.slice.call arguments, 2
-> func.apply obj, args.concat arguments
@honza
honza / inheritance.js
Created May 26, 2011 17:22
Class inheritance in Javascript
var __hasProp = Object.prototype.hasOwnProperty;
var __extends = function(child, parent) {
// copy all properties from parent to child
for (var key in parent) {
if (__hasProp.call(parent, key))
child[key] = parent[key];
}
function ctor() {
this.constructor = child;
}
@honza
honza / hiding.coffee
Created May 26, 2011 19:53
Object-hiding in CoffeeScript
do ->
class Animal
constructor: ->
alert 'Hello'
class Nothing
constructor: ->
alert "Won't say anything"
@honza
honza / app.js
Created June 26, 2011 01:47
Django-style Mustache-power templates for node.js
var fs = require('fs');
var mustache = require('mustache');
var BASE = fs.readFileSync('base.html', 'utf-8');
var CACHE = {};
var context = {
name: 'Honza',
age: 22
};
@honza
honza / vars.js
Created July 12, 2011 14:29
What looks best?
/*
* How do you like your Javascript variables?
* Is there a PEP8 for Javascript?
*/
// Option 1
var viewPage = function() {};
// Option 2
@honza
honza / maps.js
Created August 3, 2011 13:28
Google Directions API inconsistencies
// When run multiple times, the following logs `false` 50% of the time and `true` 50% of the time
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': '211 Horseshoe Lake Drive, Halifax, Canada'}, function(results, status) {
console.log(status == google.maps.GeocoderStatus.OK);
});