Skip to content

Instantly share code, notes, and snippets.

View c4urself's full-sized avatar

Christian Verkerk c4urself

  • Tubular Labs
  • Mountain View
View GitHub Profile
@c4urself
c4urself / jquery.notification.js
Created December 14, 2011 06:28
jQuery notifications
define([ 'jquery' ], function($) {
$.fn.notification = function(msg_type, msg, options) {
var container = this;
var defaults = {
autoHide: true,
hideSpeed: 3000,
fadeInSpeed: 'fast',
hideOthers: true
};
@c4urself
c4urself / styles.less
Created December 15, 2011 10:48
General styles.less
@yellow: yellow;
@green: green;
.pie {
behavior: url(PIE.htc);
}
@import "css/mixins";
@import "css/base";
@import "css/tables";
@c4urself
c4urself / truncatewords_by_chars.py
Created January 27, 2012 10:18
Django truncate words by characters
from django import template
register = template.Library()
@register.filter
def truncatewords_by_chars(value, arg):
"""
Truncate words based on the number of characters
based on original truncatewords filter code
@c4urself
c4urself / jquery.tooltip.js
Created February 2, 2012 09:33
jquery tooltip
define([ 'jquery' ], function($) {
var Tooltip = function(element, options) {
this.$element = $(element);
var tooltip = this,
title = this.$element.attr('title');
this.options = $.extend({}, $.fn.tooltip.defaults, options);
this.text = this.$element.removeAttr('title') && title || this.options.text;
@c4urself
c4urself / django_orm_inner_join.py
Created February 7, 2012 21:43
Django ORM INNER JOIN SQL test
from django.db import models
class Banana(models.Model):
name = models.CharField(max_length=255)
father = models.ForeignKey('self', null=True)
def __unicode__(self):
return self.name
@c4urself
c4urself / it_fib.py
Created February 17, 2012 23:17
Iterative fibonacci
def iterative(n):
if n == 0 or n == 1:
return n
prev2 = 0
prev1 = 1
for index in xrange(2, n + 1):
ivalue = prev1 + prev2
prev2 = prev1
prev1 = ivalue
if index == n:
@c4urself
c4urself / abstractview.js
Created February 23, 2012 09:43
Abstract view for Backbone
define([
'jquery',
'underscore',
'backbone',
'mustache'
], function($, _, Backbone, Mustache){
var view = Backbone.View.extend({
model: null,
template: null,
@c4urself
c4urself / email_backend.py
Created March 26, 2012 11:57
Django email
"""
This file enables email-based authentication for Django. The only steps required are
1. Add 'EmailAuthenticationBackend' to your settings' AUTHENTICATION_BACKENDS file
2. Add the {'authentication_form': EmailAuthenticationForm} to your login view (if using 'django.contrib.auth.views.login')
3. When saving a User instance, generate the username from the email using the 'generate_hash_from_email' function
"""
import hashlib
from django import forms
@c4urself
c4urself / topnav.js
Created August 4, 2012 17:43
Topnav backbone view
define([
'jquery',
'underscore',
'views/abstractview',
'models/authentication',
'text!templates/navigation/topnav.html',
'text!templates/navigation/notauthenticated.html'
], function($, _, AbstractView, authModel, mainNavigationTemplate, notAuthenticatedTemplate){
var view = AbstractView.extend({
@c4urself
c4urself / prototyping_basic.js
Created October 5, 2012 17:18
Prototyping example
function Engineer () {}
Engineer.prototype = {
getYearsWorked: function () {
return this.yearsWorked;
}
};
function UIEngineer (years) {
this.yearsWorked = years;