Skip to content

Instantly share code, notes, and snippets.

@akb
akb / gist:1725280
Created February 2, 2012 19:33
example mongoose model description
model 'User'
name: {type: String, index: true}
email: {type: String, index: true, unique: true}
password: String
model 'Post'
title: String
creator: {type: User.ObjectId, required: true}
createdOn: {type: Date, required: true}
mostRecentEditor: {type: User.ObjectId, required: true}
@akb
akb / gist:1352285
Created November 9, 2011 18:03
a web server as a series of tubes
var tubes = require('tubes');
var model = new tubes.model.Model({
name: 'Bob Dobbs',
age: 34,
favoriteColor: 'red'
});
model.on('updated', function (data) {
tubes.emit('data updated', model.fields);
@akb
akb / gist:1187817
Created September 2, 2011 02:38
pretty print a date in javascript
(function () {
return ['Jan.', 'Feb.', 'Mar.',
'Apr.', 'May', 'Jun.',
'Jul.', 'Aug.', 'Sep.',
'Oct.', 'Nov.', 'Dec.'][this.getMonth()] + " " +
(function (d) {
var s = d.toString(), l = s[s.length-1];
return s+(['st','nd','rd'][l-1] || 'th');
})(this.getDate()) + ", " +
this.getFullYear() + " " +
@akb
akb / gist:1173540
Created August 26, 2011 14:39
scrollbar thing
window.onscroll = function () {
if (!docked && (menu.offsetTop - scrollTop() < 0)) {
menu.style.top = 0;
menu.style.position = 'fixed';
menu.className = 'docked';
docked = true;
} else if (docked && scrollTop() <= init) {
menu.style.position = 'absolute';
menu.style.top = init + 'px';
menu.className = menu.className.replace('docked', '');
@akb
akb / truncatesmart
Created May 6, 2011 20:37
truncatesmart template filter
from django import template
register = template.Library()
@register.filter
def truncatesmart(value, limit=80):
"""
Truncates a string after a given number of chars keeping whole words.
Usage:
@akb
akb / invalid.js
Created January 31, 2011 17:59
Client-side pseudo-jquery template example
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script type="text/jqtpl" id="item">
<h1>{{ title }}</h1>
<p>Name: {{ name }}</p>
</script>
<script>
var counter = 0;