Lunch Shoppe

A place for much random randomness... 
Filed under

ruby

 

Vlad the Deployer and Glassfish

I'm a fan of Glassfish app server as it's multi-threaded and works wonderfully with JRuby. However, today I realized that Vlad didn't have a way to deploy using glassfish so I wrote and extension. Check it out here: http://github.com/abhiyerra/vlad/tree/master

Loading mentions Retweet
Filed under  //   rails   ruby  

Comments [0]

rails script/runner

script/runner allows one to execute long running processes
by either running Ruby code or access the models directly.
For example, say you have some code like the following in your model code:
 

 
class NewsFeed << ActiveRecord::Base 
  def self.download_feeds 
    # TODO: The code to download the feeds and put them in the database 
  end 
end 

 
Say you want to run download_feeds on the commandline, you can by
running the following on the shell.
script/runner NewsFeed.download_feeds
This is useful if you need to run something regularly. So you can put
this in a cron file to execute regularily, like downloading news.

Loading mentions Retweet
Filed under  //   rails   ruby  

Comments [0]

Connecting to MySQL using JDBC

This is some JRuby code demonstrating how to connect to MySQL database.
 

 
require "rubygems" 
require "jdbc/mysql" 
require "java" 
def get_entries 
  begin 
    # Prep the connection 
    Java::com.mysql.jdbc.Driver 
    userurl = "jdbc:mysql://localhost/DBNAME" 
    connSelect = java.sql.DriverManager.get_connection(userurl, "root", "") 
    stmtSelect = connSelect.create_statement 
 
    # Define the query 
    selectquery = "SELECT * FROM users;" 
    # Execute the query 
    rsS = stmtSelect.execute_query(selectquery) 
    # For each row returned do some stuff 
    while (rsS.next) do 
      puts rsS.getObject("id") 
    end 
  end 
  # Close off the connection 
  stmtSelect.close 
  connSelect.close 
end 
get_entries 

Loading mentions Retweet
Filed under  //   ruby  

Comments [0]

JRuby fork

fork is not implemented yet in JRuby due to a couple of factors having to do with how it was implemented in Java. However, Charles Nutter came up with a solution using ffi. However, it is not in the mainline yet which is sort of annoying since so much task based software seems to use it. Also, I don't want to start using MRI again on my server box.

Edit:

This should enable fork. But it hasn't been working well from what I have been using it for.

 jruby -J-Djruby.fork.enabled=true filename.rb # (EXPERIMENTAL, maybe dangerous) Enable fork(2) on platforms that support it. 

Loading mentions Retweet
Filed under  //   programming   ruby  

Comments [0]

Fibers & Cooperative Scheduling in Ruby

Interesting article on Ruby Fibers. Need to learn a bit more about it.

Loading mentions Retweet
Filed under  //   ruby  

Comments [0]

JRuby memcached client

Pretty cool, my gemification of the jruby-memcache client by Ikai has been remerged into his tree.

Loading mentions Retweet
Filed under  //   ruby  

Comments [0]

Rhodes: Mobile development in Ruby

This is pretty cool. I have to play with this when I have time aka once done with finals.

Loading mentions Retweet
Filed under  //   ruby  

Comments [0]

JRuby

I've been using JRuby for my Ruby development and man it's getting faster all the time. It's pretty cool. I really want to help out, but I think I should learn a bit more about how compilers work. I sent in a few small patches to fix small issues. Hopefully, it will be 1.9 compatible soon so I can start using that for development purposes also it'll probably start letting people move to 1.9 in general if there are more than one source for its use.

I recommend anyone who is going to use Ruby to use JRuby and when using it use 'jruby --fast' which makes the code pretty past.

Loading mentions Retweet
Filed under  //   ruby  

Comments [0]

git

