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 jquery | |
#= require jquery_ujs | |
#= require turbolinks | |
#= require bootstrap | |
# | |
#= require require-config | |
#= require requirejs/require | |
#= require_tree . | |
# | |
define "jquery", -> window.jQuery |
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 has_foo? | |
->(thing) { thing == "foo" } | |
end | |
def has_bar? | |
->(thing) { thing == "bar" } | |
end | |
def has_baz? | |
->(thing) { thing == "baz" } |
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 'rspec' | |
require 'person' | |
describe "descendants" do | |
it "returns all its descendants" do | |
sonny = Person.new('Sonny') | |
pa = Person.new('Pa', sonny) | |
grandpa = Person.new('Grandpa', pa) | |
expect(Person.all_descendants_of(grandpa).map(&:name)).to eq ['Pa', 'Sonny'] |
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 SafeStruct | |
def self.with_attributes(params) | |
params.keys.map do |key| | |
define_method(key) do |&block| | |
ivar = instance_variable_get("@#{key}".to_sym) | |
if block && !ivar.nil? | |
block.call(ivar) | |
end | |
ivar | |
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
exports.first = function(l) { | |
return l[0] | |
}; | |
exports.rest = function(l) { | |
return l.reduce(function(accumulator, item, index) { | |
if(index > 0) { | |
accumulator.push(item); | |
} | |
return accumulator; |
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
# Runs exec inside the fork in order to capture the output of the subprocess | |
pid = fork { exec('ssh 127.0.0.1') } | |
_, status = Process.waitpid2(pid) | |
puts status.success? |
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 value_and_identity(object) | |
"(Value: #{object.inspect}, ID: #{object.object_id})" | |
end | |
def increment(val) | |
puts "---> #increment received argument #{value_and_identity(val)}" | |
result = val += 1 | |
puts "---> 'result' is #{value_and_identity(result)}" |
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 'sinatra' | |
require 'only_http' | |
use OnlyHttp | |
get '/' do | |
"We'll never see this over HTTPS!" | |
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
Recipe Compile Error in /etc/chef-custom/recipes/cookbooks/main/recipes/default.rb | |
================================================================================ | |
NameError | |
--------- | |
Cannot find a resource for sysctl on gentoo version 2.1 | |
Cookbook Trace: | |
--------------- | |
/etc/chef-custom/recipes/cookbooks/redis/recipes/default.rb:9:in `from_file' |
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
new DeclarativeForm({ | |
method: 'POST', | |
action: '/my-server/does/things/with/forms', | |
localCsrfToken: 'a7u9k9j87o7kj9j89o9jjk7o', | |
components: { | |
name: { | |
type: 'text', placeHolder: 'Enter your name...', initialValue: '', | |
validations: { required: true, minLength: 10 } | |
}, | |
dateOfBirth: { |
OlderNewer