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
omg = [1,2,3] | |
omg ===Array # => false | |
Array === omg # => true | |
omg.is_a? Array # => true | |
tmp = 1 | |
tmp.is_a? Array #=> false |
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 RomanNumeral | |
VALUES_OF_LETTERS = { I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000 } | |
MODERN_ROMAN_PATTERNS = { CM: 900, CD: 400, XC:90, XL: 40, IX: 9, IV: 4 } | |
def self.i_to_old_roman int | |
i_to_roman int, VALUES_OF_LETTERS | |
end | |
def self.i_to_modern_roman int |
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 'csv' | |
SAMPLE_DATA = {"key1": "value1", "key2": "value2", "key3": "value3"} | |
headers = JSON.parse(SAMPLE_DATA).keys | |
input_lines = File.readlines "path/to/log/file" | |
parsed_line = 0 | |
csv_file = CSV.open "path/to/file.csv", "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
# See http://docs.opscode.com/config_rb_knife.html for more information on knife configuration options | |
current_dir = File.dirname(__FILE__) | |
log_level :info | |
log_location STDOUT | |
node_name "YOUR OPSCODE USERNAME" # The actual name will be set when provisioning | |
client_key "#{ENV['HOME']}/.chef/USERNAME.pem" | |
validation_client_name "ORGANIZATION_NAME-validator" | |
validation_key "#{ENV['HOME']}/.chef/ORGANIZATION_NAME-validator.pem" | |
chef_server_url "https://api.opscode.com/organizations/ORGANIZATION_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
mkdir test_prj | |
cd test_prj | |
berks init | |
create Berksfile | |
create Thorfile | |
create .gitignore | |
run git init from "." | |
create Gemfile | |
create Vagrantfile |
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
name 'base' | |
description 'Create users and sudoers, configure ssh, set timezone and swap' | |
run_list "recipe[apt]", "recipe[user::data_bag]", "recipe[base::bootstrap]", | |
"recipe[build-essential]", "recipe[git]" | |
default_attributes( | |
users: ['config'], | |
authorization: { | |
sudo: { |
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 'flickraw' | |
require 'mini_magick' | |
require 'parallel' | |
def get_photo_urls_from_photoset(flickr, photoset_id) | |
total_pages = nil | |
current_page = 1 | |
urls = [] | |
opts = { | |
photoset_id: photoset_id, |
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
# 1) Create your private key (any password will do, we remove it below) | |
$ cd ~/.ssh | |
$ openssl genrsa -des3 -out server.orig.key 2048 | |
# 2) Remove the password | |
$ openssl rsa -in server.orig.key -out server.key |
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 foo | |
some_function(true, { :before => {a: 1}, | |
:after => {b: 2} }) | |
call_block { do_something } | |
end | |
def bar | |
case @var | |
when 1 | |
print [1..42] |
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
Vagrant.configure("2") do |config| | |
config.vm.hostname = "NODE NAME" # will be the node name on chef-server. | |
config.vm.box = "BOX NAME" | |
config.vm.box_url = "BOX IMAGE DOWNLOAD URL WHEN BOX DOES NOT EXIST" | |
config.vm.boot_timeout = 180 # Raise error when bootup takes too long | |
config.omnibus.chef_version = :latest # Use the latest chef version on this box | |
#config.vm.network :private_network, ip: "33.33.33.10" # THIS CAUSES SSH PROBLEM, remove it |