Skip to content

Instantly share code, notes, and snippets.

View atheiman's full-sized avatar
😬

Austin Heiman atheiman

😬
View GitHub Profile
@atheiman
atheiman / install.sh
Created June 26, 2016 02:28 — forked from loren/install.sh
Chef install script with retry logic on dpkg to get around race with unattended upgrades
#!/bin/sh
# WARNING: REQUIRES /bin/sh
#
# - must run on /bin/sh on solaris 9
# - must run on /bin/sh on AIX 6.x
#
# Copyright:: Copyright (c) 2010-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@atheiman
atheiman / README.md
Last active July 17, 2016 18:00
Deep merge hashes. If both values are numeric they are summed. (Ruby)

Deep merge hashes. If both values are numeric they are summed.

$ ruby deep_sum_merge.rb
source:
layer_1: 10
deeper:
  layer_2: 20
  deeper:
    layer_3: 30
 deeper:
rbenv versions
which bundle
bundle --help
@atheiman
atheiman / README.md
Last active October 10, 2016 20:56
apache_fun

Just messing around with parsing a log file with Ruby...

$ ruby apache_fun.rb
01:02:03 report
  2 INFO messages
  1 WARN messages
01:02:05 report
  2 ERROR messages
 1 INFO messages
# 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 = []
[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...
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')
@atheiman
atheiman / java_properties.rb
Last active January 29, 2017 01:00
Ruby hash to Java properties file
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
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)
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