Skip to content

Instantly share code, notes, and snippets.

@adampats
adampats / skip.rb
Created July 7, 2015 20:31
skipping item in enumerable
@panels = @servicelist.map do |service|
next if service[:hidden] == "true"
{
title: service[:title],
panel_name: __method__.to_s,
icon: service[:logo],
query_string: {},
id: service[:id]
}
end
@adampats
adampats / cert.sh
Created July 10, 2015 06:00
Generate self-signed cert one-liner
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -subj "/CN=$HOSTNAME/O=Company/C=US"
@adampats
adampats / images.rb
Created July 21, 2015 20:36
images hash
images = [{:image_id=>"ami-04692a6c",
:image_location=>"979382823631/bitnami-djangostack-1.6.4-0-dev-linux-ubuntu-12.04.4-x86_64-ebs-ami-e651b78e-3-ami-5e24a136",
:state=>"available",
:owner_id=>"979382823631",
:creation_date=>"2015-02-03T17:30:54.000Z",
:public=>true,
:architecture=>"x86_64",
:image_type=>"machine",
:kernel_id=>"aki-919dcaf8",
:name=>"bitnami-djangostack-1.6.4-0-dev-linux-ubuntu-12.04.4-x86_64-ebs-ami-e651b78e-3-ami-5e24a136",
@adampats
adampats / spec.rb
Created August 4, 2015 17:08
RbVmomi VirtualMachineConfigSpec
spec = {
deviceChange: [
{
operation: :edit,
device: RbVmomi::VIM::VirtualCdrom(
key: 2,
controllerKey: 200,
backing: RbVmomi::VIM::VirtualCdromAtapiBackingInfo(
deviceName: ""
),
@adampats
adampats / process.rb
Last active August 26, 2015 21:10
ERB result
# define some stuff
@var1 = "hello"
@var2 = { key: "stuff", value: "world" }
# populate using ERB
e = ERB.new( File.read('test.erb') )
e.result(binding)
@adampats
adampats / arrays.rb
Created September 1, 2015 18:30
Combine two arrays of hashes
a = [
{ key: "key1", value: "value1" },
{ key: "key2", value: "value2" }
]
b = [
{ key: "key3", value: "value3" },
{ key: "key4", value: "value4" }
]
a.push(b)
@adampats
adampats / optargs.sh
Created September 14, 2015 22:50
optargs issue
#!/bin/bash
usage_message=" Usage: sudo bash start-registry.sh -u [HT_USER] -p [HT_PASS]"
if (($# == 0)); then
echo "Missing opts."
echo "$usage_message"
exit 1
fi
@adampats
adampats / configxml-post.sh
Created September 15, 2015 17:58
Create new Jenkins job via API
jenkins_server='jenkins-dev.domain.net'
job_name='my-new-branch-job'
username='adam'
curl -s -k -X POST "https://$jenkins_server/createItem?name=$job_name" \
--data-binary @config.xml \
-H "Content-Type:text/xml" \
-u $username
# enter password when prompted
@adampats
adampats / get-configxml.sh
Created September 15, 2015 18:00
Get jenkins job config.xml
jenkins_server='jenkins-dev.domain.net'
job_name='app-deploy'
username='adam'
curl -X GET -u $username -k "https://$jenkins_server/job/$job_name/config.xml" -O
# prompted for password
@adampats
adampats / create-csr.sh
Created September 15, 2015 18:03
Sample cert request with SAN
# create private key
openssl genrsa -out app.key 2048
# create config/ini file for request
# generate csr
openssl req -new -out app.csr -key app.key -config request.ini
# issue from CA using CSR