Skip to content

Instantly share code, notes, and snippets.

View Serabe's full-sized avatar

Sergio Arbeo Serabe

View GitHub Profile
// The production source code.
var ALIVE = 1;
var DEAD = 0;
function Game(height, width) {
this.height = height || 100;
this.width = width || 100;
this.table = new Array(this.height);
for(var i = 0; i < this.height; i++) {
this.table[i] = new Array(this.width);
/*
* CELLS
*/
function Cell() {}
Cell.prototype.step = function(num) {
if(this.keepState().indexOf(num) >= 0) {
return this;
}
// The production source code.
// Cell related stuff
function alive() {
return {state: 'alive', keptState: [2,3], nextState: dead};
};
function dead() {
return {state: 'dead', keptState: [0,1,2,4,5,6,7,8], nextState: alive};
};
@Serabe
Serabe / f.js
Created February 13, 2014 13:06
var a = function(x) { console.log(x); }
var b = a.toString().match(/\(([^{]*)\).* \{(.*)\}/)
var args = b[1].split(',').map(function(el) { return el.trim(); });
args.push(b[2] + b[2]);
var fn = Function.apply({}, args);
fn(1);
@Serabe
Serabe / f.js
Created February 13, 2014 13:09
var twice = function(a) {
var b = a.toString().match(/\(([^{]*)\).* \{(.*)\}/)
var args = b[1].split(',').map(function(el) { return el.trim(); });
args.push(b[2] + ";" + b[2]);
return Function.apply({}, args);
}
class CustomDateInput < SimpleForm::Inputs::Base
def input
@builder.date_field(attribute_name, input_html_options).html_safe
end
end
<%= simple_form_for @event do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.input :start_at, as: :custom_date %>
<%= f.input :end_at, as: :custom_date %>
<%= f.submit %>
<% end %>
rails g model Reservation user:references event:references
Añadir has_many :reservations a User y Event
class Reservation
class << self
def for_event_and_user event, user
Reservation.where(event: event, user: user)
end
end
@Serabe
Serabe / redis-cli
Last active August 29, 2015 13:57
A simple and more powerful redis cli. Written in Ruby, based on pry, redis and hiredis.
#!/usr/bin/env ruby
def are_required? gem_name
require gem_name
true # It could have been already required
rescue LoadError
puts "Install #{gem_name} gem."
false
end
everything_is_good = ['redis', 'hiredis', 'pry'].inject(true) do |memo,gem_name|
def last_n n
KeepLastN.new self, n
end
class KeepLastN
attr_reader :conn, :limit
def initialize conn, n
@conn = conn