{ Josh Rendek }

<3 Go & Kubernetes · honeypots · homelab · leadership

Aug 19, 2012 · 1 min

Fixing Psych::SyntaxError when using Jekyll

I was working on my blog and moving some posts around when I kept getting a Psych::SyntaxError when generating it with Jekyll and ruby 1.9.x. Unfortunately the default stack trace doesn’t provide much information on what file was causing the issue, so a quick way to find out is opening up irb:

{% codeblock Example to run in irb - sample.rb lang:ruby %} require ‘yaml’ Dir.foreach(“source/_posts”).each {|f| YAML.load_file(“source/_posts/” + f) unless f == “.” || f == “..” } {% endcodeblock %}

read more

Aug 19, 2012 · 1 min

Moved domains to my name

Moved everything over to my other domain, joshrendek.com incase you’re wondering why you got redirected.

read more

Aug 16, 2012 · 1 min

Never Set Instance Variables Again

Tired of doing this on every method in ruby? {% codeblock lang:ruby %} class Person def initialize(name) @name = name end end {% endcodeblock %}

Use the awesome power of ruby and metaprogramming to auto set method paramters to instance variables:

{% codeblock lang:ruby %} class Person def initialize(name) method(method).parameters.collect {|x| instance_variable_set("@#{x[1]}", eval(x[1].to_s)) } end end {% endcodeblock %}

Now you can access your parameters being passed in as instance variables for an object. You can extract this out into a method to apply to all objects or just make a simple extension to include it in files that you wanted to use it in. While this is a trivial example, for methods with longer signatures this becomes a more appealing approach. I’ll probably extract this out into a gem and post it here later.

read more

Jul 26, 2012 · 7 min

Deploying Rails with RVM in a production environment

Let’s start out by logging into our machine and installing some pre-requistes (these can also be found by running rvm requirements as well):

1sudo apt-get -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion git-core mysql-client libmysqlclient-dev libsasl2-dev libsasl2-dev mysql-server

Lets also install nodejs:

1curl -O http://nodejs.org/dist/v0.8.4/node-v0.8.4.tar.gz
2tar xzvf node-v0.8.4.tar.gz
3cd node-v0.8.4.tar.gz
4./configure && make && sudo make install

read more

Jul 22, 2012 · 3 min

The problem with Pingdom

{% codeblock Time to be Awesome - awesome.rb %} puts “Awesome!” unless lame {% endcodeblock %}

[The problem with pingdom.](http://www.pingdom.com Pingdom)

My money’s in that office, right? If she start giving me some bullshit about it ain’t there, and we got to go someplace else and get it, I’m gonna shoot you in the head then and there. Then I’m gonna shoot that bitch in the kneecaps, find out where my goddamn money is. She gonna tell me too. Hey, look at me when I’m talking to you, motherfucker. You listen: we go in there, and that nigga Winston or anybody else is in there, you the first motherfucker to get shot. You understand?

read more

Apr 4, 2012 · 2 min

MySQL Performance tuning constant references vs index merges and intersects

I had a query that, after adding indexes, was taking anywhere from 1.5 to 5ms to return on my local machine. In production and staging environments it was taking 500+ms to return.

The query was producing different optimizer paths:

The good optimizer:

 1*************************** 2. row ***************************
 2           id: 1
 3  select_type: SIMPLE
 4        table: activities
 5         type: ref
 6possible_keys: index_activities_on_is_archived,index_activities_on_equipment_id,index_activities_on_date_completed,index_activities_on_shop_id
 7          key: index_activities_on_shop_id
 8      key_len: 5
 9          ref: const
10         rows: 1127
11     filtered: 100.00
12        Extra: Using where

The bad optimizer:

 1*************************** 2. row ***************************
 2           id: 1
 3  select_type: SIMPLE
 4        table: activities
 5         type: index_merge
 6possible_keys: index_activities_on_is_archived,index_activities_on_equipment_id,index_activities_on_date_completed,index_activities_on_shop_id
 7          key: index_activities_on_shop_id,index_activities_on_is_archived
 8      key_len: 5,2
 9          ref: NULL
10         rows: 1060
11        Extra: Using intersect(index_activities_on_shop_id,index_activities_on_is_archived); Using where

My first thought was it might have been the MySQL versions since I was running 5.5 locally and 5.0 in production, but that turned out not to be the case.

read more

Feb 28, 2012 · 6 min

Why the Cloud isn't for your Startup

The Lure

You’re a new startup, you’re tight on funds and don’t have the server knowledge to run your own servers, but you plan on growing exponentially very quickly. You have three choices:

  • Suck it up and learn some sysadmin skills (or hire one)
  • Use a PaaS provider (such as EngineYard, Heroku, or EC2)
  • Use a mix of both

But how do you know which path to take?

I’ll be using my experience running Servly for most of this article. I’ve been using dedicated servers and virtual machines and the cloud for over 6 years with Servly and other business ventures.

read more

Feb 27, 2012 · 2 min

Using RSpec to test C code

I was working on a C assignment for school and wanted an easy way to test the output of a program running against multiple test cases.

Using RSpec I came up with the following spec:

 1describe "Calculator "do
 2    before(:all) do
 3        `make clean; make;`
 4    end
 5    it "should accept p1" do
 6        `./calc < testing/p1.cal`.should include "accept"
 7    end
 8
 9    it "should reject p2" do
10        `./calc < testing/p2_err.cal`.should include "reject"
11    end
12
13    it "should reject p3" do
14        `./calc < testing/p3_err.cal`.should include "Variable a duplicate declaration"
15    end
16
17    it "should reject p4" do
18        `./calc < testing/p4_err.cal`.should include "Variable b uninitiated at line 5"
19    end
20
21    it "should accept p5" do
22        `./calc < testing/p5.cal`.should include "accept"
23    end
24
25    it "should accept p6" do
26        `./calc < testing/p6.cal`.should include "accept"
27    end
28
29    it "should reject p7" do
30        `./calc < testing/p7_err.cal`.should include "syntax error at line 9"
31    end
32
33    it "should reject p8" do
34        `./calc < testing/p8_err.cal`.should include "Variable d undeclared"
35    end
36
37    it "should reject p9" do
38        `./calc < testing/p9_err.cal`.should include "divide by zero at line 7"
39    end
40
41end

I was then able to run all my tests with a single command and get informative output.

read more

Nov 30, 2011 · 1 min

OSX + Vim + CTags (Exuberant) for fast context switching in large projects

Installing CTags (Exuberant)

Lets first install ctags-exuberant using Homebrew

1brew install ctags-exuberant

Remember the path that ctags got installed to, with version 5.8 on my machine it was in:

1/usr/local/Cellar/ctags/5.8/bin/ctags

Setting up Vim/MacVim

Download the TagList plugin from VimOnline .

In your .vimrc file add the following:

1let Tlist_Ctags_Cmd='/usr/local/Cellar/ctags/5.8/bin/ctags'
2
3let g:Tlist_Ctags_Cmd='/usr/local/Cellar/ctags/5.8/bin/ctags'
4
5fu! CTagGen()
6    :execute "!" . g:Tlist_Ctags_Cmd .  " -R ."
7endfunction
8
9nmap <silent> :ctg :call CTagGen()

Open up vim/MacVim, and type

1:ctg

read more