Skip to content

Instantly share code, notes, and snippets.

Avatar

Greg Hardy gregohardy

  • Puppet Labs
  • Belfast
View GitHub Profile
@gregohardy
gregohardy / colours-bash.sh
Last active Apr 29, 2020
Bash colours/italics/bold for echo. (works in macos)
View colours-bash.sh
#/bin/bash
function bold()
{
echo "\033[1m${1}\033[22m"
}
function dim()
{
echo "\033[2m${1}\033[22m"
@gregohardy
gregohardy / command
Last active Mar 19, 2020
Find and replace uri's recursively with sed
View command
grep -rl '/utils' ./ | xargs gsed -i "s+/utils+/lib/utils+g"
View delete_aws_resources.rb
#!/usr/bin/ruby
# Assumptions.
# You have tagged your resources with a common tag. This tag is passed by the ENV var below.
# The security group name is the tag_name as well.
require 'aws-sdk-ec2'
tag_name = ENV['PT_tag_name']
@gregohardy
gregohardy / get_vpc.rb
Created Mar 12, 2019
Deferred puppet function
View get_vpc.rb
require 'aws-sdk-ec2'
Puppet::Functions.create_function(:'amazon_aws::get_vpc') do
dispatch :up do
param 'String', :vpc_name
end
def up(vpc_name)
client = Aws::EC2::Client.new(region: 'us-west-2')
vpc_id = ""
@gregohardy
gregohardy / Gemfile
Created Feb 4, 2019
Faye messaging ruby example
View Gemfile
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'
@gregohardy
gregohardy / gist:88e5a3b33fe220c12488890ddb529226
Created Sep 27, 2018
Symbolize a nested hash containing arrays.
View gist:88e5a3b33fe220c12488890ddb529226
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
View Doing a if else statement in Make
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 / Dockerfile
Created Dec 20, 2017
Dockerfile ENTRYPOINT example of running a script
View Dockerfile
ENTRYPOINT ["sh", "-c", "find /etc/puppetlabs/code/modules/azure/lib | grep rb | xargs rufo"]
@gregohardy
gregohardy / start.json
Last active Dec 14, 2017
All the API calls for an Azure ARM VM.
View start.json
Create Resource Group
HTTPS request
put subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}
{
"resourceGroupName": "ccgh792",
"subscriptionId": "c82736ee-c108-452b-8178-f548c95d18fe"
}
Body:
{
"location": "westus"
@gregohardy
gregohardy / cleanup.rb
Last active May 9, 2018
Azure Account Managment
View cleanup.rb
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