To my shame as a rubyist, it was only a couple of hours ago that I found out, while reading Ruby Inside about mod_rails and the wonders it does for the Rails community.
(more…)
Archive for the ‘Tutorials’ Category
Dreamhost and mod_rails for your tiny Rails application
Thursday, May 29th, 2008Ruby for daily chores: Extracting most frequent loto numbers
Sunday, August 19th, 2007Here’s the quick story: I was hoping to win the Romanian lottery (6 winning numbers out of 49). On the website, they were having the list of the winning numbers from 1998 to now. So I copy-pasted them all into a text file, and wrote a quick and dirty script to count their appearances and sort them – thus getting the lists of the most frequent numbers and the least frequent ones.
First, the input text file – I’ll show you a brief excerpt:
Setting up Rails and SQLITE
Wednesday, April 25th, 2007If you are interested in web, databases and the like then you probably already heard of SQLITE. If not, here’s a quick intro
SQLITE is a database engine that uses just one file per database. It’s tiny, simple to use and, most importantly, very easy to use with Ruby on Rails. All you need is the sqlite ruby gem, which is already included in most Ruby installations.
What is sqlite3? Nothing much than a newer and better version of sqlite. You should use it instead of sqlite if you have the chance.
How do you set it up in Rails?
Let’s say you want to make your own database-driven Rails application. Mysql is a big download, a bit difficult to install, etc. Plus, you don’t really need it; you just want a tiny sql database engine that works with Rails, so you can develop and test your application.
Nothing easier: if not already installed on your machine, then you download and install sqlite3.
Then you make sure you have the latest sqlite bindings in place : gem install sqlite3 .
Hmm.. what else?
Grepping in Ruby
Tuesday, April 3rd, 2007You can’t call yourself a programmer if you never used Grep (or diff, or wget, or regular expressions for the matter). I couldn’t call myself a programmer till the fourth year of college, btw..
Still, grep has a pretty big manual page, and being a casual grep user I never see the need to memorize it. The one and only grep command I use and abuse is
grep -Rn "my pattern" . which, for people not familiar with it, means “search my pattern in all files under the current dir, recursively, and if find then print out also the line number”. Seriously, this might be the one and only use I have for grep now.
What about more complicated tasks, involving regular expressions and the like?
Since my job involves Ruby and Rails, there’s basically no need for me to use grep anymore. I mean, my tasks don’t involve real-time text line extractions; from time to time, though, they involve writing scripts that extract specific patterns from some log file.
Here’s where Ruby is my best friend. And given that I’ve had a bit of trouble putting together the bits and pieces found on the internet, I’m sticking it all together here:
How to import Textpattern into Wordpress
Friday, March 30th, 2007IMPORTANT ANNOUNCEMENT: This article was published more than 2 (TWO) years ago. It has helped, apparently, quite a lot of people migrate to Wordpress. However, there are high chances it has become highly outdated or even harmful. Before trying the steps and script I described here, you should try to use the migration script included in Wordpress. Chances are it got updated in the last 2 years and is now better than this (old) script.
I’ve talked a bit about this before : in my years of blogging I switched from a Blogspot account to Livejournal and finally, in 2004, to a self-hosted stand-alone blog. The main criteria for my CMS-blogging engine back then was simple: does it have RSS? can I have several Sections; is it nice-looking? Textpattern had it all at the time and I went for it. But, after a while, Wordpress 1.5 came along and I started getting angry that it had all this power: plugins, community, easy-to-hack framework.
Bottom line, I’ve been dreaming for 2 years already to migrate my Textpattern blog into a Wordpress one, one that I could easily hack, extend and theme. Finally, the day before yesterday (March 31 2007) I pulled myself together and started doing it.
Have you ever wanted this? If so, then tough luck: the instructions over here suck; so does the info from this wp thread.
So, without much ado, here are my instructions on migrating Textpattern 4.0.4 to Wordpress 2.1:
Ruby on Rails – 1-2-3 to performance analysis
Wednesday, March 28th, 2007My cool colleagues from Trex Global gave me an unusual assignment this week: profile the current implementation of our first two apps, DeferEm and DepreciateEm.
Among the requests, the usual ones:
Request response duration
Execution profile of flow (path taken, time in methods)
SQL Queries made
Analyze and Identify performance bottlenecks - in-memory, sql query exec
Rails on a Mac – 1-2-3 noobie guide
Tuesday, March 27th, 2007Warning! This is not a full-blown tutorial, rather a quick step-by-step intro on what you have to do to run Rails on your Mac, if you are a noobie who just heard of Rails and wants to have it running on his computer ASAP:
- Step 1 – Get Rails – Rumours say that in the upcoming OS X version β Leopard, Rails will be included by default. If you are on a previous version, though β such as Tiger, then no need to despair β somebody thought about people in a hurry and made out a beautiful app. Itβs called Locomotive and includes ruby, rails and many useful gems(tiny ruby libraries with extra functionalities).
- Step 2 – Get MYSQL for the database backend. If you want to install it as a standalone app, then be my guest. It’s a bit complicated and I’ll be talking about this in a future article. Until then, though, there’s a very nice app out there that has it all: it’s called MAMP (as in Mac, Apache, Mysql, Php) and it’s free. It comes with PhpMyAdmin as well to help manage your databases from the browser.
- Step 3 – Get Started: You should install and start MAMP, and write down the connection settings it shows (server name, port, socket). Then you go to PhpMyAdmin and create a new database; write down the name, user and password. Start Locomotive and select “Create New…” (Command+N). You select the folder where the app will be created, give a name to the app, OK, and you are set – the system creates the rails application folders where you wanted. All it’s left to do is complete the database config file (RAILS_APPLICATION/config/database.yml) with the connection settings you found out from MAMP – remember to input the server name, database name, user name and the socket value (socket:/path/to/your/mysql.sock) .
development:
adapter: mysql
database: myapp_development
username: root
password: root
socket: /Applications/MAMP/tmp/mysql/mysql.sock
host: localhost
Here you are now! Your Rails application is ready to be developed on your Mac. Go get a good Ruby on Rails tutorial and start rolling!