Archive for the 'ruby' Category

monstar.rb update

April 24th, 2013

New update on the monstar.rb ruby script to monitor and restart scripts/apps upon file ctime changes.
Now a -e –exec switch allows any system script/app to be launched via Process.spawn(SCRIPT)
PID processes are killed via INT SIGNAL.
More on github monstar.rb repository.
(blogged from Vim)


Manage URI Query params in Ruby

February 10th, 2012

How to programatically remove a Query parameter from an URI String in Ruby.
For the following URI:
http://example.com/resource?param1=1&param2=2&offset=3
If one wants to remove the “offset” parameter, the following may help.

EDIT: if a left side only param exists, it will be removed. Something like param2 in:
http://example.com/resource?param1=1&param2=&offset=3
(blogged from Vim)


DataMapper update_or_create

October 13th, 2010

Source code: git repository at github
DataMapper has a defined method named first_or_create, very explicit name, that takes a condition and attributes as params. Its source code defined in dm-core-1.0.2/lib/dm-core/model.rb is:
def first_or_create(conditions = {}, attributes = {})
  first(conditions) || create(conditions.merge(attributes))
end
What is does is simply find the first resource by conditions, or create a new resource with the […]


install PostgreSQL in Mac OSX via Homebrew

March 10th, 2010

Apple OSX Snow Leopard
System Version: Mac OS X 10.6.2
Kernel Version: Darwin 10.2.0
Install notes for PosgreSQL 8.4 install using the great
Homebrew by Adam Vandenberg.
Run the author’s installation script, and that’s it. Try:
$ brew help
$ brew search postgresql
$ brew install postgresql
==> Summary
/usr/local/Cellar/postgresql/8.4.2: 2297 files, 31M, built in 3.3 minutes
$ brew info postgresql
postgresql 8.4.2
My advice ? Use Homebrew. True UNIX […]


install do_postgres on OSX Leopard

March 3rd, 2010

Install notes for Datamapper do_postgres driver ruby gem on severall operating systems:
Apple OSX Snow Leopard
System Version: Mac OS X 10.6.2
Kernel Version: Darwin 10.2.0
(No Macports; No Homebrew)
PosgreSQL 8.4
I wanted to have PosgreSQL server working on the mac so that development is easier.
There is a .dmg package from the guys at EnterpriseDB that is a single click install. Check […]


Gemcutter indexing ruby gems

November 23rd, 2009

Date: Sat, 21 Nov 2009 22:15:15 -0500 (EST)
From: noreply@rubyforge.org
To: me@mydomain.com
Subject: [RubyForge] Gem index has been shut down
Hello -
You’re receiving this email because you’re a RubyForge project admin and a recent change robably affects you.
A few days ago we repointed gems.rubyforge.org to the gemcutter.org box. This means that Nick Quaranto’s excellent gemcutter app is now […]


sdef - scripting definition files

August 24th, 2009

Scripting definition files (sdefs) are XML files that describe everything
about an application scripting interface: terminology, implementation
information, and complete documentation. Applications may incorporate
them to define their own scriptability, and scripting clients such as
AppleScript and Scripting Bridge read them to determine what operations
an application supports.
man sdef


tokyo cabinet

July 23rd, 2009

Interesting article with links from Ilya Grigorik about Tokyo Cabinet, Tokyo Tyrant (remote network access to the DB, via a rest_client p.ex.) and the “magnifique” Lua programming language, integrated for the ease of creation of user _designed functions into the server. A question I asked is the ability, or lack, of dinamically feed the server […]


on work…

January 15th, 2009

3 or 4 new projects ahead.
One of them will be  CouchDB and Merb (no DataMapper, no ActiveRecord). The db schema is modeled by each user and upon criteria decisions.
All of them Git managed, as been doing for the last year.
Served by a Debian based Linux distro, coded under Debian, UNR (my lovely little netbook), and […]


Disparition de Guy Decoux

September 25th, 2008

This is a small post to remember a great ruby programmer.
Ruby France announced Guy Decoux “disparition”:
“He was part of the generation of developers who switched from Perl to Ruby in the 90s. While his mastering of Perl was already great, his knowledge about Ruby was so deep and impressive that a lot of Rubyists would […]


fragment identifiers

June 12th, 2008

Q: how in Routes/Markaby do we implement fragment identifiers # as in www.foo.bar/pedro#here, for named anchor jumps ?
H(int): is it necessary to parse the controller ?
H(int): can a regexp solve it ? ‘/foo/(\w+)#(\w+)’ doesn’t…
A: …


