Skip to content

Instantly share code, notes, and snippets.

View mateusmaso's full-sized avatar

Mateus Maso mateusmaso

View GitHub Profile
@gereon
gereon / gist:3150445
Created July 20, 2012 12:20
Mac OSX Spotlight Enhancement

Mac OSX Spotlight Enhancement

Add this to Info.plist in /System/Library/Spotlight/RichText.mdimporter/Contents/ and Spotlight will search for source code files.

<string>public.c-header</string>
<string>public.c-plus-plus-header</string>
<string>public.c-source</string>
<string>public.objective-c-source</string>
public.c-plus-plus-source
@therabidbanana
therabidbanana / readme.md
Created August 15, 2012 15:50
Identity Map for backbone models

I read this trick on the Soundcloud blog: http://backstage.soundcloud.com/2012/06/building-the-next-soundcloud/

You can return an existing object from a javascript constructor to avoid creating a new object. I'm using this as an identity map - one instance per id. Adapted to Coffeescript and adding a feature to update the existing class with any new information (me.set(data)), it looks something like user.coffee.

You have to copy-paste the simple return super constructor into every child class. Without this the code breaks. Not sure how to solve this issue.

@marocchino
marocchino / schema.rake
Created August 28, 2012 08:24
rake db:schema:dump_all
namespace :db do
namespace :schema do
# desc 'Dump all database schema'
task :dump_all => [:environment, :load_config] do
ActiveRecord::Base.configurations.keys.grep(/_development$/).map{|o|o.sub "_development", ""}.each do |name|
begin
filename = "#{Rails.root}/db/#{name}_schema.rb"
File.open(filename, 'w:utf-8') do |file|
ActiveRecord::Base.establish_connection("#{name}_#{Rails.env}")
@nikcub
nikcub / README.md
Created October 4, 2012 13:06
Facebook PHP Source Code from August 2007
@dblandin
dblandin / activate_tab.applescript
Last active September 29, 2023 16:26
AppleScript to grab a list of tab titles from Google Chrome.
# Activate tab
# $ osascript activate_tab.applescript 1, 2
on run argv
set window_index to item 1 in argv
set target_index to item 2 in argv
tell application "Google Chrome" to set active tab index of first window to target_index
tell application "Google Chrome" to activate
end run
@amatiasq
amatiasq / Handlebars- Backbone.js
Created February 5, 2013 00:06
This allow Handlebars to look up Backbone Model's attributes: {{ user.address.street }} If user is a Backbone Model this will become user.get("address").street And if user.get("adress") is also a Backbone Model this will be produced: user.get("address").get("street")
Handlebars.JavaScriptCompiler.prototype.nameLookup = function(parent, name, type) {
var result = '(' + parent + ' instanceof Backbone.Model ? ' + parent + '.get("' + name + '") : ' + parent;
if (/^[0-9]+$/.test(name)) {
return result + "[" + name + "])";
} else if (Handlebars.JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
return result + "." + name + ')';
} else {
return result + "['" + name + "'])";
}
};

Managing Nested Models and Collections in Backbone.js

One common pattern for nesting another model or collection inside a model is to assign it as a property on that object, for example, @messages on Mailbox as illustrated on the Backbone.js homepage.

class Mailbox extends Backbone.Model
  urlRoot: '/mailbox'

 initialize: -&gt;
@snatchev
snatchev / routes.rb
Last active December 16, 2015 07:09
DRYing up your Rails API routes. Rails' routing gives you the ability to add multiple contraints and scopes to routes. These conditions are and'ed together. Meaning all conditions must be true for the route to match. If you want to or them, to have any condition match, you are left with duplicated code. In this example, I wanted both http://api.…
Rails::Application.routes.draw do
def api_endpoints
controller :api do
resources :widget
post :register
get :help
end
end
Controller = require('controller')
Post = require('app/models/post')
class List extends Controller
className: 'posts-list'
constructor: ->
super
# Post.all() returns a promise. Data from
# the server is fetched asyncronously.
@wkrsz
wkrsz / backbone-rivets.config.js
Last active December 18, 2015 04:49 — forked from wulftone/backbone-rivets.config.js
Some funky syntax for Rivets: model.@Attribute, model.attribute, model.computed().
// Bind to backbone attribute (read/write with get/set, subscribe to change:attribute event):
// data-text="model.@attribute"
//
// Bind to output of function (calls the function to get value, subscribes to 'change' event):
// data-text="model.computedProperty()
//
// Bind to attribute (subscribes to 'change' event):
// data-text="model.attr"
(function(rivets){