Skip to content

Instantly share code, notes, and snippets.

View gregohardy's full-sized avatar

Greg Hardy gregohardy

  • Puppet Labs
  • Belfast
View GitHub Profile
@gregohardy
gregohardy / Installation and runnanization
Last active July 29, 2016 15:40
Azure ARM simple ruby examples
$ gem install gem install azure_mgmt_compute
$ ruby status.rb
There are [1] in this account
AZURE VM IDs FOR THIS ACCOUNT
=============================
/subscriptions/<subscription id###>/resourceGroups/CLOUD-ACCEPTANCE-TESTS/providers/Microsoft.Compute/virtualMachines/CLOUD-3cdbed43
=============================
@gregohardy
gregohardy / OSXtest.sh
Last active October 8, 2016 09:24
gzip => base64 encoding of long strings => decode => gunzip
#!/bin/bash
BAR=$(printf '#!/bin/bash\ntouch /tmp/ididit\necho \"root:changeme2016\" | chpasswd"' | gzip | openssl base64 -A)
echo $BAR | python -m base64 -d | gunzip
@gregohardy
gregohardy / ruby_spec.rb
Last active October 10, 2016 15:39
Server spec
require 'spec_helper'
require 'pry'
%w(serverspec rake).each do |package_name|
describe package(package_name) do
it { should be_installed.by('gem') }
end
end
[
@gregohardy
gregohardy / azure_resource_content.pp
Created March 28, 2017 13:41
azure resource with content
azure_resource_group { 'test-rg':
ensure => present,
location => 'eastus',
}
# Example with a source
azure_resource_template { 'test-storage-account':
ensure => 'present',
resource_group => 'test-rg',
source => 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json',
params => {
@gregohardy
gregohardy / cleanup.rb
Last active May 9, 2018 17:04
Azure Account Managment
require 'azure_mgmt_compute'
require 'azure_mgmt_resources'
require 'azure_mgmt_storage'
require 'azure'
include Azure
include Azure::ARM::Compute
include Azure::ARM::Compute::Models
include Azure::ARM::Resources
@gregohardy
gregohardy / start.json
Last active December 14, 2017 16:19
All the API calls for an Azure ARM VM.
Create Resource Group
HTTPS request
put subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}
{
"resourceGroupName": "ccgh792",
"subscriptionId": "c82736ee-c108-452b-8178-f548c95d18fe"
}
Body:
{
"location": "westus"
@gregohardy
gregohardy / Dockerfile
Created December 20, 2017 17:53
Dockerfile ENTRYPOINT example of running a script
ENTRYPOINT ["sh", "-c", "find /etc/puppetlabs/code/modules/azure/lib | grep rb | xargs rufo"]
build-docker-linux: OS_TYPE = linux
build-docker-linux: build-docker
build-docker:
@if [ -z "$(IMAGE)" ];then\
docker build -t $(DOCKER_IMAGE) --build-arg targetos=$(OS_TYPE) .;\
else\
docker build -t $(IMAGE) --build-arg targetos=$(OS_TYPE) .;\
fi
@gregohardy
gregohardy / gist:88e5a3b33fe220c12488890ddb529226
Created September 27, 2018 11:00
Symbolize a nested hash containing arrays.
def symbolize(obj)
return obj.reduce({}) do |memo, (k, v)|
memo.tap { |m| m[k.to_sym] = symbolize(v) }
end if obj.is_a? Hash
return obj.reduce([]) do |memo, v|
memo << symbolize(v); memo
end if obj.is_a? Array
obj
end
@gregohardy
gregohardy / Gemfile
Created February 4, 2019 20:15
Faye messaging ruby example
source 'https://rubygems.org'
gem 'cookiejar', '>= 0.3.0'
gem 'em-http-request', '>= 0.3.0'
gem 'faye-websocket', '>= 0.9.1'
gem 'multi_json', '>= 1.0.0'
gem 'rack', '>= 1.0.0'
gem 'websocket-driver', '>= 0.5.1'
gem 'permessage_deflate', '>= 0.1.0'
gem 'eventmachine', '>= 0.12.0'