Skip to content

Instantly share code, notes, and snippets.

View werelax's full-sized avatar

Elías Alonso werelax

View GitHub Profile
@werelax
werelax / omniauth.rb
Created September 7, 2011 15:32
OmniAuth en modo test
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = {
"uid" => '12345',
"provider" => 'facebook',
"user_info" => {"name" => "Test Pepito", "nickname" => 'pepito'},
"credentials" => {"token" => 'testest'}
}
@werelax
werelax / test.rb
Created September 18, 2011 18:02
First try with ternary associations with ActiveRecord
require 'active_record'
require 'sqlite3'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)
ActiveRecord::Schema.define do
create_table :users do |t|
@werelax
werelax / test.rb
Created September 21, 2011 19:30
Serializing tag array in the model
# encoding: utf-8
require 'active_record'
require 'sqlite3'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)
@werelax
werelax / gist:1245128
Created September 27, 2011 14:09
Cool random strings in ruby
length = 12
rand(36**length).to_s(36)
@werelax
werelax / gist:1246137
Created September 27, 2011 20:28
Cool logger of files being loaded with spork, for later adding it in the prefork block
Spork.prefork do
# ... your normal prefork block goes here ...
module Kernel
def require_with_trace(*args)
start = Time.now.to_f
@indent ||= 0
@indent += 2
require_without_trace(*args)
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@werelax
werelax / lousy_cells.js
Created October 19, 2011 17:03
Some experiments for a reactive programming/declarative JS library
// Some helpers
function unique (array) {
var a = [];
var l = array.length;
for(var i=0; i<l; i++) {
for(var j=i+1; j<l; j++) {
// If array[i] is found later in the array
if (array[i] === array[j])
j = ++i;
@werelax
werelax / lousy_cells.js
Created October 19, 2011 23:52
LousyCells + Pseudo-Declarative behaviour proof of concept
// Some helpers
function unique (array) {
var a = [];
var l = array.length;
for(var i=0; i<l; i++) {
for(var j=i+1; j<l; j++) {
// If array[i] is found later in the array
if (array[i] === array[j])
j = ++i;
@werelax
werelax / LousyTemp.js
Created October 23, 2011 14:49
Microscopic JavaScript template system
function LousyTemp(text) {
var code = '%>' + text + '<%';
code = code
.replace(/[\n\r\t]/g," ")
.replace(/(["'])/g, '\\$1')
.replace(/<%=(.*?)%>/g, "', $1, '")
.replace(/%>(.*?)<%/g, "_t_.push('$1'); ");
code = "obj||(obj={}); var _t_ = []; with(obj) {" + code + "}; return _t_.join('');";
return new Function('obj', code);
}
@werelax
werelax / gist:1677252
Created January 25, 2012 16:51
ScrollPagination with two divs
# Inside the inbox page
outer = $('.left-column')
inner = $('.headers')
offset = inner.height() - outer.height() - 50
scroll_pos = outer.scrollTop()
if scroll_pos > offset
# The scroll bar is at the end!