This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* CELLS | |
*/ | |
function Cell() {} | |
Cell.prototype.step = function(num) { | |
if(this.keepState().indexOf(num) >= 0) { | |
return this; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomDateInput < SimpleForm::Inputs::Base | |
def input | |
@builder.date_field(attribute_name, input_html_options).html_safe | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def last_n n | |
KeepLastN.new self, n | |
end | |
class KeepLastN | |
attr_reader :conn, :limit | |
def initialize conn, n | |
@conn = conn |
OlderNewer