Category: Home

Atom Entries Generator

Posted by on 20-Aug-2009

Recently there are a lot of tools to test the receiving part of your webhooks. I’m personally using http://www.postbin.org/ for my tests. I couldn’t find however a good way to “feed” my webhooks with a constant stream of fresh entries. There is a Superfeedr Simpulator, but it’s to much bound to their service. I needed a more general solution, so I created AtomGen - Infinite Atom Entries Generator.

The application providing two feeds. First one generating Atom entries every minute and the second one - every 5 minutes. The one minute feed is protected by a secret token in the end of the URL.
If your application is installed for example on URL http://example.com/ , the two feeds will be:

http://example.com/feed/1/YouSecretHere    (1min feed)
http://example.com/feed/5                  (5min feed)

The application is currently deployed on Google AppEngine. You can use the 5 minutes feed for your tests - go to
http://pubsubhubbub.appspot.com/subscribe and subscribe for the http://atomgen.appspot.com/feed/5 topic. This will send to your subscribers a new valid Atom entry every 5 minutes.

There is also a FriendFeed group, which is already subscribed to the 5 minutes feed. You can use it to gen notifications via IM etc.

The feeds have atom:link[@rel="hub"] element and the 5 minutes feed is pinging the hub on feed generation. By default the Google’s reference implementation is used.

I tried to make the atom generator a good Internet cityzen by setting up the proper HTTP headers (‘Last-Modified’, ‘ETag’ etc.). ‘Etag’ header contains the ID of the last entry, cryptography signed, like suggested in
http://code.google.com/p/pubsubhubbub/wiki/PublisherEfficiency

The current implementation does not use Google Datastore. Feeds are kept only in the memcached object caching system.

Install merb from git

Posted by on 16-Sep-2008

Trying to install the development version of merb , i’ve got:

no such file to load -- extlib/tasks/release

Seems the extlib gem is too old for merb. Fix:

$ git clone git://github.com/sam/extlib.git
$ cd extlib
$ rake gem
$ sudo gem install pkg/extlib-0.9.4.gem

The rest of installation process:

$ sudo gem install sake erubis mime-types
$ sake -i http://merbivore.com/merb-dev.sake
$ mkdir ~/merb_src && cd ~/merb_src
$ sake merb:clone
$ sake merb:install:all

Your first application:

$ merb-gen app my_app --flat && cd my_app

TinyURL Ramaze Application

Posted by on 28-May-2008

Created tinyurl ramaze applicationeverything in one file – model, view, controller. Required gems: sqlite3-ruby, sequel, validatable, ramaze .Even have an API:

$ curl -O turl.rb http://zhware.net/code/ruby/ramaze/turl.rb.txt
$ ruby turl.rb
# browse http://localhost:7000/
# shorten url
$ curl http://admin:secret@localhost:7000/_api?turl=http://zhware.net/code/ruby/
# restore the original url
$ curl http://admin:secret@localhost:7000/_api?url=abc
# number of hits for given turl
$ curl http://admin:secret@localhost:7000/_api?hits=abc

Do not forget to change the BASE_URL and LOGINS values. By default the database file (sqlite3) will be created in the same directory with turl.rb . If this is not acceptable, change the DB_FILE line.

Update: created the turl project on github

26th Ruby Kansai Workshop in Kyoto

Posted by on 19-May-2008

On 17-May-2008 there was 26th Ruby Kansai Workshop in Kyoto . A lot of fun like always :) The chatlog from the presentations is available on lingr.

I gave a presentation “Ruby off Rails” about developing web applications in Ruby, but without Rails – Sequel, Rack, Ramaze etc. talk. The presentation slides:

The sources from the talk (plus some extras – rack middleware examples) are available on Google sites for download.

There was no time to speek about Tamanegi – my feeds aggregator in Ramaze , but maybe on some other meeting…

There are also another two presentations:

“5 ways to run Ruby on Rails web applications”

by okkez-san

presentation slides

Benchmarking CGI, FastCGI, mod_ruby, mod_rails and mongrel_cluster. Received very good documentation with configs for all mentioned deployment options.

Okkez-san is using Rabbit – very cool presentation tool, written in Ruby! Just needed ruby-gnome. Will try it soon maybe.

Some notes:

  • ebb is still a pain to install
  • mod_ruby is not bad deployment option
  • webrick overperforms fastcgi for simple installs (still a valuable option for intranet for example)
  • thin is fast

I think thin is faster because of the underlaying EventMachine TCP stack implementation in C. The others are just pure Ruby-based, so there is nothing to compare for simple requests (ab benchmarks).

“Agile web posting with Ruby”

by ujihisa-san

presentation slides

There are sooooo many web services around. Can the posting to them be automated, using Ruby-based tools?

!!! Big Fat Warning: The presented tools will make you very ‘productive’. Maybe your friends will stop following you. Use on your own risk! ;)

Main working horse – www:mechanize ruby port :

gem install mechanize

So far so good. But can you post directly from VIM? Seems there is vimscript – i way to customize vim in different languages. Try:

vim --version

and if you see +ruby you can use ruby in vimscripts like:

