During the creation of our team’s encrypted data bags for Chef, the JSON was generated on a single line in the files. While this is great for keeping the size small during deployments, it’s not the most helpful when looking at a diff on github to see what was changed.
We found while we were re-encoding the data bags recently that the JSON was being split out into a more “prettified” format by a newer version of Knife. I put together a line of code (mixed bash and Python) to navigate through a folder tree and re-format the other JSON files in the same way as the new version of Knife (with a 2 space indention instead of the Python JSON library’s standard 4):
find . -type f -iname "*.json" -print0 | while IFS= read -r -d $'\0' line; do if [ $(cat "$line" | wc -l) -eq 0 ] ; then JSONBLOB=$(cat "$line" | python -c "import json, sys; print(json.dumps(json.loads(sys.stdin.read()), indent=2, separators=(',', ': ')))"); echo "$JSONBLOB" > "$line"; fi; done
Here is the code spaced out into a slightly more readable format:
find . -type f -iname "*.json" -print0 | while IFS= read -r -d $'\0' line do if [ $(cat "$line" | wc -l) -eq 0 ] then JSONBLOB=$(cat "$line" | python -c "import json, sys; print(json.dumps(json.loads(sys.stdin.read()), indent=2, separators=(',', ': ')))") echo "$JSONBLOB" > "$line" fi done
Copying and pasting this command will run this in the current directory and all subdirectories. You can change the directory this is run on by changing the target in find
command to find /directory/path
.
I recently helped Virginia Tech Television (VTTV) put together their new website (soon to be available at both vttv.vt.edu and vttv33.com, currently available at vttv33.com/beta). The previous site, a well designed custom PHP CMS, has unfortunately grown stagnant from neglect after the station stopped using Blip.tv in favor of YouTube.
This sort of neglect is an almost constant problem with student organization websites. Those who come in and understand enough code to construct a new page are usually around just long enough to put a page online, maintain the new system for a year, and then graduate or move on to other projects. The system sits infrequently modified from that point on, leading to outdated information and, in the case of many Wordpress installations, copious amounts of spam.
To hopefully mitigate that, thew new VTTV site was designed with two goals in mind: to give basic (easily updatable) information, and to get visitors over to the consistently-maintained YouTube channel.
At the end of September, I took part in a Startup Weekend for the first time. While I had participated in a number of Hackathons, Startup Weekend Blacksburg was the first competition that wasn’t entirely “code code code!”, but additionally focused on business development and market validation.
After pitches on the first night, I joined a team with six other people, consisting of five software developers, and two business majors. The pitch, which later adopted the name Pet My Pets, was for a website for pet owners that would match people who needed their pets watched with people who wanted pets but for one reason couldn’t take one on full-time. Effectively, it was AirBnb for pets.
From left to right: Joe Fletcher, Matthew Hubbard, Michael Liu, Wilson Mitchell, Subir Jolly, Phil Sayre, and Andrew Mussey.
Our focus for the weekend was to build the website and to verify that there were customers that would be willing to either have their pets watched or to “rent” pets. Interviews with people throughout the Blacksburg community resulted an overwhelmingly positive response on both sides. While some people were concerned about letting a random person from the internet watch their pet, they said they would be put at ease if there was some sort of verification or background checking in place.
For our website, we set up a Python Django application backed by SQL Lite with a Bootstrap template on top. SQL Lite functioned perfectly for rapid, distributed development. If the idea were to progress beyond Startup Weekend, we had planned to migrate to MySQL. Dynamic content on the website was scripted using jQuery, and the page was hosted on AWS (thanks to the free Startup Weekend credits). While the app isn’t online yet, we were able to launch a landing page on the very first night using a Bootstrap template backed by a Lua script hosted on Webscript.io. The Webscript.io platform served as a great, quick, database-free way to get email addresses of interested customers and to send them a fast “Welcome” message.
We didn’t come out of the weekend with any awards, but we did close out Sunday with a ton of knowledge. My biggest takeaway came in the form of team dynamic; while developers at Startup Weekend events are typically harder to acquire, our team containing five almost ran into the opposite issue of having too many developers. A single developer could have played the role of product manager and more effectively divvied up the workload for the other programmers. This would have been a huge help in preventing overlap and improve efficiency while building.
The Roanoke Times has a great writeup on the weekend, which includes more information about Pet My Pets. If you’re interested in the idea, you can check out the Pet My Pets website at http://petmypets.co.
A huge thanks goes out to Alex Meng, Viktoriya Leshchenko, David McGrath, and Lauren Rose for offering up their pets for the production of the video at the top of this post.
Edit: As Shane pointed out in the comments, there is a new Install Agent feature in Cloud Intelligence that offers a similar one line agent install. Visit Cloud Intelligence to check it out!
After recently setting up a new Rackspace Cloud Server with the Cloud Monitoring agent, I was annoyed by the length of the install Knowledge Center article. I decided to write a script to assist in and speed up the install of this agent.
Before running this script, you will need the following:
curl
installed on your server.To install the Cloud Monitoring agent, simply run this command from your Cloud server:
sudo bash -c "$(curl -s https://raw.githubusercontent.com/amussey/blog-posts/master/2014/10_Rackspace-Monitoring-Agent-Installer/install.sh)"
This script has been tested with all currently available Performance flavor Cloud servers that have OSes supported by the Cloud Monitoring Agent Knowledge Center article (as of Oct 2014). For more information on compatibility and to view the contents of the script, visit the github repo for this blog post. As always, pull requests and comments are welcome!
I recently open sourced the code for the website I use for DJ booking, DJMu-Z.com. On the front page, I host this mouse responsive “M” animation using a single image and a piece of Javascript. You can check out the code involved on Bitbucket:
During the summer, Rackspace Blacksburg set on a consistent schedule of office-wide tech talks. These talks ranged in subject from conference presentations to new technologies to managerial styles. Above are some of the talks that have been given in the last couple months that I have had a chance to record and post to the Racksburg YouTube channel.
You can watch all the Racksburg Tech Talks via the Rackspace Tech Talks playlist. You can see more content from the Rackspace Blacksburg office on the Racksburg YouTube channel.
The Rackspace Blacksburg (Racksburg) office. Taken for the Racker Rush website.
I’ll admit it: I’ve been completely sucked into webscript.io. Webscript.io is a site that allows for small Lua scripts to be hosted on user-selected URLs. A coworker and I have spent the last two weeks designing new dashboards for our Rackspace team, scraping websites, and throwing small scripts back and forth. The number of written lines of Lua between the two of us has easily broken into the thousands.
While working on a recent script, I ran into a situation where JSON would need to be input and parsed. Unfortunately, the built-in webscript.io JSON.parse
function does not have any sort of decent error handling. If there is a problem, your script 500s and the user receives a blank response.
There are a lot of incredibly in-depth Lua JSON libraries, but keeping with webscript.io’s spirit of “small scripts”, I was hesitant to import any of them in their entirety. All I needed from these libraries was validation - is this string valid JSON, or are there missing brackets and broken syntax?
This led to the creation of a Lua JSON Validator. The module does exactly as described above: takes a string as input and returns true or false if it’s valid JSON.
To use the module, you simply need to import it via a require
statement:
local validJson = require "amussey/lua-json-validator/validJson" if validJson(jsonString) then -- interact with valid JSON else -- report invalid JSON end
A series of test cases are also provided with the module.
To view the source code, visit the github repo:
https://github.com/amussey/lua-json-validator/
As always, pull requests on the repo or comments on this post are welcome!
I had the opportunity to film the Racksburg (Rackspace Blacksburg) response to the ALS Ice Bucket challenge from Graham Weston last week. Awesome to see so many participating Rackers!
While constructing the Github Team Pull Request Highlighter, I ran into the need to translate color codes back and forth between hex (#ff0000
) and RGB/RGBA (rgba(255, 0, 0, 1)
).
This led to the construction of a micro-library hex-to-rgb.js (direct link to the library). This library allows for easy conversion between the formats through two functions: hexToRgb
and rgbToHex
.
hexToRgb
returns an object with r, g, and b properties.
var color = hexToRgb("#1fbcff");
color.toString(); // rgb(31, 188, 255)
color.r; // 31
color.g; // 188
color.b; // 255
hexToRgb
can also accept an alpha
value has a second parameter. This allows the output of rgba
strings.
var color = hexToRgb("#1fbcff", 0.5);
color.toString(); // rgba(31, 188, 255, 0.5)
color.r; // 31
color.g; // 188
color.b; // 255
color.alpha; // 0.5
rgbToHex
returns a hex string in the format #ffffff
. It can accept a wide variety of inputs.
rgbToHex(31, 188, 255); // #1fbcff
rgbToHex("rgb(31, 188, 255)"); // #1fbcff
rgbToHex("rgba(31, 188, 255, 0.5)"); // #1fbcff
rgbToHex
can also accept the color objects produced by hexToRgb
.
var color = hexToRgb("#1fbcff");
rgbToHex(color); // #1fbcff
var color2 = hexToRgb("#1fbcff", 0.5);
rgbToHex(color2); // #1fbcff
The repo for this library is available here (or click here if you want save time and go directly to the library).