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
# this is totally untested... | |
require 'rest-client' | |
require 'json' | |
PAGE_REGEX = /page=(?<page>\d+)/ | |
def get_paginated(base_url, length=30) | |
base_url += "?per_page=#{length}" | |
items = [] |
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
[chefvm stage_dr] simple-passenger-cookbook $ cat Berksfile | |
source 'https://supermarket.chef.io' | |
metadata | |
cookbook 'apt', '~> 4.0' | |
cookbook 'build-essential', '= 2.4.0' | |
[chefvm stage_dr] simple-passenger-cookbook $ rm Berksfile.lock | |
[chefvm stage_dr] simple-passenger-cookbook $ bundle exec berks install | |
Resolving cookbook dependencies... |
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
irb(main):001:0> def equals(a, b='B', c='C'); p a; p b; p c; end | |
=> :equals | |
irb(main):002:0> def colon(a, b: 'B', c: 'C'); p a; p b; p c; end | |
=> :colon | |
irb(main):003:0> equals('A', c='see') | |
"A" | |
"see" | |
"C" | |
=> "C" | |
irb(main):004:0> colon('A', c: 'see') |
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 'net/http' | |
require 'rspec' | |
class ApiClient | |
def initialize(server_url, username, password) | |
@server_url, @username, = server_url, username | |
authenticate(password) | |
end | |
def authenticate(password) |
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 Hash | |
def to_java_properties_hash(prefix='') | |
properties = {} | |
self.each do |property, value| | |
new_prefix = prefix.empty? ? property.to_s : prefix + '.' + property.to_s | |
if value.respond_to? :to_java_properties_hash | |
properties.merge!(value.to_java_properties_hash(new_prefix)) | |
else | |
properties[new_prefix] = value.to_s |
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
output = 'peer count: 6 | |
ip address: 1.2.3.4 | |
status: up | |
client version: 1.2.3 | |
ip address: 1.2.3.5 | |
status: up | |
client version: 1.3.0 |
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
a = b | |
a.b = B | |
c.e = true | |
1234=1234 |
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
~ $ cat tmp/erb_example.rb | |
#!/usr/bin/env ruby | |
require 'erb' | |
template = "number: <%= @number %>\nstring: <%= @string %>" | |
@number = 3.4 | |
@string = 'blue' | |
puts ERB.new(template).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
^\w+(\.\w+)*@(\w+\.)*\w+\.\w+$ |
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
# given a list of hashes: | |
foo = [ | |
{ a: whatever, b: whatever, c: whatever }, | |
{ a: whatever, b: whatever, c: whatever }, | |
# ... | |
] | |
bar = { b: whatever, y: whatever, z: whatever } |