Nerdblog.pl

Rails Rumble 2014

Wow, it's been such a crazy last few days that I completely forgot to brag on my blog! That's unacceptable!

Me and my buddies from Growth Republic and around have taken part in Rails Rumble 2014! It's a hackathon where you have 48 hours to come up with and develop a web application. The only requirement is that you do not use any assets you have created beforehand (open source libraries do not count as long as either you are not the author or you are but they are not a core part of your project), the app is based on Rails or any other Rack-based stack and your team consists of at most 4 people.

Let me proudly present to you our project, it's called Gilgamesz.

A photo posted by Michał Matyas (@nerdblogpl) on

A photo posted by Michał Matyas (@nerdblogpl) on

Gilgamesz is an application that allows you to create text-based games of the Choose Your Own Adventure variety. Probably some of you remember those neat books that gave you a choice of what to do next by going to a proper page? This is something like this only on-line and a bit better.

Our system is pretty rudimentary (remember we only had 48 hours and a skeleton crew) - you can create your own story, add items and have inventory-based events because of that. No programming required!

I'm not saying our app is perfect tough - the JS library we used for the tree-like graph kinda sucked and we only learned about it halfway through the process and the interface could use a facelift to make it less of a hassle to use. Also, there were some unforeseen complications (one of the developer's girlfriend broke her leg and had to be taken to a hospital) but I like the end product of our struggle.

If you want to help us, you can vote for Gilgamesz.

All you need is a Twitter account, simply visit Rails Rumble website, log-in using the yellow button at the left-top corner of the screen and then click Favourite. Do it if you want to make a group of Rails nerds happy :D

Bash with heredoc

Just a quick one I've learnt today. "Normal" heredoc:

VAR=<<HEREDOC
something something
with ${variable}
HEREDOC

Heredoc with pipe to another command:

cat <<HEREDOC | command
something something
with ${variable}
HEREDOC

Heredoc appended to file:

cat <<HEREDOC >> file
something something 
with ${variable}
HEREDOC

And this is fine too:

cat <<HEREDOC |
something something
with ${variable}
HEREDOC
command

Though I think it's less readable this way.

Nerdblog.pl Podcast

This message is for Polish readers only (mostly to my friends), you will probably not be interested.

Dla wszystkich zainteresowanych, w wolnej chwili razem z pecetem nagraliśmy pierwszy odcinek Nerdblog.pl Podcast. Nie mam pojęcia czy pecet pozostanie w ekipie czy też był tylko gościem, formuła i jakość podcastu też mam nadzieję się poprawią w przyszłości. Prawdopodobnie też będę mówił w przyszłości o rzeczach ciekawszych niż te pierdoły, które poruszaliśmy do tej pory.

Całość jest nagrywana całkowicie niepoważnie, zawiera alkohol i brzydkie wyrazy. Zostaliście ostrzeżeni. Dla ambitnych jest jeszcze odcinek pilotażowy.

Testing your generators with rspec and ammeter

Generators in Rails are awesome and fun and probably one of the reasons Rails became so successful. If you ever wrote one for any reason, you probably know that Rails has Rails::Generators::TestCase class, useful for checking if the script you've written has created all files correctly. But what if you're like us and prefer using rspec rather than Rails'es bundled testing tools?

Read more

Rails Magic #2

Let's assume you have a model with a range type (Rails supports these for PostgreSQL since 4.0).

> foo = Foo.new
> foo.some_range = 1..5
> foo.save!
> foo.some_range
 => 1..5
> foo.reload
> foo.some_range
 => 1...6

Wait.. what? It silently converted inclusive range into exclusive one?

And before somebody says "ooh, but it's the same range anyway, right?", here's the reason I even noticed the problem:

> (1..5).last
 => 5
> (1...6).last
 => 6

WELL, looks like we have a problem. It wouldn't be so bad if there was any sane way of converting exclusive ranges to inclusive ones in Ruby other than (begin..(end-1)).

Still, as @katafrakt_pl noticed:

> (1..5).last(1).first
 => 5
> (1...6).last(1).first
 => 5

...maybe I'll just wrap that in custom class, like Rails people are planning to do.