- Your class can be no longer than a hundred lines of code.
- Your methods can be no longer than five lines of code
- You can pass no more than four parameters and you can't just make it one big hash.
- In your controller, you can only instantiate one object, to do whatever it is that needs to be done.
- Your view can only know about one instance variable.
- Your Rails view should only send messages to that object i.e., no Demeter violations.[ "thunder dome principal". Translated: one model in, one model out! ]
- Rules are meant to be broken if by breaking them you produce better code. [ ...where "better code" is validated by explaining why you want to break the rule to someone else. ]
- cane: https://github.com/square/cane
- Capybara: https://github.com/jnicklas/capybara
- REST Client: https://github.com/archiloque/rest-client
- Savon: https://github.com/savonrb/savon
- Unicorn: https://github.com/defunkt/unicorn
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 "kafka" | |
require "logger" | |
require "optparse" | |
script_name = File.basename($0, File.extname($0)) | |
default_logfile = "logs/#{script_name}.log" | |
default_offset = "latest" | |
options = {} | |
OptionParser.new do |opts| |
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 NilWhatAreYouDoingStahp | |
attr_accessor :not_nil | |
def initialize | |
@not_nil = "I'm not nil! I'm a value!" | |
end | |
def wat | |
if not_nil.nil? | |
not_nil = "Ok, now I'm not nil." |
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 Nilbog | |
class_eval do | |
Object.methods.each do |method| | |
class_eval("def #{method}; #{nil}; end") | |
end | |
end | |
def method_missing(_) | |
nil | |
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
check_letter() { | |
echo "$1: `type $1 >/dev/null && type $1 | sed -e \"s/^$1: //\" | tr '\n' ' '`"; | |
} | |
letters() { | |
for letter in {a..z}; do | |
check_letter $letter | |
check_letter `echo $letter | tr a-z A-Z` | |
done | |
} |
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
'use strict'; | |
// none of this is good | |
class Greet { | |
required(arg) { | |
throw new Error(`${arg} is required`); | |
} | |
requireArgs(given, required) { |
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 ssl_config do | |
ssl_config(client_cert, client_cert_key) | |
end | |
def ssl_config(_client_cert=nil, _client_cert_key=nil) do | |
[] | |
end | |
def ssl_config(client_cert, client_cert_key) do | |
[ |
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
is_binary <<255::size(8)>> # => true | |
is_bitstring <<255::size(8)>> # => true | |
is_binary <<255::size(4)>> # => false | |
is_bitstring <<255::size(4)>> # => true | |
# So a binary is a bitstring but a bitstring isn't necessarily a binary. | |
# We can see that effect in pattern matching as well: | |
<<255::size(4)>> # => <<15::size(4)>> | |
<<x>> = <<255::size(4)>> # => MatchError! |
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
original = [ | |
{ a: { foo: 1 } }, | |
{ b: { foo: 2 } }, | |
{ c: { foo: 3 } }, | |
{ d: { foo: 4 } }, | |
{ e: { foo: 5 } }, | |
{ f: { foo: 6 } }, | |
{ g: { foo: 7 } }, | |
] |
NewerOlder