Skip to content

Instantly share code, notes, and snippets.

View olivoil's full-sized avatar

Olivier Melcher olivoil

View GitHub Profile
@olivoil
olivoil / phantom.coffee
Created June 24, 2012 15:05 — forked from BinaryMuse/phantom.coffee
Take screenshots with Phantom.js from Node.js
#!/usr/bin/env coffee
# Call the program with: coffee phantom.coffee http://url.to/screengrab
phantom = require 'phantom' # npm install phantom
child_process = require 'child_process'
url = process.argv[2]
createScreenshot = (page, filename) ->
@olivoil
olivoil / hstore_accessor.rb
Created June 16, 2012 01:48 — forked from inopinatus/hstore_accessor.rb
hstore accessor class method for AR
# put this file in lib/ and include it from an initializer
module HstoreAccessor
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def hstore_accessor(hstore_attribute, *keys)
serialize hstore_attribute, ActiveRecord::Coders::Hstore
@olivoil
olivoil / Coffeescript ctags
Created June 10, 2012 04:41 — forked from bjornharrtell/Coffeescript ctags
ctags definitions for coffeescript. Detects classes, static/class methods, plain functions and variables.
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/(^|=[ \t])*class ([A-Za-z]+\.)*([A-Za-z]+)( extends [A-Za-z.]+)?$/\3/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?([A-Za-z.]+):.*[-=]>.*$/\3/m,method/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?([A-Za-z.]+)[ \t]+=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*@([A-Za-z.]+):[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*([A-Za-z.]+):[^->\n]*$/\1/f,field/
--regex-coffee=/(constructor: ).@([A-Za-z.]+)/\2/f,field/
@olivoil
olivoil / ngrams-and-tire.rb
Created June 5, 2012 19:49 — forked from karmi/ngrams-and-tire.rb
An example of using ngram analysis in ElasticSearch with the Tire rubygem
# An example of using ngram analysis in ElasticSearch with the Tire rubygem
# ==========================================================================
# The original, raw example: https://gist.github.com/988923
require 'rubygems'
require 'tire'
require 'yajl/json_gem'
class URL
def initialize(attributes={})
@olivoil
olivoil / app.js
Created June 3, 2012 19:15 — forked from joewest/app.js
ember.js login form
App = Ember.Application.create({});
App.loginController = Ember.Object.create({
// do login stuff
});
App.LoginFormView = Ember.View.extend({
login: null,
password: null,

Recently, we've been working on extracting Ember conventions from applications we're working on into the framework. Our goal is to make it clearer how the parts of an Ember application work together, and how to organize and bootstrap your objects.

Routing

Routing is an important part of web applications. It allows your users to share the URL they see in their browser, and have the same things appear when their friends click on the link.

The Ember.js ecosystem has several great solutions for routing. But, since it is such an important part of most web applications, we've decided to build it right into the framework.

If you have already modeled your application state using Ember.StateManager, there are a few changes you'll need to make to enable routing. Once you've made those changes, you'll notice the browser's address bar spring to life as you start using your app—just by moving between states, Ember.js will update the URL automatically.

Routing in Ember

In Ember, the application's state manager handles routing. Let's take a look at a simple example:

App.stateManager = Ember.StateManager.create({
  start: Ember.State.extend({
    index: Ember.State.extend({
      route: "/",
@olivoil
olivoil / gist:2853473
Created June 1, 2012 16:43 — forked from svperfecta/gist:2853467
Rakefile to Generate Emacs CTAGS
# Generate TAGS files with bundler projects. Bundle must be updated, and tags binary
# must be exuberant ctags.
namespace :tags do
namespace :generate do
desc <<-EOT
Generate a new emacs TAGS file for the current project.
Requires exuberant ctags and bundler.
EOT
task :emacs do
@olivoil
olivoil / gist:2202874
Created March 26, 2012 04:02 — forked from benedikt/gist:1977438
Protect all fields against mass assignment in a mongoid document by default
module Mongoid
module MassAssignmentSecurity
extend ActiveSupport::Concern
included do
attr_accessible nil
end
end
module Document
@olivoil
olivoil / wait_until.rb
Created March 4, 2012 01:08 — forked from metaskills/wait_until.rb
Never sleep() using Capybara!
# Have you ever had to sleep() in Capybara-WebKit to wait for AJAX and/or CSS animations?
describe 'Modal' do
should 'display login errors' do
visit root_path
click_link 'My HomeMarks'
within '#login_area' do
fill_in 'email', with: '[email protected]'
fill_in 'password', with: 'test'