AR::migrations

June 9th, 2008

ActiveRecord database schema migration info is stored in the main database, so that if one needs to manually hack a migration (fastforward/rewind), just update TABLENAME_schema_infos column ‘version’ to a new value and manually change your schema. Next ‘boot’ may generate (or not) new migrations.
riverside=# select * from foobar_schema_infos;
id | version
—+———
1 | […]


class Monstar

June 5th, 2008

I recently had to move from using FastCGI on Camping Ruby framework, to sweet Mongrel because of getting too much 500 HTTP errors under some load tests. Yes irc::zimbatm, me too.
When on FastCGI behing Lighttpd, upon each request, the code is loaded so after changing its source, it gets updated.
Now, under development, Mongrel(s), behind the […]


blog with Vim script

April 10th, 2008

… after severall exchanged emails between me and Andrei Thorp about the Vim blogging ruby script, we made some changes. So instead of the initial test for Vim compiled with +ruby message s:ErrMsg, we now have an echo.
Andrei’s git (yep, they are git fans too, git rocks!) commit was calling another Vim from his machine. […]


Rubinius documentation

April 7th, 2008

self note for a nice read: Introduction to the Rubinius compiler


Shoes.rb on Github

April 4th, 2008

_why posted in Shoes mailinglist that he will be moving source code to Github.com. Since I am using Git for some months, this is good news.
In short, Shoes.rb repository:
http://github.com/why/shoes
You can clone the repository with:
git clone git://github.com/why/shoes.git
Ditz, (“a simple, light-weight distributed issue tracker designed to work with distributed version control systems like darcs and git”) will […]


Twittershoes: programming in Shoes.rb

February 22nd, 2008

I have to share this piece of code, wich results look indeed nice. You’ll see in the next blog post…

def string_alert
  c = (LIMIT-@iSay.text.length)
  @remaining.style :stroke => “#3276BA”
  c > 10 ? (@remaining.style :stroke => orange) : (@remaining.style :stroke => red) if (c < 21)
  c > 0 ? “#{c.to_s} chars” : “Too Long!”
end

[update]: Twittershoes.rb is born: screenshot here


JSON Ruby and Smallr API

February 3rd, 2008

Nuno’s smallr.net API talks JSON. So what about accessing it with Ruby ?
Well, quite easy thanks to Florian’s JSON implementation for Ruby. So:
$ sudo gem install json_pure
Now, just need some attention on the use of the address / (slash) just after json and before the query, or you’ll get a HTTP 301 Status Code.
Code follows:
require […]


on URI Ruby escaping

February 3rd, 2008

URI.escape method with no options doesn’t provide a trully good escape, and i just noticed it upon the need to access an API.

