Skip to content

Instantly share code, notes, and snippets.

@toddself
toddself / gist:1902302
Created February 24, 2012 17:40
Backbone.Validator usage
var TestModel = Backbone.Model.extend({
use_defaults: true,
defaults: {
title: "BAD TITLE"
},
validators: {
title: {
is_type: 'string',
max_length: 40
}
@toddself
toddself / gist:2293136
Created April 3, 2012 15:55
Asynchronous Template Loader
TemplateLoader = (function(){
var template_cache = {};
var template_path = '/tmpl';
var loading_cache = {};
var load_template = function(template, callback){
var deferred = $.Deferred();
if(_.isUndefined(template) || !_.isFunction(callback)){
return false;
}
@toddself
toddself / col.patch
Created July 19, 2012 03:52
col.py patch
--- col.py 2012-07-16 11:29:49.000000000 -0700
+++ col2.py 2012-07-16 11:30:35.000000000 -0700
@@ -373,12 +373,12 @@
baseClass = SOCol
- def __init__(self, name=None, **kw):
+ def __init__(self, name=None, extra_vars={}, **kw):
super(Col, self).__init__()
self.__dict__['_name'] = name
@toddself
toddself / register.py
Created July 24, 2012 16:49
register_api
def register_api(view, endpoint, url, pk='user_id', pk_type='int', alt_keys=None):
"""Registers a MethodView derived class as a REST API by exposing the
various HTTP verbs to the correct URL schemes. Allows alternative
GET access for specific objects outside of the primary key GET scheme.
These are defined by the `alt_keys` list.
`alt_keys` is a list that can contain either strings or lists of strings.
If the data are strings, it will generate a single alternate GET URL
scheme inferring the type from the data contained in those strings.
@toddself
toddself / gist:4072576
Created November 14, 2012 14:57
html5
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>I'm a webapp!</title>
<body>
<script src="/js/my_awesome_app.js"></script>
@toddself
toddself / gist:4072579
Created November 14, 2012 14:58
dummy js app
$(document).ready(function(){
// get info about this page somehow
// this is, by the way, a dumb way to do this
$('head').append($(document.createElement('og:description'))
.html('This page kicks some major butt'));
});
@toddself
toddself / gist:4194920
Created December 3, 2012 13:03
default render method
MyBaseView = Backbone.View.extend({
tpl_name: '',
render: function(){
var dfd = $.Deferred();
var template_context = this.model;
if(_.isUndefined(template_context) || _.isFunction(template_context)){
template_context = new (Backbone.Model.extend({}));
}
@toddself
toddself / gist:4198793
Created December 3, 2012 22:40
lame html body
<div id="header"></div>
<div class="background vert_spacer">
<div id="main">
<div id="nav"></div>
<div id="workflow">
<lift:bind name="page_title"><h1 id="page_title"></h1></lift:bind>
<div id="flash_message"></div>
<div id="verify_message"></div>
<div id="user_data"></div>
<div id="section"></div>
@toddself
toddself / regions.js
Created December 6, 2012 03:51
region manager
(function($, _){
var Region = function(el){
this.el = el;
this.$el = $(el);
};
_.extend(Region.prototype, {
show: function(view){
// clean up...
this.clear();
@toddself
toddself / wxlayout.py
Created December 22, 2012 15:58
a layout manager for wxwidgets
#!/usr/bin/env python
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the