I've been content with Mercurial as it's fast and lets you do development and for the most part keeps out of your way. It has few dependences and is a great DVCS. However, the problem I am finding with Mercurial and one of the great benefit's of DVCS is branching and Mercurial, I think, gets its branching legacy from CVS/Subversion. To branch in Mercurial you basically clone the repository into a new repository and work in the new repository. For example, say you have repository A. Branching it involves running cloning A into B. You make your changes in B and merge them back into A when you are ready. This works but it sucks especially for Rails development which I do. The way one usually does Rails development is you have a checkout of a repo and you run a development server and work on those changes. However, when you want to branch in Mercurial you have to go to the new directory and start a new server instance and develop, merge, stop the server, start new server, etc. For some of you this may be fine, but for me it is a pain in the ass! This is one of the things I like about git all the branches are within the same directory tree so you don't need to do all those change directories. You can basically branch within the same tree and work with that. No need to clone all these repos to different directories. Now the things I dislike about git is that it's written in C! When I went to install it on Debian it had n+1 different packages it had to install! Though, I am biased toward scripting languages I personally think it would have been easier to port the app in the long run. However, another feature that I love about git is git-svn. It make branched development so easy as the branches are local so best of both worlds. This is especially since I work with a lot of subversion code bases. If I need to make different patches it makes it simpler to do so, especially when requirements change unexpectedly and you want to start a new branch without checking out the trunk again. So I'm going to play with git for a bit longer, but overall for now I like it. The documentation has clearly improved since I last looked at it.

Loading mentions Retweet
Filed under  //   programming   ruby  

Comments [0]

Ruby and the Way Forward

Ruby has just won me over. I mean there are so many things to love about it and several to hate, but I must say the language itself is quite nice. I have always been a Python fan, but I feel Ruby is a better Python. It is what Python should have always been.

Things I like:
  • Any object is extendable. I love this because it keeps things pure. Who wants to figure out whether it is len(blah_list) when you can do blah_list.length. Objects have properties and those properties are extendable or should be easily so to meet the needs of the developer. I'm not saying other languages don't have something like this, but Ruby just makes them so easy. I know this is ripe for abuse by people who may want to convert their Array objects to do array objects weren't really meant to do, but overall it's still a cool feature.
  • Blocks! Every Ruby user uses blocks as an excuse and I'm also going to be one of them. However, blocks are wonderful. Python has them too and the recent with statement is going to make it even easier.
  • Gems. Alright not really part of the language itself, but might as well be. My pain with Python has always been to install third party libraries and recently it has been getting better with easy_install and eggs, but considering the Ruby community dealt with that issue as the community has been growing is great since it makes it easy to deal with dependencies of libraries and if future Ruby releases have gems built in it will make it even better. This is one idea from Perl that is just awesome and Ruby implemented it pretty well.
  • I love the Regex support as part of the language itself. I mean Python was great and all, but I found it a pain to use Regex through libraries then again maybe I'm just an idiot? But having full support in the language itself is just friggin awesome.
  • ` for running system commands. Simple and returns a string so you can muck around with the output if you so choose. Great for those fast scripts.
Things I dislike:
  • Ruby has some weird method names for some of the standard libraries. Like how the hell am I supposed to know that 'test'.intern converts a string to a symbol.
  • The global variables! It seems like these could be abused and would be best if they weren't there. I mean all these things can be implemented mostly without them or with more logically named ones.
  • Looking at the Ruby code there seems to be a break of style within code for various libraries. Python is amazingly well organized in a consistent style while the Ruby code mostly the core libraries seem to be inconsistent in their style. I may be anal in that I hate seeing def method param, param2 and def method(param, param2) in the same class for different methods. It just doesn't look good! So I would think there should be a style set for the core language code itself.
  • Documentation. Ruby's documentation isn't really it's strong point, but it is getting better. Meanwhile, Programming Ruby is an amazing book and I recommend it to everyone learning Ruby.

Loading mentions Retweet
Filed under  //   code   programming   ruby  

Comments [0]