Skip to content

Instantly share code, notes, and snippets.

View shireeshj's full-sized avatar
🏠
Working from home

Shireesh Jayashetty shireeshj

🏠
Working from home
View GitHub Profile

One day of Go

One of my ongoing resolutions is to learn a new programming language every year. I've been looking at Go for a while and I thought it would be fun to use the 'holiday' today to really get cranking. I recorded some random impressions as I was chugging along...

When learning a language, I'm one of those people that can't simply read documentation and contrived code examples with any usable level of recall -- I need to internalize it by writing code to solve a legitimate problem. So, I decided to write a little library, a parser for the Linux /proc filesystem. There aren't very many good ones that I've found for Go (and I am thinking of some projects I may want to use it for in the future).

Steps taken:

  1. Read a bit of code
# scenario:
# - you work from a dev account that has git authentication with keys in place
# - you use a sudoer account (first_user) to ssh and run chef on a server
# - the chef recipes deploy an application under a second_user
# - first_user and second_user don't have git keys in place and you want to use forwarding
# initial run (bootstrapping maybe)
include_recipe 'helper'
#!/bin/sh
# linux firewall/forwarding
modprobe iptable_nat
echo 1 | tee /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 10.10.10.1/2 -o eth0 -j MASQUERADE
# install openvpn
apt-get update && apt-get install -y openvpn
cd /etc/openvpn/
INSTANCE=$(curl http://169.254.169.254/latest/meta-data/public-hostname)
openvpn --genkey --secret ${INSTANCE}.key
1.9.3-p327
@shireeshj
shireeshj / irb3.rb
Created July 11, 2012 07:51
irb3 - Run an IRB-esque prompt over multiple Ruby implementations at once using rvm
#!/usr/bin/env ruby
# encoding: utf-8
#
# This is a modified version of irb3 by Peter Cooper. This uses RVM instead of rbenv
# irb3 - Runs an IRB-esque prompt (but it's NOT really IRB!) over multiple
# versions of Ruby at once (using rvm)
# Contributor: Shireesh Jayashetty ( elitmus.com )
#
# Original version: https://gist.github.com/1229225
# By Peter Cooper, BSD licensed
@shireeshj
shireeshj / irb3.rb
Created July 11, 2012 07:48 — forked from ashleyw/irb3.rb
irb3 - Run an IRB-esque prompt over multiple Ruby implementations at once using rbenv
#!/usr/bin/env ruby
# encoding: utf-8
# irb3 - Runs an IRB-esque prompt (but it's NOT really IRB!) over multiple
# versions of Ruby at once (using rbenv)
#
# By Peter Cooper, BSD licensed
#
# 1. Type in expressions and press enter.
# 2. Leave space on the end of lines to enter more lines.
@shireeshj
shireeshj / migrate_s3.rake
Created May 8, 2012 05:36
rake task to migrate paperclip attachments to Amazon S3
namespace :attachments do
task :migrate_to_s3 => :environment do
require 'aws/s3'
# Load credentials
s3_options = YAML.load_file(File.join(Rails.root, 'config/s3.yml')).symbolize_keys
bucket = s3_options[:bucket_name]
# Establish S3 connection