Skip to content

Instantly share code, notes, and snippets.

View stevekane's full-sized avatar

Steven stevekane

View GitHub Profile
@stevekane
stevekane / gist:6356006
Created August 27, 2013 16:44
ClickElsewhereMixin (an Ember mixin used to detect clicks outside a view) Original Attribution: Alex Speller's gist at https://gist.github.com/alexspeller/6251054
#original attribution https://gist.github.com/alexspeller/6251054
bound = (fnName) -> Ember.computed fnName -> @get(fnName).bind(@)
App.ClickElsewhereMixin = Ember.Mixin.create
#use this method hook to define your desired behavior
onClickElsewhere: Ember.K
#bound version of our instance method
@stevekane
stevekane / gist:6468526
Created September 6, 2013 19:12
Rough idea for passing along events in a component to component methods
AR.AgentrunPickadateComponent = Ember.Component.extend
events: [
'onOpen',
'onClose',
'onRender',
'onStart',
'onStop',
'onSet'
]
@stevekane
stevekane / gist:6597165
Last active December 23, 2015 06:58
CP of Object proxies that define a "view-specific" attribute
wrapWithProperty = (arrayName, propertyName, value) ->
Ember.computed arrayName + ".[]", ->
@get(arrayName).map( (each) ->
eachHash = {}
eachHash[propertyName] = value
eachHash.content = each
Ember.ObjectProxy.create(eachHash)
)
wrapWithHash = (arrayName, hashName) ->
@stevekane
stevekane / gist:7376558
Last active December 27, 2015 19:19
Quick sketch of RSVP.Hash wrapper
model: function (params) {
var FetchPromise = Ember.RSVP.Promise(function (resolve, reject) {
Ember.RSVP.hash({
dinosaurs: App.Dinosaur.find(),
ninjas: App.Ninja.find()
})
.then(function (objects) {
resolve(objects);
})
@stevekane
stevekane / gist:7421605
Last active December 28, 2015 01:38
quick n dirty route problem
<div class="row">
<ol class="breadcrumb">
<li>{{#link-to "videos"}}Videos{{/link-to}}</li>
</ol>
</div>
<div class="media">
<div class="media-header">
<h3>{{title}}</h3>
<h4>{{description}}</h4>
<h5>Published on: {{publication_date}}</h5>
@stevekane
stevekane / gist:7764181
Created December 3, 2013 05:11
Curry example for future reference
/**
first arg is a function, second is the number of arguments
to expect before executing
(N.B. The second arg is optional and will default to the arity
of the function if not provided)
*/
function curry (fn, numArgs) {
var numArgs = numArgs || fn.length;
@stevekane
stevekane / gist:8051456
Created December 20, 2013 07:18
React router example...WIP
var routeManaged = false;
var HashRoutePlugin = {
getCurrentRoute: function() {
return window.location.hash;
},
pushCurrentRoute: function(newRoute) {
window.location.hash = newRoute;
},
setCurrentRoute: function(newRoute) {
var rr = new RouteRecognizer
//this is currently used
rr.add([
{path: "whatever", handler: whateverHandler}
]);
//when recognize is run, it will return this
[{handler: whateverHandler, params: {}}]
@stevekane
stevekane / graph.js
Last active August 29, 2015 14:07
This is an overview of the way a graph object with backwards refs is stored
//Object -> Node -- constructor
let Node = (hash) => {
this.id = hash.id || new UUID()
this.value = hash
this.parentId = null
this.childIds = []
}
//-> Graph -- constructor
let Graph = () => {
@stevekane
stevekane / red.js
Last active August 29, 2015 14:07
A quick illustration of the compact and readable nature of iteration with reducers
/*
This gist is just a quick example of the same function written
in a composable manner (using prodash.js). Please understand
that the functions exported by prodash are almost ALL curried
by default allowing them to be partially applied.
The goal of this code is to iterate through a list of "particles"
and return a Float32Array of their x,y,z components. Only living
particles should be included.
*/