Verbose Logging

software development with some really amazing hair

T + S G I F R

Articles tagged with "ruby"

Custom Scout Plugins For Lonely Sysadmins

· Posted in Software
When you run servers, there are certain things you need to know. When you're the only one running the servers, there are a few more things you need to know. One is the loneliest number Since I'm basically the only person running the servers keeping Yardstick Measure alive, I need to know as much as I can about them. More than that, I need to know things you might not really care about if you have a team of dedicated people managing the servers. …

NewRelic with Rails 2.3.x and Sinatra Metal Controllers

· Posted in Software
Our application at Yardstick is Rails 2.3.x, and we use some Sinatra based metal controllers. We also use NewRelic to monitor things. Get Low Something got updated somewhere, maybe the NewRelic gem, maybe something else. Our Apdex hit 0.3 or something stupid and stayed there. After a long debugging period going back and forth with the NewRelic folks, we figured it out. Problem, meet Solution The way a metal controller in Rails 2.3 works is that …

Ruby Batteries Included

· Posted in Programming
At the beginning of April 2013, MWRC ensued in Salt Lake City, Utah. I rolled the dice and submitted a talk, not thinking that they'd pick it. Announcements started rolling out on the twitter, and boom, there it was. Speaking at MWRC 2013: @darkhelmetlive on "Ruby Batteries Included". mtnwestrubyconf.org/2013/ruby-sess…— MtnWest RubyConf (@mwrc) January 24, 2013 Well, the conference came and went, and I had a great time. Lots of great speakers, …

How Do I RDoc? Documenting Ruby

· Posted in Programming
Yesterday I did a talk at Mountain West Ruby Conf 2013 all about the Ruby Standard Library. The basic premise is you should be looking to the standard library first, before running to RubyGems.org and GitHub for new code. If all you need is a hammer, you don't need to buy the hardware store. Where are the docs? The problem is that sometimes, the standard library doesn't have the documentation you might want. Maybe it's not that great of an examp…

Make Your Own Celluloid

· Posted in Programming
Oh look, a post on ruby concurrency. LOLZ THREADS. Anyway, let's get past the lolz about ruby and threads and just run this on JRuby okay? Celluloid Celluloid is a ruby library to make concurrency easy. It gives you a nice object oriented interface to the concurrent patterns it provides. We're going to look at two specific interfaces: Actors and Futures. Before we begin, let me say I love Celluloid. I'm just doing this to see how much basic func…

Basecamp Next Todo Migrator

· Posted in Programming
I had this conversation on Twitter yesterday. That's fine. 37Signals is known for saying no to things in the interest of a better product. A migrator for BCX isn't exactly something that would add enough value to the product to warrant spending their time on it. It's cool. Don't worry, I got this I built one. It only took a couple hours to throw together and clean up. It's super basic, but it did the job for me. It handles todolists with their t…

RubyConf Mission Complete

· Posted in Editorial
RubyConf 2012 is at an end, and what a time it was. This was my first conference, and it was all thanks to my employer Yardstick. If it wasn’t for them, I probably wouldn’t have been able to come, learn so much, and meet so many great people. My mission was to thank as many people as possible, in person. Open source is somewhat of a thankless job. Lots of people using your code or what have you, and never receiving thanks for it. While I didn’t …

rc Files and You: Automating Your Project

· Posted in Programming
I gave a lightning talk at RubyConf 2012 in Denver. Man was I nervous. Apparently I did an okay job though, and I'd like to thank all the people who were and took time out of their day to listen to me. Thanks! If you want to view the original talk, the video is here. Scroll to 10:15 to find me, but I recommend watching them all. A few people had more questions (I talked really fast since it was a lightning talk after all) and this was originally…

My RubyConf Mission: Thank All The People!

· Posted in Editorial
Are you excited for RubyConf? I am! It’s my first time, and it’s made possible by my awesome employer, Yardstick. Thanks Yardstick! I’m excited for the talks, though there are some time slots where it’s going to be tough to pick which talk to go to! Luckily, Confreaks records everything so I can always watch it later! Thanks Confreaks! See the pattern? Two paragraphs, two thank yous. But I want more. I want to thank you I want to meet you at Rub…

Private Rubygems on Heroku

· Posted in Programming
Maybe Heroku changed something, or maybe it's the new Cedar stack, but using private gems from Github is pretty easy. It apparently didn't work before. The important part is in your ~/.ssh/config Host heroku.com ForwardAgent yes After that it's no big deal. Just use an ssh URL to Github (or wherever, the Github part doesn't really matter) in your Gemfile and off you go! source :rubygems ruby '1.9.3' gem 'sinatra', :git => 'git@github.com:darkhel…

