Thursday, June 21, 2012

Weird string encoding issue with ruby net-ldap lib ( 0.3.1 )


Getting this error:

#

The fix was to enable some invalid encoding checks, so here is the original line ( ~23 net-ldap-0.3.1/lib/net/ber/core_ext/string.rb ):

self.encode('UTF-8').force_encoding('ASCII-8BIT')

After some playing around I found that this works rather well:

self.encode('UTF-8', invalid: :replace, undef: :replace, replace: '' ).force_encoding('ASCII-8BIT')

I couldn't find the git source for the 0.3.1 build, so I just downloaded the gem, and created a new repo.

You can download the gem from here:
https://docs.google.com/open?id=0Bwcyw39lMxDSODdpNTdObHk4bXc

I'm going to try to see if I can get this pushed upstream.

Monday, April 9, 2012

Why use git?

After some serious face time with git and a neat little addon called 'git flow' I've come up with my elevator pitch for using git:

  1. Git is designed to get out of your way and let your development awesomeness shine.
  2. Git is fast, mainly because things like history and checkpoints are all stored locally.  Combined with it's compression bits it's actually much faster then most.
  3. Used with 'git flow' it can make complicated branching strategies and bug fix methodologies a breeze in big orgs with many developers across a disparate geographical area.
We use git here @hpcloud, and I can tell you it's amazing to see what these developers and engineers have done with it.

Wednesday, March 28, 2012

"Why git?" series.

Many moons ago a colleague lamented a story to me that went something like this:

SysEngGuy: I asked DeveloperGuy why we should switch to git
Me: Cool, what was his answer?
SysEngGuy: He said it was better, but when I asked him why he just kept saying "because it's better"
Me: But why is it better?
SysEngGuy: Exactly, why would I be compelled to move to something else "just because."

Even if git is super awesome ( which I now know it is ) you can't expect people to switch over unless you sell them on the idea.  Especially when you're dealing with a SysEngGuy that is deeply entrenched in whatever happens to be the "current" way of doing things.

I'm starting a series of posts answering the question of "why is git better?"  My goal here is to both answer the question, and hopefully in doing so, solidify my understanding of git in general.

Tuesday, March 27, 2012

Groovy little script to bootstrap a chef server

This is a groovy little script I wrote to bootstrap a chef-server using a HPCloud node.


#!/bin/bash
##
# Install everything required to get chef-server up

TARGET_IPADDR="15.185.181.148"

SSH_KEY_FILE="/home/krogebry/.ssh/keys/KSONSoftware.pem"

## Fix that idiotic byobu garbage
ssh -i ${SSH_KEY_FILE} ubuntu@${TARGET_IPADDR} 'byobu-disable'

## Fix the ssh behavior so the box is actually usable
ssh -i ${SSH_KEY_FILE} ubuntu@${TARGET_IPADDR} 'sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/'

## Fix that idiotic byobu garbage ( this time for root )
ssh -i ${SSH_KEY_FILE} root@${TARGET_IPADDR} 'byobu-disable'

## Install some packages
ssh -i ${SSH_KEY_FILE} root@${TARGET_IPADDR} 'apt-get update -y'
ssh -i ${SSH_KEY_FILE} root@${TARGET_IPADDR} 'apt-get install -y libgecode-dev g++ make libyaml-dev libssl-dev'
ssh -i ${SSH_KEY_FILE} root@${TARGET_IPADDR} 'apt-get install -y ruby1.9.1 rubygems1.8'

## Fixing ruby
ssh -i ${SSH_KEY_FILE} root@${TARGET_IPADDR} 'update-alternatives --set ruby /usr/bin/ruby1.9.1'

## Update gems
ssh -i ${SSH_KEY_FILE} root@${TARGET_IPADDR} 'gem update'

## Install chef server
ssh -i ${SSH_KEY_FILE} root@${TARGET_IPADDR} 'gem install chef-server json'

## Configure chef
ssh -i ${SSH_KEY_FILE} root@${TARGET_IPADDR} 'mkdir /etc/chef ; ln -s /var/lib/gems/1.8/ /var/lib/gems/1.9.1 ; mkdir /root/.chef'

## Send up some chef-solo bootstrapping bits
scp -i ${SSH_KEY_FILE} files/server/solo.rb root@${TARGET_IPADDR}:/etc/chef
scp -i ${SSH_KEY_FILE} files/server/chef.json root@${TARGET_IPADDR}:/root/
scp -i ${SSH_KEY_FILE} files/server/chef.init root@${TARGET_IPADDR}:/etc/init.d/chef-server
scp -i ${SSH_KEY_FILE} files/server/chef-expander.init root@${TARGET_IPADDR}:/etc/init.d/chef-expander
scp -i ${SSH_KEY_FILE} files/server/chef-solr.init root@${TARGET_IPADDR}:/etc/init.d/chef-solr
scp -i ${SSH_KEY_FILE} files/server/knife.rb root@${TARGET_IPADDR}:/root/.chef/

## Bootstrap chef-server
ssh -i ${SSH_KEY_FILE} root@${TARGET_IPADDR} 'chef-solo -c /etc/chef/solo.rb -j ~/chef.json -r http://s3.amazonaws.com/chef-solo/bootstrap-latest.tar.gz'

Friday, October 28, 2011

A coworker of mine was asking me one of his favorite interview questions.  It basically goes like this:

"Write me something that will change any file ending in .html to .htm"

Okay, simple enough, I write out a quick bash loop and hand it to him, then he says:

"Okay, now let's say the directory has spaces in the name"

A bash for loop will create an array by splitting on spaces, so something like this would break:

for file in `find ./ -name *.html`
do
  mv $file $newfile
done

If you had a directory named "my directory" you'd have an entry for "my" and an entry for "directory/blah.html" which wouldn't work.

The solution is to do some "while reading this line" bullshit in bash, but my solution was much more elegant, throw away bash and use ruby:

irb(main):001:0> Dir.glob("**/*.html").each do |fileName| system( "mv \"%s\" \"%s\"" % [fileName,fileName.gsub( /\.(html)$/,".htm" )] ) end

This question is designed to see if you can think around complicated scenarios.  However, in the wild I'd never trust bash to do the right thing.

Bash is dumb, ruby is elegant perfection.  I guess I would have failed that interview question. ;)

Tuesday, October 25, 2011

Chef is fun.

I'm currently using chef to manage 91 nodes, and find it to be a fantastic tool. I esspecially like to combine knife commands with shell stuff for something like this:
for node in `knife search node "chef_environment:prod"|grep "Node Name"|awk '{print $3}'`; do         echo -ne "${node}\t" ; knife node show $node -a ec2.instance_type; done |awk '{print $1 "\t" $3}'
Which gives me a list of nodes in production along with their ec2 instance type.  It's handy for generating simple reports, and getting an idea for how may instances of each type we have running in any given environment.

Monday, April 18, 2011

Marriage is tough

Five Finger Death Punch sums up my feelings on the current state of things quite nicely:

"I'd rather hate you for who you are then love someone you're not"

In other words, I'd rather have all the bad then one second of something that you're not.

I love you Kira, and you're worth it. ;)