Skip to content

Instantly share code, notes, and snippets.

@Cinderhaze
Cinderhaze / parsingAwsJson.rb
Created May 7, 2015 12:33
My first 'successful' attempt at getting the info I need
# JSON Parsing example
require "rubygems"
require "json"
string = '{"desc":{"someKey":"someValue","anotherKey":"value"},"main_item":{"stats":{"a":8,"b":12,"c":10}}}'
parsed = JSON.parse(string) # returns a hash
p parsed["desc"]["someKey"]
p parsed["main_item"]["stats"]["a"]
@Cinderhaze
Cinderhaze / Parsing JSON with Ruby?
Created May 7, 2015 02:51
Trying to parse AWS JSON with ruby
I found a good example of how to parse JSON with ruby on stack overflow here => http://stackoverflow.com/a/13625633
For an example of AWS JSON, I found an example at (http://unix.stackexchange.com/questions/121718/how-to-parse-json-with-shell-scripting-in-linux), but I fixed some errors in the json and have a copy here (https://gist.github.com/Cinderhaze/f122232d15eb700449f0)
I put the above json in a file (ec2s.json) and ran 'gem install json'
I have tried the following in IRB
require 'json'
file = File.open('ec2s.json')
contents = file.read
file.close
{
"OwnerId": "121456789127",
"ReservationId": "r-48465168",
"Groups": [],
"Instances": [
{
"Monitoring": {
"State": "disabled"
},
"PublicDnsName": null,
PROVISIONED="/some-app-dir/PROVISIONED";
if [[ -f $PROVISIONED ]]; then
echo "Skipping provisioning";
exit;
else
echo "Provisioning";
fi
#...do provisioning things
@Cinderhaze
Cinderhaze / RaspberryPiErrorRails
Created December 7, 2014 02:40
Error installing rails on Raspberry Pi
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:1:in `<main>'