Glenn Jahnke's blog



Glenn JahnkeGlenn Jahnke
Standup 1/5/2012 - The Death of SOAP
edit Posted by Glenn Jahnke on Thursday January 05, 2012 at 09:17AM

Helps

Soap4R and Ruby 1.9.2

"Soap4R and Ruby 1.9.2 don't work, what's the best alternative?"

Several people recommended the Savon gem. It was strongly suggested to not try and replicate any of the Soap protocol because it is pretty painful to implement.

Interestings

Constants versus Immutable Objects

Someone apparently had confusion around what it means to be constant in Ruby, and what it means to be immutable.

A constant prevents modifications to references to variables.

SOME_CONST = 3
SOME_CONST = 4
warning: already initialized constant SOME_CONST

Immutability means that the variables themselves cannot be modified.

an_array = [1,2,3]
an_array.freeze
an_array[3] = 4
RuntimeError: can't modify frozen array

You should note, though, that freezing an object only makes the variables that object contains immutable. For instance,

an_array = [1,2,3,{}]
an_array.freeze
an_array[3]["foo"] = "bar"

will not throw any errors or warnings.

Glenn JahnkeGlenn Jahnke
Standup 11/17/2011 - Cloudy Cloud
edit Posted by Glenn Jahnke on Thursday November 17, 2011 at 09:37AM

Interestings

Travis CI: Javascript Testing in the Cloud

Jasmine gem test suites are now being run on Travis CI which is an open, distributed build system for the open source community.

Check out Travis CI.

Fix Git Author

As Pivots move to different machines frequently when we pair switch, its often a problem that we forget to switch the author when we commit to Git. Here's how you can fix the author of a commit (before you've pushed to remote).

  1. change your git author
  2. git commit --amend --reset-author -C HEAD

This changes the author of commit to whomever is configured in the git config, and uses the same message you previously used (the -C HEAD part).

TDDium Cloud Test Runner

TDDium is an easy-to-use, secure, hosted testing environment that takes the tedium out of building high quality Ruby web applications using Test Driven Development and Continuous Integration.

Glenn JahnkeGlenn Jahnke
Polyglot Factorial
edit Posted by Glenn Jahnke on Tuesday November 15, 2011 at 09:35PM

Someone on Hacker News mentioned the number of orderings of a deck of cards. I took up the challenge in some of my favorite and not so favorite languages, I'll let you guess :).

Ruby

ruby-1.9.2-p180> (1..52).inject{|a,b|a*b} => 80658175170943878571660636856403766975289505440883277824000000000000

Scala

scala> BigInt(1).to(BigInt(52)).toList.foldLeft(BigInt(1))((a,b) => a*b) res23: scala.math.BigInt => 80658175170943878571660636856403766975289505440883277824000000000000

Haskell

Prelude> foldl1 (\x -> \y -> x*y) [1..52] 80658175170943878571660636856403766975289505440883277824000000000000

CoffeeScript

coffee> [1..52].reduce (a,b) -> a*b

8.065817517094388e+67

Java

Non-existent REPL> import java.math.*; public class Factorial { public static void main(String[] args) { BigInteger result = BigInteger.ONE; BigInteger fiftyTwo = new BigInteger("52"); for(BigInteger i = BigInteger.ONE; i.compareTo(fiftyTwo) <= 0; i = i.add(BigInteger.ONE)) { result = result.multiply(i); } System.out.println(result); } }

$ java Factorial 80658175170943878571660636856403766975289505440883277824000000000000

** I could have used the product function in most of those examples, but I wanted to play with foldL ;)

Glenn JahnkeGlenn Jahnke
Is your XML foo savvy?
edit Posted by Glenn Jahnke on Tuesday November 15, 2011 at 09:25AM

Helps

  • "How do you change the address and port that Solr is running on?"

Somewhere in the server.xml file was suggested, however that didn't seem to work. The workaround was using IP Tables.

Interestings

  • as_json (with options) seems to always be called with an explicit nil argument from to_json under Rails 3. Some people just use as_json explicitly, or pass an explicit empty hash as the arg to get around this oddity.

  • Jenkins now supports Ruby plugins.

  • Support Movember! Pivotal has raised quite a bit of money and you can too.

Glenn JahnkeGlenn Jahnke
Is your XML foo savvy?
edit Posted by Glenn Jahnke on Tuesday November 15, 2011 at 09:25AM

Helps

  • "How do you change the address and port that Solr is running on?"

Somewhere in the server.xml file was suggested, however that didn't seem to work. The workaround was using IP Tables.

Interestings

  • as_json (with options) seems to always be called with an explicit nil argument from to_json under Rails 3. Some people just use as_json explicitly, or pass an explicit empty hash as the arg to get around this oddity.

  • Jenkins now supports Ruby plugins.

  • Support Movember! Pivotal has raised quite a bit of money and you can too.

Glenn JahnkeGlenn Jahnke
Standup 2011.04.12: Tweeting Standup and RSpec
edit Posted by Glenn Jahnke on Tuesday April 12, 2011 at 09:28AM

Interestings

It was suggested that we should Tweet our standups as well as post them to our blog.

Helps

What is the overhead of an RSpec "it" block?

People seem to think the overhead is really negligible compared to Rails load time or making any DB calls whatsoever. People have seen whole codebases moved from TestUnit to RSpec with no notable speed slow-down.

Glenn JahnkeGlenn Jahnke
Standup 9/3/2010
edit Posted by Glenn Jahnke on Friday September 03, 2010 at 09:21AM

Help

Server-Side Image Editing

"What's the latest and greatest server-side image processing library people are using?"

Most people quickly agreed that ImageMagick was the way to go.

Data Analysis

"Are there good libraries for data analysis similar to NumPy in Python but for Ruby?"

While there may not be many Ruby libraries that directly comparable to NumPy, there are a fair number of packages to do related work. For instance, you can utilize RSRuby which is a bridge between the R statistical language and Ruby. GnuPlot is another Ruby library that allows both data processing and plotting of graph data.

RSRuby - R / Ruby binding

GnuPlot - Data processing and Plotting

Glenn JahnkeGlenn Jahnke
Standup 9/1/2010 - Rspec2 + RubyMine and Testing for Class methods
edit Posted by Glenn Jahnke on Wednesday September 01, 2010 at 09:24AM

Help

Testing for class methods in Ruby

How do you test for the existence of a class method? Test it using #respond_to?

class Foo
    def self.bar 
        puts "Hello, World!"
    end
end

Foo.respond_to?(:bar)
 => true

And to make sure we are really just talking about class methods and not instance methods:

foo = Foo.new

foo.respond_to?(:bar)
 => false

Interesting

RubyMine and Rspec2 Bug Fixed!

We use the latest and greatest RubyMine version available at Pivotal, but sometimes technology choices such as Rails 3 and Rspec 2 are still ahead of it. The formatter that analyzes test output breaks on Rspec 2's output before any tests run. The bug is further discussed http://youtrack.jetbrains.net/issue/RUBY-6485. Luckily this bug will be fixed in the next EAP release.

Excuting .rvmrc commands and cruisecontrol

We've had a difficult time getting .rvmrc files to work with cruisecontrol.rb builds. Specifically, ccrb seems to launch the rake task in the project working directory. This means that the .rvmrc file is ignored. A workaround is to have your CI script directly use RVM or to add "cd .. && cd work" before your project cruise script or rake task.