Skip to content

Instantly share code, notes, and snippets.

View lukelex's full-sized avatar

Lukas Alexandre lukelex

View GitHub Profile
@lukelex
lukelex / channel_subscribe_callback.js
Created December 10, 2012 03:39
Private Pub client subscription callback
// on privatepub this data is sent by server to client
var opts = {
server: "foo",
channel: "/hello/world",
...
}
// and you can add a subscription callback
// it will take a Faye subscription object. (see http://faye.jcoglan.com/browser/subscribing.html)
opts.subscription = function(subscription) {
@lukelex
lukelex / _form.html.haml
Created December 17, 2012 05:10
Form using HAML alongside Batman.js
%fieldset
%legend
%span{"data-hideif" => "post.id"} New Post
%span{"data-showif" => "post.id"} Edit Post
#error-explanation.alert-message.block-message.error{"data-showif" => "post.errors.length"}
%p
%strong
%span{"data-bind" => "post.errors.length"}
%span{"data-bind" => "'error' | pluralize post.errors.length"}
prevented this post from being created:
@lukelex
lukelex / application_controller.rb
Created December 20, 2012 22:56
CORs Rails integration
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :cor
private
def cor
headers["Access-Control-Allow-Origin"] = "js-app-origin.com"
headers["Access-Control-Allow-Methods"] = %w{GET POST PUT DELETE}.join(",")
headers["Access-Control-Allow-Headers"] = %w{Origin Accept Content-Type X-Requested-With X-CSRF-Token}.join(",")
@lukelex
lukelex / gist:4362032
Created December 23, 2012 04:54
CSS3 rotate transitions
div.exampletransitione {
width: 500px;
height: 60px;
margin: 20px 0;
}
div.exampletransitione div.transition {
width: 20px;
height: 20px;
background-color: #ED8029;
@lukelex
lukelex / install.md
Created December 24, 2012 14:17
Installing latest version of MongoDB on ubuntu

=Install MongoDB

==Add 10gen package to source.list

The 10gen package contains the latest mongoDB version, append below line to the end of the file “/etc/apt/sources.list”

deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen

For example, vim the “source.list” and append the 10gen package like this :

@lukelex
lukelex / gist:4369478
Created December 24, 2012 14:44
Build latest Ruby version from source
wget --no-check-certificate https://raw.github.com/joshfng/railsready/master/railsready.sh && bash railsready.sh
@lukelex
lukelex / toggle_attribute.js
Created December 24, 2012 18:59
Toggle an attribute
$('input:checkbox').attr('checked', function(idx, oldAttr) {
return !oldAttr;
});
@lukelex
lukelex / require_dir
Created January 10, 2013 03:49
Require all ruby files from a directory
Dir["./path/to/directory/*.rb"].each {|file| require file }
@lukelex
lukelex / git.plugin.zsh
Created January 26, 2013 17:14
Git aliases
# Aliases
# simple stuff
alias g='git'
compdef g=git
alias gs='git status'
compdef _git gst=git-status
alias gpl='git pull'
compdef _git gl=git-pull
alias gplr='git pull --rebase'
compdef _git gup=git-fetch
@lukelex
lukelex / JsonBasedClass
Created April 18, 2013 00:01
Instantiate a coffeescript object based on a JSON
class JsonBasedClass
constructor: (json) ->
for k,v of json
if k.indexOf '$'
key = @toCamel k
@[key] = v
@["$#{k}"] = v
toCamel: (field) ->
field.replace /(\_[a-z])/g, ($1) ->