Proc, Block, and Two Smoking Lambdas

· Posted in Programming
Ruby 1.9 has 4 different ways to deal with closures. Cue music Proc Procs are the weird ones of the bunch. Technically, all of these things I'm going to describe are Procs. By that I mean, if you check the class, it's a Proc. A Proc is made by using Proc.new and passing a block, Proc.new { |x| x }, or by using the proc keyword, proc { |x| x }. A return from inside exits completely out of the method enclosing the Proc. A Proc doesn't care about t…

Rubygems Beyond The Thunderdome

· Posted in Editorial
Stop me if you’ve heard this one before. You get into some new tech over the weekend. With enough excitement to kill a horse, you whip up a ruby gem and put it on Github. You get a few hits, some people using it over the next little while. A few bugs get reported, and you fix them. A few features get requested, and you implement them. A few pull requests get submitted too, and you merge them. You’re using it yourself, so you’re finding your own …

Worst URL Shortener Ever

· Posted in Programming
I was bored last night, so I hacked this up. My original thought was since riak has an HTTP interface, I could just proxy GET requests to it when a short URL was used, but either I was doing it wrong or you can't set the Location header when you POST documents. Oh well. Anyway, this uses riak just to store the URL, and the riak key as the short URL key. There is no error checking, UI, or anything fancy. It's pretty much the simplest thing that c…

Simple Ruby Pipes

· Posted in Programming
Here's something I cooked up this evening. Nothing too epic, but it's a neat illustration of metaprogramming with ruby. Ruby allows you to reopen classes and add methods to them. You can also make a Module and include that in a class to add methods. I've added four methods to the Symbol class and overridden one method in the Array class (using alias to keep the old method around since super doesn't quite work). Now we can pipe arrays like bash u…

Easy Sinatra Metal For Rails 3.x

· Posted in Programming
I was doing some optimizing the other day on a Rails 2.3.x application with a metal controller. I didn't feel like writing a straight rack application, so I used sinatra. A pretty good explanation of how this works can be seen in Adam Wiggins' slides: Rails Metal, Rack, and Sinatra from Adam Wiggins In Rails 3, they still have metal controllers, in that the ActionController::Metal class is essentially a really thin controller, and you can use it…

Productivity ∩ Learning = ∅

· Posted in Editorial
Do you have a TODO list Sure you do. I bet you have all sorts of cool projects on it, like a better todo list application, a web spider for some RSS feeds, a search engine experimentation, a git backend built on riak, and a slew of other ideas you haven't got around to. I bet you also have some new programming languages you want to learn. Maybe expand your scripting language knowledge with some Python, break into functional programming with Cloj…

Import Delicious To Google Bookmarks

· Posted in Software
You may have heard, but Delicious is getting the boot. I left Delicious long ago, because it never did anything for me. Yeah I could bookmark things, share them, whatever. I never went back to the bookmarks though. I wanted my bookmarks to work seamlessly with how I used the web. That means, it had to work with Google. Back in the day I used Google Bookmarks back when I was evaluating bookmarking apps in 2008 (when I settled on Delicious) and it…

Deploying Your Ruby App With Mongrel2

