Skip to content

Instantly share code, notes, and snippets.

@pehrlich
pehrlich / rails.js
Created March 20, 2011 08:47
Allow determination of ajax data-type by surveying the submit button
//var method, url, data, dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
var method, url, data, dataType = element.data('type') || element.find(':submit:first').data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
@pehrlich
pehrlich / gist:1431019
Created December 4, 2011 19:08
Phonegap index.html
<!DOCTYPE html>
<html>
<head>
<!-- todo: optimize preloading & caching in the app -->
<title>Brickbook iOS</title>
<script src="http://jsconsole.com/remote.js?E4FD2C56-98CF-notgivingyoumyactualkey-34EB-69B8779345D0"></script>
<link href="http://192.168.47.105:3000/assets/application.css" media="screen" rel="stylesheet" type="text/css"/>
<script src="http://192.168.47.105:3000/assets/application.js" type="text/javascript"></script>
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1.0, user-scalable=no">
@pehrlich
pehrlich / gist:1431055
Created December 4, 2011 19:23
PhoneGap + jQuery mobile application.js.coffee
# This is a manifest file that'll be compiled into including all the files listed below.
# Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
# be included in the compiled file accessible from http:#example.com/assets/application.js
# It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
# the compiled file.
#
#= require jquery
#= require jquery.extensions
#= require jquery_ujs
#= require jquery.mobile-1.0
@pehrlich
pehrlich / sparkle.js.coffee
Created December 17, 2011 21:11
jq extension to create 'chaser lights' circling around a button
$.fn.sparkle = (arg_options) ->
options = {
width: 3
gap: 3
comets: 2
}
$.extend(options, arg_options) if arg_options
span = options.width + options.gap
@pehrlich
pehrlich / nxt.css
Created December 20, 2011 20:36
borked jquery themeroller theme
/*!
* jQuery Mobile v1.0rc2
* http://jquerymobile.com/
*
* Copyright 2010, jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
/*!
* jQuery Mobile Framework
@pehrlich
pehrlich / application_controller.rb
Created December 24, 2011 16:15
handle json with query mobile
# someday: move to json response module?
def json_response(options)
logger.warn "JSON response: #{options}"
render json: options
end
def json_callback(method, args = [])
json_response({status: :window_callback, method: method, args: args})
end
@pehrlich
pehrlich / SerializeConverter.rb
Created January 25, 2012 03:30
Serialize to property for neo4j
module Neo4j
module TypeConverters
class SerializeConverter
# serializes to sting
class << self
def convert?(type)
type == :serialize
end
@pehrlich
pehrlich / neo4j-AcceptsHashFor.rb
Created January 25, 2012 05:55
Allows a neo4j to be given a hash and build a related model
module Neo4j
module Rails
class Model
class << self
# This allows anything to be thrown at a relationship and understood.
# usage:
#
# has_one(:location).to(Location)
# accepts_hash_for :location
@pehrlich
pehrlich / backbone_extensions.js.coffee
Created January 27, 2012 01:11
Getting rid of some cruft in backbone
# the current setup, for conveience, removes all capital letters from class names, which is not the best.
# this could be fixed, but carefully.
# remove the default ensure element, we handle this in Base
Backbone.View.prototype._ensureElement = () ->
class ZenBucket.Views.Base extends Backbone.View
initialize: (render) ->
# set up sensible defaults
@pehrlich
pehrlich / active_controller.js.coffee
Created February 6, 2012 03:22
Spine.js get active controller from stack
Spine.Stack.include
active_controller: ()->
@manager.active_controller
window.app = new App
app.manager.bind 'change', (controller)->
console.log 'stack change', this, arguments
@active_controller = controller