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
binsearch = (a, t, probe) -> | |
min = 0 | |
max = a.length - 1 | |
while (min <= max) | |
i = Math.floor((min + max) / 2) | |
v = a[i] | |
probe? i, v |
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
--- | |
beans: | |
invoice_service: | |
class: InvoiceService | |
method: constructor | |
arguments: | |
- bean:billing_provider | |
- bean:asset_provider | |
- dry_run: true | |
billing_provider: |
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 | |
# | |
# Taken from http://stackoverflow.com/questions/819263/2357790#2357790 | |
def age_at(dob, date) | |
date.year - dob.year - ((date.month > dob.month || (date.month == dob.month && date.day >= dob.day)) ? 0 : 1) | |
end | |
require "date" |
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
registry = ConstructorRegistry.new("My plugin registry") | |
type = ProviderClass | |
argument_adaptor = ArgumentAdaptor::PositionalArgument.new(:foo, [:bar], :baz) | |
constructor = Constructor.new(type, argument_adaptor) | |
registry.register(:provider1, constructor) | |
factory = Factory.new(registry) | |
provider = factory.create(:provider1, foo: "fooish", baz: "wombat") |
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
module Starjuice | |
module Factory | |
module Constructor | |
class Adaptor | |
def initialize(adaptor = nil) | |
@adaptor = adaptor || ->(properties) { [properties] } | |
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
<% | |
require 'json' | |
require 'net/http' | |
json = Net::HTTP.get('169.254.169.254', '/latest/meta-data/iam/security-credentials/chef-lab-workstation') | |
creds = JSON.parse(json) | |
%>--- | |
driver: | |
name: ec2 | |
aws_access_key_id: <%= creds["AccessKeyId"] %> |
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
execute "reboot" do | |
only_if { ::File.exists?("/var/run/reboot-required") } | |
node.run_state['reboot'] = true | |
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
--- | |
driver: | |
name: ec2 | |
aws_access_key_id: ... | |
aws_secret_access_key: ... | |
aws_session_token: ... | |
aws_ssh_key_id: chef-lab | |
ssh_key: <%= ENV['HOME'] %>/.ssh/chef-lab.pem | |
subnet_id: subnet-3eb66215 | |
vpc_id: vpc-1cf49679 |
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 self.encrypt(password, cleartext) | |
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc") | |
cipher.encrypt | |
iv = cipher.random_iv | |
salt = Time.now.nsec.to_s | |
iterations = ITERATIONS | |
key_len = cipher.key_len | |
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(password, salt, iterations, key_len) | |
ciphertext = cipher.update(cleartext) + cipher.final | |
return ciphertext |
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 'spec_helper' | |
require 'base_library/test/plugin_spec' | |
$LOAD_PATH.unshift('../../lib', __FILE__) | |
require 'base_library/plugin/my_plugin' | |
spec = BaseLibrary::Test::PluginSpec.new(BaseLibrary::Plugin::MyPlugin.new) | |
spec.run |