Skip to content

Instantly share code, notes, and snippets.

@fantactuka
fantactuka / require-queue.js
Created September 27, 2013 08:55
Loading modules in a specific order
var requireQueue = function(modules, callback) {
function load(queue, results) {
if (queue.length) {
require([queue.shift()], function(result) {
results.push(result);
load(queue, results);
});
} else {
callback.apply(null, results);
}
@fantactuka
fantactuka / controller.js
Last active December 22, 2015 04:58
Backbone by-Role access concept
var can = Backbone.Role.can;
var EntitiesController = Backbone.Controller.extend({
before: {
index: function() {
return can('read', 'entities');
}
}
});
@fantactuka
fantactuka / backbonish-app.js
Created July 9, 2013 11:53
Template-level defined views in a backbone-ish app
// Handlebars helper
var ViewsCache = Backbone.View.ViewsCache = {};
Handlebars.registerHelper('view', function(view, options) {
var id = _.uniqueId('view-');
views[id] = { view: view, options: options.hash };
return new Handlebars.SafeString('<script type="text/view" data-view-id="' + id + '"></script>');
});
@fantactuka
fantactuka / Gruntfile.js
Last active December 18, 2015 15:59 — forked from lrvick/.bowerrc
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-bower-task');
grunt.initConfig({
bower: {
install: {
options: {
verbose: true,
cleanup: true
}
@fantactuka
fantactuka / rails.rb
Created February 26, 2013 19:49
Rails composer
rails_apps_composer new APP_NAME -r core frontend init railsapps setup
var flattenObj = function (object, target, prefix) {
prefix = prefix || '';
return _(object).inject(function(result, value, key) {
if (_.isObject(value)) {
flattenObj(value, result, prefix + key + '.');
} else {
result[prefix + key] = value;
}
{
"name": "the-web-app",
"version": "0.0.1",
"dependencies": {},
"devDependencies": {
"grunt": "0.4.0",
"grunt-contrib-copy": "0.4.0",
"grunt-contrib-sass": "0.2.2",
"grunt-contrib-connect": "0.1.2",
"grunt-contrib-watch": "0.2.0",
@fantactuka
fantactuka / gist:4123991
Created November 21, 2012 09:36
Quick iterating through string matching
"Hello world".replace(/[aeoiu]/g, function(match, matchIndex) {
console.log(match, matchIndex);
});
// -> e, 1
// -> o, 4
// -> o, 7
@fantactuka
fantactuka / gist:4113044
Created November 19, 2012 19:21
Stupid Objective C hashes
NSMutableDictionary *requestConfig = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"GET", @"method",
@"/", @"path",
[[NSMutableDictionary alloc] init], @"params",
^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"[Request] Success: %@", responseObject);
}, @"success",
^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"[Request] Failure: %@", error);
}, @"failure",
@fantactuka
fantactuka / app.rb
Created October 28, 2012 20:51
Parallel requests in sinatra
require "sinatra"
require "sinatra/async"
require "em-synchrony"
require "em-synchrony/em-http"
class App < Sinatra::Base
register Sinatra::Async
aget "/" do
Fiber.new {