Skip to content

Instantly share code, notes, and snippets.

@wesen
wesen / backbone-mixin.js
Created August 21, 2011 10:38
Merge backbone views (mixin pattern)
/**
* ## Merging mixin views in backbone.js ##
*
* really just more a test for tumblr gistr
*/
/**
* Merge the mixin (a Backbone.View) into another Backbone.View. Automatically merge events, defaults, and call the parent initializer.
**/
function mergeMixin(view, mixin) {
@wesen
wesen / emacs.applescript
Created August 22, 2011 06:35
Run a file in a new iterm emacs
on run {input}
set the_path to POSIX path of input
set cmd to "emacsclient -nw " & quoted form of the_path
tell application "iTerm"
activate
set myterm to (make new terminal)
tell myterm
set number of columns to 120
set number of rows to 60
@wesen
wesen / app.js
Created August 22, 2011 23:45
Deferred JSON with jquery / backbone.js
var App = {
Views: {
Member: {},
Admin: {},
Misc: {},
Cart: {},
Checkout: {}
},
Collections: {},
Controllers: {},
@wesen
wesen / main.js
Created August 23, 2011 14:15
Creating an ajax spinner with spin.js
var spinnerOpts = {
lines: 10,
length: 7,
width: 3,
radius: 3,
trail: 40,
speed: 1.0
};
$.fn.spin = function(opts) {
@wesen
wesen / common.h
Created August 23, 2011 18:18
magic settings for avr-gcc development
#ifndef COMMON_H__
#define COMMON_H__
#include <inttypes.h>
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************
*
* Input toggles. Previous element is replaced with input box when clicked
*
***************************************************************************/
$.fn.makeInputToggle = function () {
this.each(function () {
var that = $(this);
if (that.data("inputToggled")) {
/***************************************************************************
*
* Input Default fields handling
*
***************************************************************************/
var origJqueryVal = $.fn.val;
$.fn.origVal = origJqueryVal;
@wesen
wesen / form.js
Created September 6, 2011 17:35
get form data as json
/**
* Extract the value of all form fields specified in fields.
**/
$.fn.getFormData = function (fields) {
var res = {};
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
res[field] = $(this).find("[name=" + field + "]").val();
}
/**
* Start the bootloader by letting the watchdog run out. Safer than
* jumping directly into the bootloader.
**/
void start_bootloader(void) {
cli();
eeprom_write_word(START_MAIN_APP_ADDR, 0);
wdt_enable(WDTO_30MS);
while(1) {};
}
/**
* Convert a mysql timestamp to javascript, taking the timezone into account.
**/
function mysqlToDate(timestamp) {
var months = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var regex = /^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9])T([0-2][0-9]):([0-5][0-9]):([0-5][0-9])(.*)/;
var parts = timestamp.replace(regex,"$2/ $3, $1 $4:$5:$6 GMT$7").split('/');
var str = months[parseInt(parts[0])] + parts[1];
return new Date(str);
}