Archive for the 'ruby' Category
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)
posted by pedro mg at 9:24 pm
& filed under ruby, code, github | No Comments »
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¶m2=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¶m2=&offset=3
(blogged from Vim)
posted by pedro mg at 1:53 am
& filed under web, ruby, code | No Comments »
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 […]
posted by pedro mg at 6:38 pm
& filed under ruby, code, merb, datamapper | No Comments »
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 […]
posted by pedro mg at 11:15 am
& filed under tech, apple, ruby, code, git, github, gist, osx, unix, postgres, postgresql, datamapper, database, dbms | 7 Comments »
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 […]
posted by pedro mg at 5:24 am
& filed under linux, os, ubuntu, apple, ruby, code, debian, vimblog.vim, vimblog, merb, osx, postgres, postgresql, datamapper | 3 Comments »
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 […]
posted by pedro mg at 8:29 pm
& filed under tech, ruby, standards, code, rubyforge, open source, merb, gemcutter | No Comments »
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
posted by pedro mg at 10:47 pm
& filed under tech, ruby, code, osx | No Comments »
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 […]
posted by pedro mg at 2:37 am
& filed under ruby, code, tokyocabinet | No Comments »
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 […]
posted by pedro mg at 1:27 am
& filed under tech, web, rss, linux, os, ubuntu, ruby, standards, vim, gvim, s3, ec2, mac osx, debian, mvc, rspec, TODO, git, github, vimblog.vim, vimblog, merb, couchdb, aws | 6 Comments »
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 […]
posted by pedro mg at 5:54 pm
& filed under life, ruby, code | No Comments »
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: …
posted by pedro mg at 11:12 pm
& filed under ruby, code, mvc | No Comments »
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 | […]
posted by pedro mg at 7:46 pm
& filed under ruby, code, camping | 2 Comments »
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 […]
posted by pedro mg at 2:25 pm
& filed under ruby, code | 2 Comments »
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. […]
posted by pedro mg at 3:22 pm
& filed under linux, ruby, shell, code, vi, vim | 2 Comments »
April 7th, 2008
self note for a nice read: Introduction to the Rubinius compiler
posted by pedro mg at 10:36 pm
& filed under ruby, code | No Comments »
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 […]
posted by pedro mg at 12:31 am
& filed under ruby, code, git | No Comments »
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
posted by pedro mg at 12:48 am
& filed under linux, ruby, code, twitter | 1 Comment »
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 […]
posted by pedro mg at 10:32 pm
& filed under ruby, code | No Comments »
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)
posted by pedro mg at 9:06 pm
& filed under ruby, code | No Comments »
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 […]
posted by pedro mg at 10:51 pm
& filed under ruby, code | 1 Comment »
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 […]
posted by pedro mg at 7:56 pm
& filed under ruby, camping | 4 Comments »
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 […]
posted by pedro mg at 4:32 am
& filed under ruby, code, camping | 2 Comments »
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:
$ […]
posted by pedro mg at 12:21 am
& filed under ruby, code | No Comments »
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 […]
posted by pedro mg at 1:39 am
& filed under google, gmail, mail, ruby, code | 7 Comments »
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 […]
posted by pedro mg at 5:34 pm
& filed under ruby, code | 2 Comments »
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 […]
posted by pedro mg at 2:48 am
& filed under ruby, perl, code, camping, mvc | No Comments »
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. […]
posted by pedro mg at 3:48 am
& filed under , linux, ruby, code, vi | 2 Comments »
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…
posted by pedro mg at 5:07 am
& filed under , rss, ruby, code, Flickr | No Comments »
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 […]
posted by pedro mg at 12:00 am
& filed under tech, ruby, code, vim | No Comments »
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.
posted by pedro mg at 1:27 am
& filed under tech, web, linux, life, digital-life, ruby, shell, code, api, vi, vim, gvim, blog, open source, mac osx | No Comments »
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 […]
posted by pedro mg at 7:05 am
& filed under tech, web, ruby | No Comments »
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 […]
posted by pedro mg at 11:52 pm
& filed under tech, web, linux, ruby, code, api, vi, Wordpress, xmlrpc, vim, gvim, mac osx | No Comments »
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 […]
posted by pedro mg at 12:50 am
& filed under tech, web, linux, ubuntu, gnome, digital-life, ruby, shell, code, textmate, api, Flickr, vi, Wordpress, xmlrpc, vim, gvim, blog, screenshot, iccf, open source, GPL | 4 Comments »
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 […]
posted by pedro mg at 11:09 pm
& filed under tech, web, linux, ubuntu, gnome, ruby, php, shell, code, api, vi, MovableType, Wordpress, xmlrpc, vim | No Comments »
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
posted by pedro mg at 12:20 am
& filed under tech, web, linux, ubuntu, ruby, shell, code, api, Flickr, switter, twitter, vi, rubyforge | No Comments »