Skip to content

Instantly share code, notes, and snippets.

@rmosolgo
rmosolgo / json_storage.coffee
Last active August 29, 2015 13:59
Append `.json` to URLs for storage operations
# Taken from Batman.RailsStorage https://github.com/batmanjs/batman/blob/master/src/extras/batman.rails.coffee#L62
#
# Usage:
# #= require ./json_storage
# class MyApp.Model extends Batman.Model
# @persist Batman.JSONStorage
#
class Batman.JSONStorage extends Batman.RestStorage
# override the default URL functions to add .json:
urlForRecord: -> @_addJsonExtension(super)
@rmosolgo
rmosolgo / Gulpfile.js
Created April 18, 2014 16:12
Rendering into a Bootstrap JavaScript modal with Batman.js
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var jade = require('gulp-jade');
var batmanTemplates = require("gulp-batman-templates")
gulp.task('default', function(){
gulp.watch('./**/*', ["build", "html", "finalize"])
});
@rmosolgo
rmosolgo / calculated_properties.coffee
Created April 29, 2014 21:14
Batman.js calcuated properties over collections
class App.Sale extends Batman.Model
@hasMany 'sale_items'
@accessor 'total_price', ->
memo = 0
# adds 'sale_items' and each item as a source
@get('sale_items').forEach (item) ->
memo += item.get('subtotal')
memo
@rmosolgo
rmosolgo / Gulpfile.js
Created May 1, 2014 03:19
Example app with batman.js and leaflet
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var jade = require('gulp-jade');
var batmanTemplates = require("gulp-batman-templates")
gulp.task('default', function(){
gulp.watch('./**/*', ["build", "html", "javascripts", "stylesheets", "finalize"])
});
@rmosolgo
rmosolgo / pre-commit
Last active August 29, 2015 14:01 — forked from tannermares/pre-commit
check for focus and console.log before committing
#!/usr/bin/env ruby
if `git diff --cached spec` =~ /,\s?(:focus|focus:\s?true|:focus\s?=>\s?true)/
puts "\e[31mRemove your :focus tags before committing!\e[0m"
exit 1
end
if `git diff --cached spec` =~ /console\.log/
puts "\e[31mRemove your console.log before committing!\e[0m"
exit 1
@rmosolgo
rmosolgo / tasks_controller.coffee
Created July 20, 2014 21:40
Initialize a batman.js model with a hasMany child
class MyApp.TasksController extends MyApp.ApplicationController
new: ->
task = new MyApp.Task
task.get('task_entries').build(item: new MyApp.Item)
@set('task', task)
# /tasks/new will be rendered implicitly. MyApp.TasksNewView will be used to render that template, if it is defined.
@rmosolgo
rmosolgo / components_new_view.coffee
Created August 10, 2014 18:46
Batman.js and mass file upload with drag and drop
class Funzies.ComponentsNewView extends Batman.View
constructor: ->
super
@set 'pendingComponents', new Batman.Set
@set 'defaultKind', null
@set 'newFiles', null
@observe 'newFiles', (nv, ov) ->
if nv?.length
@_componentsFromFiles(nv)
@rmosolgo
rmosolgo / loader.js
Created January 18, 2015 16:01
Use the native loading indicator with turbolinks
var frame;
var frameSrc = "/sleep" // some local endpoint that just `sleep 2` or something
function addFrame() {
frame = document.createElement("iframe")
frame.style.display = "none"
document.head.appendChild(frame)
frame.src = frameSrc
}
@rmosolgo
rmosolgo / key-saving.js
Last active August 29, 2015 14:24
save key-by-key
// - Request saves on a key-by-key basis
//
// - After the operation, record whether keys are now persisted
// or whether they errored out
//
// - Store keys in a workflow:
// _requestedKeys -> requested, but not in flight or successfully saved
// _pendingKeys -> keys whose save is in flight now
// _successKeys -> keys whose save was successful
// _errorKeys -> keys whose save errored
@rmosolgo
rmosolgo / passbook.txt
Last active October 8, 2015 18:50
Passbook flow
_____ ___ __ __ ____ _____ _____ __ __
||_// ||=|| (( (( ||=) (( )) (( )) ||<<
|| || || \_)) \_)) ||_)) \\_// \\_// || \\
_____ _____
|- == | .-,( ),-. |-----|
|Web | .-( )-. | iOS |
| App| ( Apple Server ) | |
| | '-( ).-' |-----|
'-----' '-.( ).-' `--°--'