· Posted in Software
If you're in the ruby world, and specifically the web side of the ruby world (Rails, Sinatra, etc), you should probably know who Zed Shaw is. I mean, he only wrote mongrel, which you're probably using as your application server. Well, he's been hard at work on Mongrel2, and it's a big change from the original mongrel. Mongrel2 isn't a ruby web server. It's (and I'm going to borrow straight from the site): Mongrel2 is an application, language, an…

Rails Rumble Immediate Post Mortem

· Posted in Programming
It's 10 minutes past 6 on Sunday evening, and we just wrapped up our Rails Rumble 2010 project. Check it out at http://gemrage.com/. Check out our team here too. This. Shit. Was. Real. We had a rough start with lack of internet for 3 hours, had a few depressing times thinking we'd never finish, but we rocked our socks off with Windows and Internet Explorer, MacBooks, Twitter and Campfire, and produced a pretty cool application. Please go check o…

Most Dangerous Programming Errors, 10-6

· Posted in Programming
It's been a while, but we're continuing the Top 25 Most Dangerous Software Errors with numbers 10-6. 10. Missing Encryption of Sensitive Data Have you ever signed up for some website or service, only to receive an email 30 seconds later WITH YOUR PASSWORD IN IT! Doesn't it just fucking kill you? Have you ever used a 'Forgot your password' page only to be blindly given your password? Fantastic. I highly doubt they are doing any encryption with yo…

rack-gist - THE GISTS ARE NOW DIAMONDS!

· Posted in Software
Hello developers, how are you? Fantastic. Does your code look like mine? No. Could it load like mine? Yes. Should you use rack-gist to load your gists? I don’t know… Do you like not blocking your users while you page loads another Javascript file? Do you want code that looks like it could write your app for you in the dream computer it built for you with its own DWORDS? Of course you do. Recursive Hasselhoff! Into the best gisting of your life. …

sinatra-bundles 0.3.0 Is Out

· Posted in Software
Version 0.3.0 of sinatra-bundles is out and powering the blog for a week or so. It's cold out there, so bundle up: % gem install sinatra-bundles require 'sinatra/bundles' Version 0.3.0 has a new feature and a slight API change. Custom path prefixes Yeah, I know, not everybody is as awesome as I am with their stylesheets and javascript files in the stylesheets and javascripts directories, but now you can control where they live on the disk. docun…

Most Dangerous Programming Errors, 15-11

· Posted in Programming
It's been a while, but I've been busy pwning n00bs at Modern Warfare 2 and Bad Company 2, and buying a car, so life has been pretty busy as of late. Have no fear though! I continue the look at the Top 25 Most Dangerous Programming Errors with numbers 15 to 11. 15. Improper Check for Unusual or Exceptional Conditions When you ASSUME things, you make an ASS out of U and ME. This is all about assumptions. You assume something will work, you assume …

Find Queries Missing Indexes In Your Rails Application

· Posted in Programming
Rails developers aren't exactly known for getting their indexes right (or even at all) on their databases. Granted, databases are a tough subject, and some people and companies make their living dealing with only databases, and some only with one database (like MySQL or Oracle). If you're coming to web development with no formal background in databases, and it's all new to you, then it's totally understandable to maybe forget about indexes initi…

Most Dangerous Programming Errors, 25-21

· Posted in Programming
The Common Weakness Enumeration posted their Top 25 Most Dangerous Programming Errors last month. Most everything in the list is completely avoidable, but most new programmers, and especially those without real world experience (as opposed to trivial classroom projects), fall victim to at least some of them. A lot of them bit me in university and I still get nipped by some of them today. Proper education is the first step, and the CWE have done …

Getting Rid Of Transactions For The Poor Man

· Posted in Programming
A quick post for today. Want to get rid of transactions from ActiveRecord for something? Here's a cheap way to do it. It only works for MySQL obviously, but you can roll your own if you are on postgres. I'll make it a bit less crappy and make it a gem or something.

sinatra-bundles 0.2.0 Is Out

· Posted in Software
I pushed up a new version of sinatra-bundles and it's running smoothly on my blog here, so I best tell you about it. First, get your bundle on: % gem install sinatra-bundles require 'sinatra/bundles' Version 0.2.0 has a couple fun things. The sinatra dependency is bumped up to 1.0, since it's out (yay!), it's more awesome, and I'm not quite sure if the bug that prevented me from using earlier sinatra was fixed or not in the 0.9.6 release. etag s…

sinatra-bundles Plays Nice With Eval

· Posted in Programming
I recently added a Javascript file to my bundle with sinatra-bundles that uses Javascript's eval functionality. The call to eval executed code that referenced a method parameter. sinatra-bundles compresses Javascript files, and as part of that, shrinks variable names. Normally this isn't a problem, but in this case of eval, it became a problem, since it was trying to reference a local variable that no longer existed (because it got shrunk to som…

My Watch List, Into 2010

· Posted in Software
Lots of interesting things are afoot, and I try to keep track of them. Here's what I'm watching. Rails 3 Lots of new changes are coming with Rails 3, and it's pretty exciting. I wrote about some of the cool ones here. Rails is shaping up to be faster, more modular, and generally better and easier to work with. With all the smart people working on it, you don't have to look very hard to realize this is going to be a big release, and is only going…

Rails 3 Release Notes: What Does It Mean To You?

· Posted in Software
The Rails 3 Beta got dropped a few days ago, and the release notes for Rails were put out a bit before that. The list of changes is long; this is a big release. There's a lot to sift through, a lot to change to upgrade your existing application, and a lot to learn whether you are upgrading or starting a new app. The big question is: WTF does all this mean to me? Don't worry, I'm going to tell you. If you want to read the full release notes, go f…

Proper Rack Middleware Ordering

· Posted in Programming
It occurred to me the other day, that I should take a look at the middleware I use on this blog. I don't know what it was. My spidey senses just tingled. Boy was I right. I totally had it backwards. Rack middleware is a fantastic thing. It's like a little encapsulated rack application that you can use to filter, process, or otherwise mess with responses. There is middleware to add etags, configure caching, catch and log exceptions, deal with coo…

sinatra-bundles: Easy Asset Bundling For Sinatra

· Posted in Programming
sinatra-bundles is an easy way to bundle CSS and Javascript assets in your sinatra application. Yes! It has tests! They are on runcoderun Usage sinatra-bundles combines Javascript and CSS into one file. Meaning, you can bundle 2 or more Javascript files into one, similar with CSS stylesheets. Any bundled files are expected to be in the public directory, under 'javascripts' and 'stylesheets' Assuming you have the following files in public: ./styl…

Using Date Objects With Ruby Ranges

· Posted in Programming
I used to have some really ugly code to generate the archive links you see on the right column of this blog. It was terrible. Granted it was some of the first code I wrote on this blog, and I was cruising through it because I just wanted to get it done and working, but still, it's not really a valid excuse. It can be seen here. I had a thought the other day that it would be much better handled by the Range class, and boy was I right, although it…

My Ruby Style

· Posted in Programming
The folks at Thoughtbot have a Ruby community survey online, and you should all go take it. Well, as long as you are a ruby developer. Otherwise it doesn't really matter. Anyway, I wanted to throw out what I do for ruby style (and general programming style in some cases). I hate the 80 character limit. Get a real monitor would you please? I don't align assignment operators. I don't indent private/protected keywords. I keep the code after private…

Heroku Backup With Single Bundle

· Posted in Software
In case you missed it, the Coding Horror, Stack Overflow and Haacked blogs died in almost a literal fire. Well I don't think there was an actual fire, but basically they all hosted their blogs in virtual machines on the same physical server, and the backup process never backed up the virtual machine files since they were always in use. The backup process was managed by the hosting company and silently failed on these files. Oops. While I'm fairl…

Debugging Ruby By Aman Gupta

· Posted in Software
I wish I could see this guy speak. I learn so much just reading his slides and other writings, I can't even imagine what I'd learn if I was actually there. Debugging Ruby from Aman Gupta

Screen Scraping With Ruby

· Posted in Software
Scripting languages are the bomb. I pretty much live in them right now. Ruby is my current (and probably will be for a long time) favourite scripting language, and it has a library for everything. Even if there isn't a library for what you want, it's super easy to write your own. I ran into a problem a while back that ruby solved nicely for me. I was downloading wallpapers from a website, but it was getting annoying. Really, I just wanted to gra…

Get Your Wordpress Out Of My Blogging Software

· Posted in Programming
Hopefully you didn't notice much, except the speed increase, but my blog is no longer on the behemoth that is Wordpress. While Wordpress served me well for quite some time on my other blog it always kind of bugged me. Well no more! I took a couple days (basically 2 full days and 2 evenings) and wrote my own little blogging engine from scratch. You can find it on github and get forking if you so choose. What I used: ruby and sinatra They are pret…

Threaded Awesome

· Posted in Programming
tmm1 and joedamato put up a good slide show on slideshare about ruby threading issues, and their fixes. These things have been around for a while, but now they are here in slideshow form. Definitely check them out, even if you don't program ruby, as there are some interesting profiling/debugging shenanigans shown, among other things. Threaded Awesome from Aman Gupta

respond_to With respond_glue: Override respond_to

· Posted in Programming
So check this: you have a nice little Rails app. You have some stuff for a JSON API type system. You've got an STI setup with the Widget model class and the more concrete FancyWidget and WeirdWidget classes. You've got a WidgetsController, and the corresponding FancyWidgetsController and WeirdWidgetsController Yay. It works. You can deal with both types of Widgets using JSON. Now you need an HTML interface to it. Fine, you can just throw in a fo…

role_on: Really Simple Roles (For Rails)

· Posted in Programming
I looked at a few role systems for Rails, but never found what I wanted. They were all object based systems, never just "allow a user with this role to do this action". Either that or I never found the systems that did that, or totally missed the docs on how to configure those systems to do what I wanted. Well, actually acl9 seemed to do that, but whatever. So I made role_on The instructions are on Github, so I won't repeat them here, but it's p…

Useful Links Of The Evening

· Posted in Links
Ruby on Rails content_for Project: Builder RSS pauldix-feedzirra Basic Rails association cardinality Nested Object Form with has_one Relation

Use Net::SSH With Amazon EC2

· Posted in Programming
I'm writing up some scripts to automate some EC2 setup, and SSH is required. All the examples for Net::SSH show using just a username and password, which is all good, but the Amazon stuff requires a key file. Here's how to do it: Net::SSH.start('my.amazon.hostname.amazonaws.com', 'user', :keys => '/path/to/keypair.pem') { |ssh| … } According to the docs, the :keys named param takes an array of file names of private keys to use for publickey and …

Debugging Cucumber On Rails

· Posted in Programming
I like frameworks, but sometimes debugging them is more entertaining. I don't know why I didn't think of this method before, but mischa on github has a great little repo showing how you can do it. The README Usage: Add: require 'ruby-debug' require 'cucumber_rails_debug/steps' To features/support/env.rb Then use: Then debug # opens the debugger or Then what # prints out params, url and html Check it out here

Riding Rails With Selenium

· Posted in Programming
Selenium is a suite of tools to automate web app testing across many platforms. Cucumber is a BDD framework that allows you to write things in English (or whatever language you want, really), and have that execute as code. Put those together with webrat and rspec and you have a pretty mean stack to test your ruby on rails web application with. Sort of. I've been having some problems with it, getting it set up, but it's coming along. This isn't a…

Ruby Regex For Fun And Profit

· Posted in Programming
Regex are always fun, and since regex expressions are first class citizens in ruby, it makes it so much easier. I found this Code Golf question on Stackoverflow and threw together a quick method to do it. I can't take all the credit, since I needed to search a bit to figure out if I could do matching parenthesis in ruby, and found that I could, but only in ruby 1.9, which ruby forum topic showed me. Then a commenter on SO pointed out another opt…

Gtk And Ruby Threading Issues

· Posted in Programming
In one of my classes, we used Ruby and Gtk, but some issues popped up. The most obvious is using a block to do GUI update stuff and the like, from another thread. Things die. Puppies are killed. I found this post on Ruby Forum which fixed the problem. Relevant code. Basically, you call the Gtk.init_thread_protect method first when you start things up, then, whenever you need to do GUI update stuff, just wrap it in a Gtk.thread_protect {} block. …

Using Ruby's Eval To Make Cucumber Bigger And Greener

· Posted in Programming
In case you just crawled out from under your rock just to read my blog, and haven't the foggiest, cucumber is a ruby acceptance testing framework, and works great with rails. I was writing features for admin users in this application, and needed a step like this: Then I should be editing "test@example.com" Where the quoted email is the login. Later on (in fact right after…I was testing edit functionality, and after safe you end up on the view us…

ruby-openid IOError With Passenger

· Posted in Programming
The ruby-openid gem was giving me problems with Passenger, causing IOError problems. I found the fix here The gist of it? Add OpenID::Util.logger = RAILS_DEFAULT_LOGGER to environment.rb, and you're good!

RSS Fun With feedzirra

· Posted in Programming
Sometimes, checking RSS feeds is boring. Sometimes you just want to grab a picture or whatever from each item. For that, there's ruby. Oh and feedzirra. There is an RSS feed I read, except it's more of a picture feed and I just want to grab the pictures from it, and doing this through Google Reader is no fun. That's where ruby and feedzirra come in. feedzirra is a ruby gem for dealing with RSS feeds. It's got a great interface and just works. So…

Compiling Ruby 1.9.1 Alongside Ruby 1.8.7

· Posted in Programming
I almost threw my laptop out the window figuring this out, but if you want to install ruby 1.9.1 alongside ruby 1.8.7 (whether the prefix is the same or not), you have to give ruby 1.9 a program suffix, but also a baseruby. So you need something like this: ./configure --prefix=$HOME/local --program-suffix=1.9 --with-baseruby=ruby --enable-pthread

Rake Tutorial

· Posted in Programming
Oh me, oh my. When I first posted about this, in June of 2007, my original post started with Ruby is sweet. I should use it more often. And now, on Monday, I get to start my new job playing with Rails all day long. Funny how things change. Regardless, the quality of this tutorial hasn't changed, so here it is again. Rails Envy: Ruby on Rails Rake Tutorial