For the whole of May, I will blog about weird things in Ruby over at Idiosyncratic Ruby – Don’t miss it!
Long time readers of this blog will remember that I used to tweak GNOME’s gedit editor a lot. However, I ditched it for Sublime Text and I am not looking back. Here are some of the things I like about Sublime:
- Offers a good out-of-the-box experience, including an amazing “fuzzy search” tool (ctrl+p)
- It works on ubuntu without any problems
- Fast (enough)
- Multiple cursors!
- Once you have installed Package Control: An integrated extension repository
- Encourages you to write your own extensions
- Looks good
Wrongly used randomness can be the source of hard-to-detect bugs and security holes. This is relevant every time you use randomness, for example, when implementing an existing protocol/interface that requires random values or generating tokens for your next raffle. This article describes when to use which of Ruby’s randomness methods.
Ruby’s structs are one of my favorite data types in Ruby. They help you to keep some defined structure in the dynamic world of Ruby. Often, it makes sense to use them instead of hashes or arrays. Read-only structs take the idea a level further.
- stores your passwords in a file on your disk
- encrypts the file with a master password
- is designed for every-day-use
- is written in
234lines of understandable Ruby code… Read it!
- is tested with 222 Cucumber steps
So you’ve installed (or upgraded to) ubuntu 11.10 and everything looks great… Except – uh!, lots of gedit plugins are only compatible with gedit 2! But don’t be sad.. or angry.. This guide points out, how to, nevertheless, create a solid foundation that allows you getting prodcutive with gedit!
Rails migrations are easy to understand and easy to write. However, you can save some unnecessary key strokes by applying these three tips :)
There are plenty terminal color gems out there. Now, there is one more. Why?
puts is great for a quick output, but when a script gets more complex or you want to offer a flexible executable, consider using the logger ;). Since the logger class is part of the Ruby standard library, it can be used everywhere, without installing any gems. And it’s very easy to use :D
Somehow, I stumbled upon this useful little script by _why: Update
Hirb: “A mini view framework for console/irb that’s easy to use, even while under its influence. Console goodies include a no-wrap table, auto-pager, tree and menu.” now supports unicode in two ways:
│ Support for unicode full-width characters │ Unicode table characters instead of +/- chars │
Many people use irb with wirble. I also did.
I’ve been quite happy with it, but sometimes I noted that some symbols were displayed as : without the symbol name (e.g. in method name arrays) and that the representation of regexes looked quite strange.
This is why I’ve looked at the wirble tokenizer, fixed some bugs, liked it, extended it and created Wirb. These are the improvements:
- Use fancy colors! You can colorize the prompts, irb errors, stderr and stdout
- Output results as Ruby comments
- Enhance your output value using procs
.gemspec file of a gem allows to specify requirements for that gem – but usually you do not get to see them. These five lines patch RubyGems, so that
gem displays the requirements of a gem after it has been installed:
Not everyone likes debuggers. I rather print the debug values myself – it works and I do not need to learn a debugger :P
## ## ## ## ## ## #### ### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ######### #### ## ## ######### #### ## #### ## ## ## ## ## ## ## ## ## #### #### ## ## ## #### ## ## ##
The Zucker gem has gotten some new features. Installation is as easy as
gem install zucker
One of my favourite ways of learning something about existing code is to load it into irb and play around with it. You are able to ask every object in irb what it can do. It is as easy as you just asking for
public_methods and the object will show its abilities. But often you get spammed by
Object or irb methods that you rarely want to use.
One useful (and funny) feature of Ruby is the
Symbol#to_proc method that lets you write concise code like this:
%w|1 2 3 4|.map(&:to_i). Almost everyone who knows this feature loves it ;). However, the use cases are pretty limited, because in most cases you need to pass parameters!
In Ruby, dealing with Arrays and similar objects is pretty fun. And we have gotten more possibilities with Ruby 1.9.2 :)
Transferring an existing project to Rails 3 is not that hard, but it usually cannot be done in 5 minutes.
You can, of course, use an IDE for coding – but reconsider it: After hours of initialization, it tries to do everything for you… Somewhere in the never ending menu jungle… And you need to click all the time… Stop! Focus on the gist! You want to write code!
Most Ruby programmers know: Many things can be done in much less time on the command line. To become more productive, you should take the 10 minutes to configure some basic settings.
A common Ruby experience on ubuntu: You get some stupid error, saying something would be missing – and you don’t know what to do…
Installing Ruby/Rails on ubuntu is not hard, but some little obstacles might be confusing.
This is a Ruby implentation of the SHA-256 hashing algorithm. Truth be told: It is almost a plain copy of the Wikipedia pseudocode ;)
After editing some source files with different editors on different platforms, I had some troubles with automatically inserted tabs messing it all up.
This little script replaces all tabs with two spaces.
This article is written for people with experience in programming in general, but who are new to Ruby.
A German version is published in the offline magazine #2, a magazine by some students of TU Dresden.
The intention is to demonstrate some features of Ruby and show, what is so great about Ruby:
A clean syntax combined with the possibility to adapt the language to given requirements flexibly.
Some days ago, I discovered a website – which is the most addicting one I know :) – codegolf.com. The goal is, to solve programming problems with as short code as possible.
As I said, it is addicting. You do not write better ruby code by golfing. But you can really improve the knowledge of the language. And it is fun :)
After doing some of the other challenges I tried the brainfuck challenge.
Brainfuck is a Turing-complete esoteric programming language consisting only of 8 letters, operating on a 30000 cells-array. This is the hello world program:
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.
The goal is to build a interpreter.
Some time ago, I conducted a short presentation about Ruby. And to impress the audience, I did some live coding and implemented the quicksort algorithm in 5 minutes. They were impressed :)
In my current Rails project, I use the aegis gem for rights management. And I almost got mad, wondering, why it wouldn’t work..
About a year ago, some students at my university announced a little programming competition for students beginning studying IT, like me. The language could be chosen freely.
At this time, I had already done some C and PHP programming.. but I also had heard of Ruby and that Ruby is sooo cool. So I decided to learn the basics of Ruby by taking part… and it’s been the right decision! I fell in love with Ruby ;).
I publish my solution here. It is a good “try to understand what it does”-exercise for people new to Ruby or programming in general (or people doing Rails only all the time).
When I began programming Ruby/Rails, I quickly found the online Ruby documentation at ruby-doc.org and the Rails API, which are both very useful. But unfortunately, one cannot be always online. In this blog post, I’ll demonstrate some ways to generate or get the docs offline and some hints on using them.
At my last entry, a question arose about what is the most efficient way to convert integers between the bases 2 and 10: either using built-in ruby methods (and even do lightweight string-operations) or calculating it manually. I had to find out ;). So I have written a little benchmark program, which does the conversion in three different ways:
- using built-in to_i-magic
- calculating it by hand
- using sprintf
It stops the time each method needs to get the fastest. The result might be surprising. [Update: improved the custom methods]