- Ve problemas
- Encuentra soluciones
- Simplifica
- Automatiza
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
# Swappable Mixins in CoffeeScript | |
# ================================ | |
# Many thanks to Hashmal, who wrote this to start. | |
# https://gist.github.com/803816/aceed8fc57188c3a19ce2eccdb25acb64f2be94e | |
# Usage | |
# ----- | |
# class Derp extends Mixin |
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
# Expects that a given ActiveRecord model will have the given records. | |
# | |
# Examples | |
# -------- | |
# | |
# # Expect two people in the database with the given attributes | |
# Person.should have_records [{name: 'David', age: 12}, {name: 'Peter', age: 13}] | |
# | |
# # Expect one person in the database with the given attributes | |
# Person.should have_records name: 'David', age: 12 |
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
if Rails.env == 'development' || Rails.env == 'test' | |
def $stdout.puts_with_color(*args) | |
print "\033[32m" | |
puts_without_color *args | |
print "\033[0m" | |
end | |
klass = class << $stdout; self; end | |
klass.alias_method_chain :puts, :color |
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
<html> | |
<head> | |
<script type="text/javascript"> | |
function toggle() { | |
var toggledDiv = document.getElementById('toggledDiv'); | |
if (toggledDiv) { | |
toggledDiv.parentNode.removeChild(toggledDiv); | |
} else { | |
toggledDiv = document.createElement('div'); | |
toggledDiv.id = 'toggledDiv'; |
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
require "strscan" | |
class Command | |
end | |
class Name < Command | |
attr_reader :name | |
def initialize(name) | |
@name = 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
class Int64 | |
def palindrome? | |
num = self | |
reverse = 0_i64 | |
while num > 0 | |
dig = num % 10 | |
reverse = reverse * 10 + dig | |
num = num / 10 | |
end | |
self == reverse |
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
Directions = [:up, :down, :left, :right] | |
class Board | |
getter :cells | |
def initialize | |
@cells = [ | |
['x', 'x', ' ', 'o', ' ', 'x', 'x'], | |
['x', 'x', ' ', 'o', ' ', 'x', 'x'], | |
[' ', ' ', 'o', 'o', 'o', ' ', ' '], |