Skip to content

Instantly share code, notes, and snippets.

@joeytrapp
joeytrapp / gist:4693660
Last active December 12, 2015 01:48
How to get parent route models in the child route model() method.
App.Router.map(function() {
this.resource('posts', function() {
this.resource('post', { path: '/:post_id' }, function() {
this.resource('permissions', function() { ... });
});
});
});
App.PermissionsRoute = Ember.Route.extend({
model: function() {
@joeytrapp
joeytrapp / path_compare.js
Last active October 14, 2015 01:28
Ember.js utility to generate a controller computed property that compares a string to a part of the currentPath. Used to create boolean properties that update on based on the state of the application.
Ember.PathCompare = {
comparePartsToString: function(parts, compare, index) {
var str, first;
if (index === undefined) {
index = parts.length - 1;
} else {
if (index < 0) {
index = (parts.length - 1) - (index * -1);
}
}
@joeytrapp
joeytrapp / run-mocha.js
Created April 6, 2012 02:09
JavaScript: PhantomJS Mocha Scrapper
/*global phantom:true, console:true, WebPage:true, Date:true*/
(function () {
var url, timeout, page, defer;
if (phantom.args.length < 1) {
console.log("Usage: phantomjs run-mocha.coffee URL [timeout]");
phantom.exit();
}
url = phantom.args[0];
@joeytrapp
joeytrapp / run-jasmine.coffee
Created March 28, 2012 04:42
CoffeeScript: PhantomJS Jasmine Scrapper
# Exit early if users don't pass at least 1 argument
if phantom.args.length < 1
console.log "Usage: phantomjs run-jasmine.coffee URL [timeout]"
phantom.exit()
# Collect the passed int args or set to default value
url = phantom.args[0]
timeout = phantom.args[1] or 6000
# Create the page object to load the test page in
@joeytrapp
joeytrapp / gist:1201000
Created September 7, 2011 16:14
Global ignore file
# Numerous always-ignore extensions
*.diff
*.err
*.orig
*.log
*.rej
*.swo
*.swp
*.vi
*~
@joeytrapp
joeytrapp / dynamic_find.php
Created April 5, 2011 03:56
PHP: CakePHP Dynamic Find Behavior
<?php
class DynamicFindBehavior extends ModelBehavior {
public $mapMethods = array(
'/^(find){1}[^(all|by)]{1}(.)+(by){1}(.)+$/' => '_find'
);
public function _find(&$model, $method, $cond = null) {
$fields = $ret = array();
$virtual = $_field = $_cond = false;
$tmp = array_merge(array_keys($model->schema()), array_keys($model->virtualFields));
@joeytrapp
joeytrapp / program_cache.php
Created March 31, 2011 18:31
Make generic the cache calls for a set of models.
<?php
/**
* Program Cache Behavior
*
* Behavior for making cache calls generic in the model layer. Assumes that the
* passed in ID is uuid.
*
* Things to change:
* Different method for handling directory building
* Support for cache configs other than the default (partially implemented)