On 21st of July, I took a part in the lightning.io conference, which took place in PoznaĆ, Poland. The conference itself was quite unusual, because - as its name may suggest - it consisted of lightning talks only. What's more, each and every attendee was also a speaker.
My presentation was entitled "Application Architecture", and it was actually concentrated on the things its name says. It was all based on a presentation done by Uncle Bob.
Having just one terminal window is usually not enough. Even though having many windows (represented by tabs in Linux terminal-handling tools or by many Putty instances) can solve this problem, it is often desired to keep things in sight at the same time. For example, we may want to execute some code or tests and at the same time watch over log files by using tail.
tmux is (among screen and Terminator) one of the best tools for splitting terminal window. In this tutorial I'll show you how to begin work with tmux and how to adjust it to meet your requirements.
Two weeks ago I posted a short information concerning picking a topic for my Ruby-related e-book. I also included a link to a short, one-question survey and promised (in one of the comments) to post the results. So here they are!
For some time, I've been wondering whether writing a Ruby-related e-book would be a good idea. I missed writing, and in particular I wanted to work on something more challenging than just a blog post. It didn't take too long for me to make the decision whether I should write at all, but then another problem appeared: what topic should I choose?
First, I chose the topic I considered to be the most interesting, but then I changed my mind. And then again. And again.
Finally, I thought that the most interesting topic should be interesting not only for me as an author, but also for my potential readers. And this is what I need you help with. Please open the Google form I've created and answer one simple question: what Ruby-related e-book would you like to read?
Thanks in advance for your answers.
Text algorithms offer different ways of efficient text representation, processing and lookup. Ternary search tree is one of the most interesting data structures in its field of knowledge, as it combines storage efficiency with fast lookups and ability to perform a prefix search. I'll show you how this type of tree works and propose an example Ruby implementation, covered with specs.
How to check if given value is nil in Ruby? I'll show you not only how to do it, but also how it works in details. To be honest, explanation may seem a little bit confusing, especially for programmers having experience in other languages such as Java or C.
Curious readers may also read about an interesting feature of the Ruby interpreter, nil, true and false objects and their initialization.
Among filesystem and local memory, memcached is one of the most widely-used storage systems being adapted to cache data in web applications. I'll try to show different ways of integrating memcached with web applications in order to gain performance boost. Described techniques can be applied regardles of the framework (Ruby on Rails / Merb / Sinatra) and model layer library (ActiveRecord / DataMapper / Sequel) being used. I assume that reader has at least a basic understanding of what memcached is and how it can be used to store and retrieve data.
A careful consideration given to unit tests in a form of discussion between spokesmen of three attitudes: "Love", "Ignorance" and "Getting Real".
Which side are you on?
If you're tempted to create your own simple language in order to solve some specialized problem, then the Interpreter design pattern might be a reasonable choice.
Also, if you don't know what the AST tree is or if you're curious what the SQL language and the Interpreter pattern have in common, you should definitely read this article.
RuPy is the strongly dynamic conference concerning mostly Ruby and Python programming languages. Registration is open from some time and now we have also completed the agenda. There will be a load of talks and many geek world stars will come to talk about their experiences.
Read on if you're curious who's going to make a speech at RuPy'09.
If you want to learn how to write Rake tasks, this tutorial is right for you!
You're going to learn what the build tools are in general. I will show you how to write your first simple Rake task and how to express dependencies between tasks. I will also cover some useful FileUtils methods.
Get intimate with Rake now!
We have a first confirmed speaker - Obie Fernandez. Obie is a well-known Ruby on Rails developer and founder of the Hashrocket company. He also keeps a blog and often speaks at conferences.
Last year I have had the occasion of attending the RuPy Conference. Idea of the community-driven conference took my fancy and I decided to take an active part in the 2009 edition of RuPy.
I cooperate with the RuPy Conference organizers and I will be responsible mainly for keeping the community together. There is also a chance that I'll make a presentation entitled "Artificial Intelligence Methods in Ruby".
If I only get to know something new, I will gladly share the information with you. And if you have any questions regarding the RuPy Conference, do not hesitate to contact me.
In the introduction to building a math parser I already mentioned the Reverse Polish notation, also called "postfix notation". Its main advantage is unambiguity: you can simply read expression from left to right and calculate its value at the same time. You have to neither set up operators priorities nor use parenthesis.
There are many implementations of Reverse Polish notation parser available, but most of them seem to be too complicated. So I decided to write a very simple RPNParser Ruby class (RPN comes from "Reverse Polish notation").
Generally, it is a good idea to automate every boring, complicated programming task that often needs to be repeated. Firstly, developer's time and nerves can be spared. Secondly, the risk of doing something wrong (e.g. making a typo or leaving out one of the steps required) is minimized. Prepare the task once and don't repeat yourself anymore.
There are many tools available and the choice is determined principally by the language and environment we use. Some of the most well-know tools are make, Ant, Phing, Capistrano and Rake. In this short article, we are going to show how to write simple but powerful Rake task to run RSpec tests with code coverage meter.
A Hash in Ruby is a data structure that holds values in the key => value fashion. The Hash class provides many useful methods, some of them come from the Enumerable module. We won't go through all of them now, we'll rather focus on the often forgotten, but worth its value method: default().
We are also going to introduce the Null Object design pattern and show how it can be combined with the default() hash method.
Sometimes, when we are working with objects in Ruby, we want to make a copy of them. But what for? Well, in most cases we want to have a working copy and still maintain the original, intact object. Changing a reference back to the primary object is much simpler than repairing object's state.
As we are going to show, Ruby object cloning may sometimes behave in an unexpected way. We are going to show why weird things happen and how to force Ruby to clone objects in the way we want. We will use clone method implementation and marshalling mechanism.
If you don't know what is a sitemap, I strongly encourage you to fill this gap in knowledge first and then get back to reading.
It seems to be clear that manual updating a sitemap can turn into a horror. Hopefully we can make the Rails do the job for us. We are going to need a separate action, an XML view and model methods to provide us with URL data. You can read here how to put all these things together.
Sitemap is the most convenient way to tell the search engine how does a website structure look like and what URLs does it contain. The problem is that some pages may be nested to deep or somewhow unreachable to the search engine. Building a sitemap is a reliable way to keep the search engine aware of every subpage, even if it is located deep in the site structure or if its URL is available only through Javascript call.
We are going to talk about sitemaps history, show an example sitemap compatible with Sitemap protocol and tell how it can be generated with ready-to-use software.
Sometimes we want part of the website to be available to specific users only. Either we don't want our users to interact with a piece of functionality we are still working on or we want to show the new function to our client first, before making it available to the public. In both cases, we can't let a single unwanted user to slip through our fingers.
HTTP basic authentication is the most simple way to achieve this and we're going to show how it can be used in Rails. It's really simple!
Tidy is a quite powerful program which main purpose is to fix errors in HTML documents. TidyLib is a library version of Tidy written in C and by reason of easy C linkage, it can be used from within nearly any programming language, including PHP.
We are going to show how Tidy can be used to fix errors in HTML documents, reduce bandwidth usage, output XHTML documents and how it can be composed with existing template rendering mechanism.
Rails ActiveRecord is a quite useful piece of software, though it lacks some features and way of achieving the desired result is not always obvious.
Let's assume that we have two tables in our database: categories and posts. We would like to get most essential categories; i.e. those having at least 10 posts assigned to them. We can achieve this using the SQL JOIN, GROUP BY and HAVING clauses. However, there is no :having parameter on the find() method's parameter list.
Let's take a look at a simple workaround.
Writing test code is a worthwhile practice and building a parser is a good example to prove this claim. It won't be a good idea to start writing the parser from scratch, add all methods we think necessary and then run the code for the first time. Instead of tempting fate, we should write tests for every line of code we create.
We're going to show how easily can our parser be tested using the RSpec framework.
The example implementation of a math parser is going to be written in Ruby because of its simplicity. We are going to introduce complete and ready to use source code, together with comments and notes.
In general, parser is a program that determines whether its input is valid, referring to the given grammar. So, if we would like to parse math expression, we have to set a formal grammar first. The most convenient way to do this is to write the context-free grammar's production rules using EBNF (Extended Backus-Naur Form) notation.
We're going to show how to describe simple expressions with context-free grammar. If it sounds scary to you, don't panic! We're going to do it step by step.
Everyone knows how to calculate value of a simple math expression, like "2 + 3 * 7". But not every programmer knows how to write a program that would accomplish the same task.
We are going to build a math parser in Ruby, but first we need to consider evaluating math expressions in general.