Skip to content

Instantly share code, notes, and snippets.

View stevekane's full-sized avatar

Steven stevekane

View GitHub Profile
@stevekane
stevekane / queryparamsparsing
Created January 19, 2013 06:20
A brief discussion of views that parse request.QUERY_PARAMS and convert them into a query that is run against the database
I am looking for a library that handles request.QUERY_PARAMS and converts the parameters into a database query that returns a queryset.
The pattern I am using arrises from Ember.js 's wish to be able to send queries of the following format to my back-end and have it return the desired queryset:
GET Request: http://myurl.com/api/modelname?attribute=value
where attribute is a property of the model and value is the targetted value
in the trivial case, it should be able to generate a query such as:
@stevekane
stevekane / assetfileexample
Created January 31, 2013 23:39
example of Assestfile to compile templates
require 'rake-pipeline-web-filters'
input "static" do
output "static/js/src"
#compile handlebars templates into Ember.TEMPLATES
match "coffee/templates/**/*.handlebars" do
handlebars
concat "templates.js"
end
end
@stevekane
stevekane / ember data delete
Last active December 12, 2015 09:28
How do I correctly delete records from Ember Data
Here is the problem:
I have a UI button that adds new instaces of a DS.Model (App.FarmAnimal....trolling here). I am implementing a route-wide "undo/redo" system and I need to construct all actions such that an "opposite" action is also available. I do not want to change a flag such as "isActive" on the model instance from true to false but rather I want to truly delete it. If the model has been persisted, I will take care of alerting the user that their undo will delete a persisted model... This is not a concern.
I have used the following pattern to add a new model to the related Objects array of my parent model (App.Farm).
App.Farm.get('farmanimal').createRecord({type:"pig"})
This works as intended but the reverse operation of deleting that record...not so much.
@stevekane
stevekane / assetfile
Last active December 14, 2015 00:48
Example of Assetfile used with rake pipeline
Use gem to get rake-pipeline and rake-pipeline-web-filters (both on github w/ docs on installation/setup)
create an Assetfile in your project's root that looks something like the one shown below:
The handlebars compilation section is in the middle though you may check out the others for edification or whatnot.
require 'rake-pipeline-web-filters'
input "static" do
output "static/"
#compile the JS files that the coffeescript compiler outputs and wrap using minispade
@stevekane
stevekane / gist:5438647
Created April 22, 2013 21:20
problem w/ router
App.Router.map(function() {
this.route("menu", {path: "/menu"});
});
App.IndexRoute = Ember.Route.extend({
setup: function (context) {
this._super(context);
console.log('yo');
},
@stevekane
stevekane / gist:5513628
Last active December 16, 2015 23:28
quick route example
App.Route.map () ->
@resource "clients"
@resource "client"
@resource "coaches"
@resource "coach"
@resource "coachedclients", {path: '/clients'}
App.Coachedclients = Ember.Route.extend
model: (params) ->
return App.Client.find(coach: @modelFor('coach'))
@stevekane
stevekane / gist:5528003
Created May 6, 2013 20:38
load tasks straiught from package.json
fs = require('fs')
packageJSON = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf-8'))
npmTasks = []
deps = Object.keys(packageJSON.dependencies) + Object.keys(packageJSON.devDependencies)
for dep in deps
if dep.search('grunt-') isnt -1 then npmTasks.push(dep)
#DO YOUR NORMAL grunt stuff here until you get to the location where you load your Npm tasks
App.MyMixin = Ember.Mixin.create({
sortedContent: function () {
//return sorted content
}.property('content'),
sortManagerClass: Ember.StateManager.extend({
defaultState: "none",
none: Ember.State.extend({
//define event responses
@stevekane
stevekane / gist:5789403
Last active December 18, 2015 13:19
Dashboard setup for Ember cats and dogs
<script type="text/x-handlebars">
<h1>Dashboard</h1>
{{outlet cats}}
{{outlet dogs}}
</script>
<script type="text/x-handlebars" data-template-name="cats">
{{#each cat in controller.content}}
{{cat}}
##Hey
here is some normal text