Skip to content

Instantly share code, notes, and snippets.

@marcioj
marcioj / app.pt-BR.yml
Last active August 29, 2015 14:13
Enum with brazilian states using enumerize gem
pt-BR:
enumerize:
defaults:
state:
ac: Acre
al: Alagoas
ap: Amapá
am: Amazonas
ba: Bahia
ce: Ceará
@marcioj
marcioj / _form.html.slim
Last active August 29, 2015 14:13
Rerenders the result of an ajax request into the fancybox modal. Good for form redisplays
= simple_form_for([@topic], remote: true, data: { "rerender-inside-modal" => true }) do |f|
= f.input :name
= f.input :content
= f.submit
@marcioj
marcioj / main.rb
Created January 18, 2015 01:26
Recursive hash creation in ruby
h = Hash.new {|h,k| h[k] = Hash.new(&h.default_proc) } # => {}
h[:a] = 1 # => 1
h[:b][:c] = 2 # => 2
h[:c][:d] = 3 # => 3
h # => {:a=>1, :b=>{:c=>2}, :c=>{:d=>3}}
@marcioj
marcioj / app.js
Last active August 29, 2015 14:15
App = Ember.Application.create();
App.Router.map(function() {
// put your routes here
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return "Hello world";
}
App.IndexRoute = Ember.Route.extend({
beforeModel: function() {
console.log("beforeModel");
},
model: function() {
console.log("model")
},
afterModel: function() {
console.log("afterModel");
},
App.IndexController = Ember.Controller.extend({
say: function(msg) {
console.log("Hello " + msg);
}
});
App.IndexRoute = Ember.Route.extend({
setupController: function(controller) {
controller.say("world");
}
App.FooController = Ember.Controller.extend({
say: function(msg) {
console.log("Hello " + msg);
}
});
App.IndexRoute = Ember.Route.extend({
controllerName: 'foo',
setupController: function(controller) {
controller.say("world");
App.IndexRoute = Ember.Route.extend({
renderTemplate: function() {
this.render();
}
});
@marcioj
marcioj / app.js
Last active August 29, 2015 14:15
App = Ember.Application.create();
var html = $("#myTemplate").remove().html();
var template = Ember.Handlebars.compile(html);
var model = "Click here";
var controller = { model: model };
var view = Ember.View.create({
template: template,
App.IndexRoute = Ember.Route.extend({
viewName: "foo"
});
App.FooView = Ember.View.extend({
didInsertElement: function() {
console.log("FooView")
}
});