url = ‘http://www.ruby-lang.org’
bad = URI.escape(url)
good = URI.escape(url, Regexp.new(”[^#{URI::PATTERN::UNRESERVED}]”))

The difference is:

bad => “http://www.ruby-lang.org”
good => “http%3A%2F%2Fwww.ruby-lang.org”

(via snippets.dzone => Matt Zukowski)


The Ruby Programming Language

January 29th, 2008

… next buy.
“Bestselling author David Flanagan teams up with Ruby creator Yukihiro “Matz” Matsumoto and writer/cartoonist/programmer why the lucky stiff to bring you the authoritative guide to Ruby. Covering versions 1.9 and 1.8, this book helps you learn Ruby’s lexical structure, primary expressions, conditionals, syntax, classes, the data it manipulates, and more. For experienced programmers […]


flash-like implementation

January 13th, 2008

Flash is a Ruby on Rails method to show (mainly warning/error) messages. Camping has no such method, so i implemented an approach for error messages. The thing is, after a post method in the controller, the redirect creates a new instance for the controller, loosing the class instance variables set before.
So, after talking a bit […]


Camping on IRB

December 22nd, 2007

IRB is a great tool. What about testing parts of a Camping app in IRB (meaning App::Models module) ? Just require the app, but do not forget to establish the (in case of using it) ActiveRecord connection, that problably is specified in dispatch.rb
Try this, using _Why’s Blog webapp example:

$ cd /path/to/blog/app
$ irb
irb(main):001:0> require ‘rubygems’
irb(main):002:0> require […]


ActiveRecord connection adapters

December 22nd, 2007

…because of Camping::Models I’m using ActiveRecord Ruby implementation gem. Because source code is pretty well documented I maintain an opened xterm to check how things are done. Since I’m not using SQLite but PostgreSQL, i had to dig for the other parameters for the connection and I noticed AR has now connectors for severall DMBS:
$ […]


msg upload to gmail ruby class (imap)

December 4th, 2007

… moving to Google Hosted (Google Apps), there was the need to upload some thousands of e-mail messages. Since they were (mt) MediaTemple Berkeley mbox stores, i scp’d them locally (backup) and them imported them into Evolution local folders.
The problem was the copy/move to the google hosted imap mail server. Evolution couldn’t finish the task […]


more BDD and RSpec…

November 4th, 2007

“RSpec is a framework which provides programmers with a Domain Specific Language to describe the behaviour of Ruby code with readable, executable examples that guide you in the design process and serve well as both documentation and tests.”
…in RSpec
This is, RSpec is a state of mind in Ruby, represented in a DSL (Domain Specific Language […]


next is… Camping MVC microframework

October 30th, 2007

…next in line are 3 web apps that will me made entirely in Ruby with the help of Why’s very light yet functional Camping, the 4 Kbyte microframework.
Camping lacks things, and its Markaby is a bit slow compared to RoR’s Erb, but the approach taken by _Why looks very interesting for its simplicity.
I changed the […]


Ruby REXML::CData RDOC page

July 12th, 2007

… one can read this is in the official REXML::CData RDOC page:
ie_hack: Internet Explorer is the worst piece of crap to have ever been written, with the possible exception of Windows itself. Since IE is unable to parse proper XML, we have to provide a hack to generate XML that IE‘s limited abilities can handle. […]


Flickr SET’s RSS Feed

June 12th, 2007

… no. No feed available. But thanks to cygnoir and wirehead info at Flickr IRC channel, i can get these feed by using the API. So i’ll code it now and there, Ruby will help me get those feeds, hopefully. Good’old IRC…


Hpricot - HTML parser for Ruby

May 27th, 2007

Hpricot is a very interesting lib to parse HTML. I’ll post here the example, just to check on the beauty of it from time to time…

require ‘hpricot’
require ‘open-uri’
# load the RedHanded home page
doc = Hpricot(open(”http://redhanded.hobix.com/index.html”))
# change the CSS class on links
(doc/”span.entryPermalink”).set(”class”, “newLinks”)
# remove the sidebar
(doc/”#sidebar”).remove
# print the altered HTML
puts doc

The lib is evolving, being added […]


Blogging from Vim

May 11th, 2007

… i finally set up the page for the download of the vimblog.vim vim-ruby script. It will allow you to manage your blog posts from *the* editor VIM, very easilly. Learn one single command and, at maximum, seven simple parameters. So go ahead and blog with vim.


Engine Yard

April 4th, 2007

… i saw a small video on buiding a cluster. When placing the machines in the cabinet i noticed they inserted them close to the top. It is known the heat goes up, and a while ago i attended a conference where a mechanical engineer showed some heat graphs, thermal cabinet photos and presented […]


Blogging from VIM (timezone insanity)

February 25th, 2007

Blogging from VIM is now possible using this script. This post is being written using it. But one problem is making me loose a great ammount of time: dateCreated, meaning TMZ headache.
Wordpress XMLRPC wants a datetime timestamp for the dateCreated field. I give it an ISO8601 format as stated in XMLRPC specs.
The post is sent […]


Vi blogging bundle

February 21st, 2007

… well the name reminds Brad Choate’s Textmate blogging bundle Brad is an excellent developer and like me, was once a Delphi (Borland great product) developer. I based this on his Textmate work. I’m coding a Vi / ViM / GViM script for a plugin that has some nice results already, exclusively for […]


Wordpress XMLRPC::Client.new()

February 18th, 2007

… when coding switter, using lot’s of command line, vim, bash, i felt the need to blog from vim. Some readings (quite a few availlable, actually) later, i was testing Wordpress xmlrpc using MovableType (Six Apart) calls to it. Vim allows ruby scripts (when compiled with that directive) use to create new commands, just like […]


switter on rubyforge.org

February 12th, 2007

…now, switter was accepted on rubyforge.org. I’ll try to put source and some docs there (rdoc does wonders) soon. Meanwhile, and with threahds now working for continuous message post/get, it just needs some tickles on the readline method.
switter on a maximized shell window receiving public timelines
switter on a normal sized shell window receiving public timelines