# ~/.vim/plugins/some_plugin.vim
...
VIM.evaluate(’..’) evaluate %[sdfsds]
...

And even better: there are already a lot of ready ruby-based VIM plugins in the CodeRepos vim repository

20th “Ruby for beginners” lesson

With a ‘little’ help from google my answers was:

FizzBuzz

(‘Aho’,’Bow’ and also say ‘Aho’ for numbers that contain ‘3’):

puts (1..100).map { |i| (s=(i%3==0?'Aho':'')+(i%5==0?'Bow':'')+(i.to_s =~ /3/?'Aho':''))==""?i:s }

99 bottles of beer

I like Jeremy Voorhis’ implementation . Just modified it to handle 1 bottle situation:

#!/usr/bin/env ruby

def expensive
  @expensive ||=
    begin
      n = 99
      buf = ""
      begin
        buf << "#{n} bottle#{n>1?'s':''} of beer on the wall\n"
        n -= 1
      end while n > 0
      buf << "no more bottles of beer"
    end
end

puts expensive

‘X-Sendfile’ for Rack , take 2

Posted by on 11-May-2008

In the spirit of “Fork me if you like me” I forked the Rack project on github and applied my ‘X-Sendfile’ related changes. Now you can have download acceleration with:

use Rack::Static, :urls => ["/files"], :root => "public",
    :extra => { 'X-Sendfile' => 'yes' }

I just made a small change to pass the extra parameter down to Rack::File and adding ‘X-Sendfile’ related headers for nginx, apache and lighttpd.
extra parameter can also contain others, non x-sendfile related headers (like cache-control etc.):

use Rack::Static, :urls => ["/css","/images"], :root => "public", :extra => {
  'Cache-Control' => 'max-age=86400, public',
  'Expires' => (Time.now + 86400).utc.rfc2822
}

I also added some examples for rackup and middleware to the examples/ directory. Merged the josh’s daemonize fork too, but today (11-May-2008) it was merged to the master branch.

Rack::XStatic Middleware - ‘X-Sendfile’ for Rack

Posted by on 08-May-2008

After I found the Rails X-Sendfile plugin , decided to code something similar for Rack (and Ramaze). The result: Rack::XStatic middleware . Example usage: xfile.ru rackup file . Start it with:

rackup -s thin -p 7000 xfile.ru

For using it with nginx ’X-Accel-Redirect’ :

# inside your .ru rackup file:
use Rack::XStatic, :urls => ["/down", "/files"], :root => "public",  :extra => {
  'X-Sendfile-Type' => 'nginx',
  'X-Accel-Limit-Rate' => '1024',
  'X-Accel-Charset' => 'utf-8'
}
# inside your nginx.conf file:
location ~ ^/(down|files)/ {
  internal;
  root /full/path/to/rack/public;
}

‘X-Sendfile-Type’ can be also ‘lighttpd’ , ‘apache’ or just ‘yes’ for adding only the ‘X-Sendfile’ header.

Rack::XStatic also allow me to add custom headers to the response :

use Rack::XStatic, :urls => ["/css","/images"], :root => "public", :extra => {
  'Cache-Control' => 'max-age=86400, public',
  'Expires' => (Time.now + 86400).utc.rfc2822
}

Throttler Ramaze helper

Posted by on 14-Apr-2008

After reading Rails Plugin: Throttler I created a Throttler Ramaze Helper .

  • What is it for? ”…The throttling plugin monitors the load of your server and allows you to disable certain features of your app when the load is too high…”
  • How to use it?
    • Copy throttler.rb to /{ramaze_gem_dir}/lib/ramaze/helper/throttler.rb
    • In your controllers code:
      class MainController < Ramaze::Controller
        helper :throttler
      
        def index
            # (optional): override the threshold when calling throttled?()
            # unless throttled?(10.00) ...
            unless throttled?
               "Hello World"
            else
               "Overloaded: #{current_load}"
            end
        end
      
      protected
         # (optional) set another threshold value
         def threshold
            5.00
         end
      end
      

Thanks a lot to Kashia from #ramaze for the help.

Later I start thinking “Hm, maybe that one is better to be Rack middleware …”. Maybe next try…

Locale problems with Ubuntu-7.10 minimal install

Posted by on 21-Mar-2008

Problem (after any package install i’ve got):

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

Solution:

$ sudo apt-get install language-pack-en

Rails on GIT

Posted by on 26-Feb-2008

Semi-official Rails GIT repositories, maintained by Michael Koziarski :

$ git clone git://github.com/NZKoz/koz-rails.git

Update 13-Mar-2008: Steve’s git-svn mirror of the Rails repo (see the comments)

git clone git://git.sanityinc.com/rails.git

Second GIT origin

Posted by on 21-Feb-2008

I made a mistake to clone from my GitHub Public Clone URL . When trying to push the changes, there was a message:

fatal: The remote end hung up unexpectedly
error: failed to push to 'git://github.com/zh/raplanet.git'

So I added the second origin, the Push URL and successfully pushed to it

$ git remote add origin2 git@github.com:zh/raplanet.git
$ git push origin2 master

Well done, no changes lost :)