Angel \”Java\” Lopez on Blog

May 29, 2012

AjGenesis Code Generation in .NET, Javascript and Ruby, All the Gates are Open

Usually, I get up early in the morning. Today, I got up a bit earlier, with some ideas about how to implement a simple template engine for my personal project, AjGenesis in Ruby. Then, I put my hands at work, and 3 hours later I had a solution, built using TDD (I made frequent commits, so you can see the progress of development in the GitHub Log).

The result at my GitHub account:

https://github.com/ajlopez/AjGenesisRb

Initially, I planned to use one of the template engines already available in Ruby, like Haml. But I decided to write my own implementation. Past week, I wrote AjGenesis in Javascript/NodeJs, see:

https://github.com/ajlopez/AjGenesisNode

In that project, I separated the template engine in another package:

https://github.com/ajlopez/SimpleTpl

In this way, I designed the template format to be similar to the original templates in classic AjGenesis.

I reuse the Javascript template engine in another new project (code kata of the past weekend):

https://github.com/ajlopez/SimpleMvc

a simple MVC implementation over NodeJs/Express.

So, now you have three projects:

- Classical AjGenesis code generation, implemented in .NET (see examples folder)
- AjGenesis in Javascript/Node, with SimpleTpl template engine, with interpolated Javascript expressions, and embedded Javascript commands (see samples folder)
- AjGenesis in Ruby, with a similar internal template engine, with interpolated Ruby expressions, and embedded Ruby commands (see samples folder)

AjGenesis in Javascript was published to npm (node package manager) as beta.

AjGenesis in Ruby is still not a gem: work in progress.

REMEMBER: all these projects GENERATES the text artifacts YOU WANT to generate. There are not limited to a technology, platform or programming languages.

It’s really interesting to see how simple ideas can be reimplemented in dynamic languages. Next steps: more samples, ruby gem, node package, and web site implementing code generation as a service (ASP.NET implementation commented in my old post). (see AjGenesis: Basis of Its Implementation).

Pending implementation languages: Python, maybe Java.

(Original photo from: http://commons.wikimedia.org/wiki/File:Table_Rock_Dam_during_April_2008_White_River_Flood.jpg)

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

May 15, 2012

Metaprogramming: Links, news and resources (1)

Filed under: Java, JVM, Links, Metaprogramming, Programming Languages, Ruby, Smalltalk — ajlopez @ 1:33 pm

As a programming language fan and writer of many interpreters, I’m interested in metaprogramming. Some links I found useful:

http://en.wikipedia.org/wiki/Metaprogramming

Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data, or that do part of the work at compile time that would otherwise be done at runtime. In some cases, this allows programmers to minimize the number of lines of code to express a solution (hence reducing development time), or it gives programs greater flexibility to efficiently handle new situations without recompilation.

magarciaEPFL / MethodHandleUtils
https://github.com/magarciaEPFL/MethodHandleUtils
JVM: Composing MethodHandles at runtime like AST nodes
Runtime metaprogramming via java.lang.invoke.MethodHandle
http://lampwww.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/2012Q2/RuntimeMP.pdf

Ruby Metaprogramming: Declaratively Adding Methods to a Class
http://www.vitarara.org/cms/ruby_metaprogamming_declaratively_adding_methods_to_a_class

dlitvakb / MetaBuilder
https://github.com/dlitvakb/MetaBuilder
A Ruby MetaProgramming Excercise

Adding Properties to Ruby Metaprogramatically
http://www.infoq.com/articles/properties-metaprogramming

Ruby: More About Methods
http://ruby-doc.org/docs/ProgrammingRuby/html/tut_methods.html

Calling Methods Dynamically
http://www.linuxtopia.org/online_books/programming_books/ruby_tutorial/Reflection_ObjectSpace_and_Distributed__Ruby_Calling_Methods_Dynamically.html

Ruby dynamic method calling
http://khelll.com/blog/ruby/ruby-dynamic-method-calling/

celluloid / celluloid
Actor-based concurrent object framework for Ruby

MetaProgramming – Extending Ruby for Fun and Profit
http://www.infoq.com/presentations/metaprogramming-ruby

Three implicit contexts in Ruby
http://yugui.jp/articles/846
Yehuda Katz wrote an article about self and metaclass. In the article he said that Person.instance_eval assigns Person’s metaclass to self for a class Person. But this is obviously wrong.
Ruby always has three implicit contexts: self), so called `klass’ and the constant definition point.

Metaprogramming in Ruby: It’s All About the Self
http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/

class << self idiom in Ruby
http://stackoverflow.com/questions/2505067/class-self-idiom-in-ruby

ClassInstanceVariable
http://martinfowler.com/bliki/ClassInstanceVariable.html

Default Ruby accessor method?
http://stackoverflow.com/questions/636277/default-ruby-accessor-method
method_missing; it gets called whenever an undefined method is used

A Logic Meta-Programming Approach
to Support the Co-Evolution of
Object-Oriented Design and Implementation
http://scg.unibe.ch/archive/phd/Wuyts-phd.pdf

Meta-level Programming with CodA
http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.108.6885

C#5 and Meta-Programming
http://codebetter.com/patricksmacchia/2010/05/31/c-5-and-meta-programming/

Metaprogramming in .NET
http://www.manning.com/hazzard/

Whole Platform
http://whole.sourceforge.net/
the Whole Platform provides an Eclipse-based Language Workbench for developing new languages, manipulating them using domain notations and transforming them using a generative model driven approach.

Code Generation on the JVM: Writing Code that Writes Code
http://www.infoq.com/presentations/Code-Generation-on-the-JVM

Rascal – Meta Programming Language
http://www.rascal-mpl.org/
Rascal is a domain specific language for source code analysis and manipulation a.k.a. meta-programming.

Write A Template Compiler For Erlang
http://evanmiller.org/write-a-template-compiler-for-erlang.html
Implementing the Django Template Language in Erlang

Groovy: Best Practices Developed From Distributed Polyglot Programming
http://www.infoq.com/presentations/Groovy-Best-Practices

The Magnificent Seven
http://fogus.me/static/preso/magnificent7/#slide1
creating a Lisp variant in seven forms

The calculator language tutorial
http://www.jetbrains.com/mps/docs/tutorial.html

The art of metaprogramming, Part 1: Introduction to metaprogramming
http://www.ibm.com/developerworks/linux/library/l-metaprog1/index.html
One of the most under-used programming techniques is writing programs that generate programs or program parts. Learn why metaprogramming is necessary and look at some of the components of metaprogramming (textual macro languages, specialized code generators). See how to build a code generator and get a closer look at language-sensitive macro programming in Scheme.

Through the Looking Glass Darkly
http://gbracha.blogspot.com.ar/2010/03/through-looking-glass-darkly.html
The classic approach to reflection in object-oriented programming languages originates with Smalltalk, and is used in most class based languages that support reflection: define a reflective API on Objec
nother approach is used in many scripting languages. The language constructs themselves introduce code on the fly, modifying the program as they are executed.
The third approach is that of mirrors, and originates in Self. Mirrors have been used in class based systems such as Strongtalk, and even in the Java world. JDI, the Java Debugger Interface, is a mirror based reflective API. Here, the reflective operations are separated into distinct objects called mirrors.

Mirrors: Design Principles for Meta-level Facilities of Object-Oriented Programming Languages
http://www.bracha.org/mirrors.pdf

Metaprogramming: Ruby vs. Javascript
http://fingernailsinoatmeal.com/post/292301859/metaprogramming-ruby-vs-javascript

Metaprogramming in Ruby
http://ruby-metaprogramming.rubylearning.com/

A Basic YAML Config Module For Ruby
http://lostechies.com/derickbailey/2009/10/05/a-basic-yaml-config-module-for-ruby/

Categories, the homemade object system
http://lambda-the-ultimate.org/node/3569

Categories
http://mikelevins.livejournal.com/3678.html

Why? Language Archaeology … and Metaprogramming
http://www.artima.com/weblogs/viewpost.jsp?thread=260578

Metaclasses Demystified
http://cleverdevil.org/computing/78/
The word “metaclass” often strikes fear into the hearts of Python programmers. This article explores metaclasses in an approachable way, in order to take the mystery out of metaclasses, and enable you to leverage metaprogramming techniques to solve real problems.

Dupping Our Way Out of Instance Eval
http://banisterfiend.wordpress.com/2008/12/19/dupping-our-way-out-of-instance-eval/

Ruby.rewrite(Ruby)
http://www.infoq.com/presentations/braithwaite-rewrite-ruby
In this RubyFringe talk, Reginald Braithwaite shows how to write Ruby that reads, writes, and rewrites Ruby. The demos include extending the Ruby language with conditional expressions, new forms of evaluation such as call-by-name and call-by-need, and more.

Smalltalk magritte-metamodel
http://code.google.com/p/magritte-metamodel/
Magritte is a fully dynamic meta-description framework that helps to solve those problems, while keeping the full power to the programmer in all aspects.

My Links
http://delicious.com/ajlopez/metaprogramming

More links about DLSs, programming languages, and metaprogramming are coming.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

April 21, 2012

Ruby: Links, News And Resources (5)

Filed under: Links, Programming Languages, Ruby — ajlopez @ 5:22 pm

Previous Post

More links about this programming language:

Some Thoughts on (Ruby) Classes After 18 Months of Clojure on Vimeo
http://vimeo.com/34522837

InfoQ: RESTfulie – A Gem To Create Hypermedia Aware Services And Clients
http://www.infoq.com/news/2009/11/restfulie-hypermedia-services
Guilherme Silveira writes to InfoQ on the release of a ruby gem that makes developing hypermedia aware services and clients that consume them a breeze. He saidMuch has been spoken about what is and what are the advantages of using rest/restful ideas in one’s application. Last year, Mark Baker wrote …

Learn Ruby with the EdgeCase Ruby Koans
http://rubykoans.com/
These instructions are for *nix platforms. We also have Windows instructions .You can run the tests by calling the path_to_enlightenment.rb file.In your terminal, while in the ruby_koans directory, type:In test-driven development (TDD) the mantra has always been red: write a failing test and run …

Emanuel Goette, alias Crespo: El maldito libro de los descarrilados
http://emanuelpeg.blogspot.com/2011/02/el-maldito-libro-de-los-descarrilados.html
tutorial de Ruby on Rails en castellano.

Using Redis with Ruby on Rails
http://jimneath.org/2011/03/24/using-redis-with-ruby-on-rails.html
Redis is an extremely fast, atomic key-value store. It allows the storage of strings, sets, sorted sets, lists and hashes. Redis keeps all the data in RAM, much like Memcached but unlike Memcached, Redis periodically writes to disk, giving it persistence.Redis is an open source, advanced key-value …

To Redis or Not To Redis? (Key-Value Stores Part 4) | Engine Yard Blog
http://www.engineyard.com/blog/2009/key-value-stores-for-ruby-part-4-to-redis-or-not-to-redis/
Welcome to another post in our key value series! This week, Redis! Redis is a persistent in-memory key-value store written in C by Salvatore Sanfilippo. It’s currently in version 1.0. So let’s get down to it, “To Redis or Not to Redis?” that’s the question…So, let’s say you have a situation …

Delivering email with Amazon SES in a Rails 3 app — giant robots smashing into o…
http://robots.thoughtbot.com/post/3105121049/delivering-email-with-amazon-ses-in-a-rails-3-app
We’ve been using and loving Sendgrid on all our apps. However, Amazon SES came out last week and… you know… shiny.Right now, price. At our current email rates, we would save more than $10,000 in 2011 using Amazon SES over Sendgrid for Hoptoad.However, Sendgrid’s a reliable entity with more features …

colszowka/simplecov – GitHub
https://github.com/colszowka/simplecov
SimpleCov is a code coverage analysis tool for Ruby 1.9. It uses 1.9′s built-in Coverage library to gather code coverage data, but makes processing its results much easier by providing a clean API to filter, group, merge, format and display those results, thus giving you a complete code coverage

Getting Input: Ruby Study Notes – Best Ruby Guide, Ruby Tutorial
http://rubylearning.com/satishtalim/getting_input.html
So far we had seen a method like puts that writes to the screen. How does one accept user input? For this gets (get a string) and chomp are useful. The example p005methods.rb below illustrates the same.# p005methods.rb # gets and chomp puts "In which city do you stay?" STDOUT.flush city =

cspmoreno’s Channel – YouTube
http://www.youtube.com/cspmoreno
Canal dedicado a la programación orientada a objetos con el lenguaje Ruby on Rails con el IDE Netbeans. Explicación de como programar hasta llegar a construir nuestra propia red social

The JRuby Blog : Getting Started with JRuby and Java 7
http://blog.jruby.org/2011/12/getting_started_with_jruby_and_java_7/
Unless you’ve been living under a rock, you’ve probably heard about the new hotness for JRuby: Java 7’s support for dynamic languages. You may also have heard about the huge perf gains that JRuby’s seeing when running on Java 7. How can you try it yourself?The reference implementation for Java is …

Go Fetch | Virtuous Code
http://avdi.org/devblog/2009/03/16/go-fetch/
I’m a fan of the method in Ruby. I’ve noticed that other Rubyists don’t use it as much as I do, so I thought I’d write a little bit about why I like it so much.First of all, in case you’ve forgotten, is a method implemented on both and , as well as some other Hash-like classes (like the built-in …

Null Objects and Falsiness | Virtuous Code
http://avdi.org/devblog/2011/05/30/null-objects-and-falsiness/
Very often in Ruby code, we would like to execute some action only if an object is present:Strictly speaking, we aren’t checking for object presence here. In Ruby there is almost always an object present, but the default marker for missing data is the special object—the one and only instance of …

Concurrency in JRuby | Engine Yard Blog
http://www.engineyard.com/blog/2011/concurrency-in-jruby/
This is a recap of my talk on the same subject at EventMachine RubyConf in Baltimore on the final day of RailsConf 2011.Concurrency is a hotly debated subject in the Ruby community. Shared state or shared nothing? Threads or Events? Sync or Async? The fact that the standard Ruby interpreter does …

InfoQ: Adding Properties to Ruby Metaprogramatically
http://www.infoq.com/articles/properties-metaprogramming
Properties… the next frontier. Well, at least if you can’t stop yourself from watching the Java blog space, which is abuzz with discussions about this topic. Are Properties the next feature to save the world, give us that so desperately needed silver bullet, and finally make Java developers feel …

Programming Ruby: The Pragmatic Programmer’s Guide
http://ruby-doc.org/docs/ProgrammingRuby/html/tut_methods.html

Ruby Programming – Calling Methods Dynamically
http://www.linuxtopia.org/online_books/programming_books/ruby_tutorial/Refl...
C and Java programmers often find themselves writing some kind of dispatch table: functions which are invoked based on a command. Think of a typical C idiom where you have to translate a string to a function pointer: In Ruby, you can do all this in one line. Stick all your command functions into a …

Ruby dynamic method calling | Khaled alHabache’s official blog
http://www.khelll.com/blog/ruby/ruby-dynamic-method-calling/
I’m pretty sure that you have heard lots about ruby, specially as being a dynamic language, you can create methods on the fly, add instance variables, define constants and invoke existing methods dynamically , and that’s what this post is all about :As you know in ruby you can call a public …

Ruby Modules and Mixins
http://www.tutorialspoint.com/ruby/ruby_modules.htm
Modules are a way of grouping together methods, classes, and constants. Modules give you two major benefits.Modules define a namespace, a sandbox in which your methods and constants can play without having to worry about being stepped on by other methods and constants.Module constants are named …

Implementing Namespaces in Ruby using Nested Modules
http://pietschsoft.com/post/2008/11/02/Implementing-Namespaces-in-Ruby-usin...
Recently, I finally got around to starting to learn Ruby. I am finding it to be rather pleasant to program in. Now, one thing that I am used to using with an Object Oriented language (especially with my .NET background) are Namespaces. The only problem is that you can’t just declare a namespace in …

Include vs Extend in Ruby // RailsTips by John Nunemaker
http://railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/
Now that we know the difference between an instance method and a class method, let’s cover the difference between include and extend in regards to modules. Include is for adding methods to an instance of a class and extend is for adding class methods. Let’s take a look at a small example.As you can …

Ruby Mixin Tutorial
http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/
In Java you just have classes (both abstract and concrete) and interfaces. The Ruby language provides classes, modules, and a mix of both. In this post I want to dive into mixins in Ruby.In the Ruby language a mixin is a class that is mixed with a module. In other words the implementation of the …

My Links
http://delicious.com/ajlopez/ruby

More links about Ruby, mruby, ruby VMs are coming.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

March 28, 2012

Ruby: Links, news and Resources (4)

Filed under: Links, Programming Languages, Ruby — ajlopez @ 4:16 pm

Previous Post
Next Post

More links about Ruby Programming:

tarcieri / celluloid
https://github.com/celluloid/celluloid
Actor-based concurrent framework for Ruby

Programming Ruby 1.9 (3rd edition): The Pragmatic Programmers’ Guide
http://pragprog.com/book/ruby3/programming-ruby-1-9

Learn to Program
http://pine.fm/LearnToProgram/
A Place to Start for the Future Programmer

NoSQL OODB with Smalltalk-based Ruby VM: MagLev 1.0 Released
http://www.infoq.com/news/2011/11/ruby-maglev-10

MetaWhere & MetaSearch
http://railscasts.com/episodes/251-metawhere-metasearch
MetaWhere provides a way to do complex find conditions without SQL in Active Record. MetaSearch makes it easy to create search forms with many find options.

jeremyevans / sequel
https://github.com/jeremyevans/sequel

Sequel: The Database Toolkit for Ruby
http://sequel.rubyforge.org

Monkeypatching For Humans
http://www.codinghorror.com/blog/2008/07/monkeypatching-for-humans.html
…In those languages, you could redefine everything in the String class if you wanted to. This is commonly known in dynamic language circles as monkeypatching.

Como instalar Ruby en Ubuntu Linux
https://github.com/rubyperu/rubyperu.github.com/wiki/Instalacion-en-linux

Como instalar Ruby en Mac OS X
https://github.com/rubyperu/rubyperu.github.com/wiki/Instalacion-en-mac

Ruby performance showdown
http://nebulab.it/en/nebulog/ruby-performance-showdown

rchatley / extreme_startup
https://github.com/rchatley/extreme_startup
This software supports a workshop where teams can compete to build a software product that satisfies market demand.

eventmachine / eventmachine
https://github.com/eventmachine/eventmachine

EventMachine: fast, simple event-processing library for Ruby programs
http://www.rubyeventmachine.com

Musings On Software Community
http://haacked.com/archive/2011/11/25/musings-on-software-community.aspx
While attending Oredev 2011, I had an interesting conversation with Corey Haines about his perception of the Ruby community as compared to the .NET community.

Enums in Ruby
http://stackoverflow.com/questions/75759/enums-in-ruby

Ruby clouds: Engine Yard vs. Heroku
http://www.computerworld.com/s/article/9222258/Ruby_clouds_Engine_Yard_vs._Heroku

RubyConf Argentina and Fenix
http://blog.mmediasys.com/2011/11/26/rubyconf-argentina-and-fenix/
My talk was titled Tirando Ruby por la Ventana, which translates to Throwing Ruby through the Window
The talk was aimed at highlight a few issues with Ruby on Windows, ranging from the community to the implementation.
by @luislavena

My Links
http://delicious.com/ajlopez/ruby

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

March 1, 2012

Ruby: Links, News And Resources (3)

Filed under: Links, Programming Languages, Ruby — ajlopez @ 10:09 pm

Previous Post
Next Post

More Ruby links:

ricardochimal / taps
https://github.com/ricardochimal/taps
simple database import/export app

Padrino
http://www.padrinorb.com/
The Elegant Ruby Web Framework

MetaProgramming – Extending Ruby for Fun and Profit
http://www.infoq.com/presentations/metaprogramming-ruby

Three implicit contexts in Ruby
http://yugui.jp/articles/846

Metaprogramming in Ruby: It’s All About the Self
http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/

class << self idiom in Ruby
http://stackoverflow.com/questions/2505067/class-self-idiom-in-ruby

ClassInstanceVariable
http://martinfowler.com/bliki/ClassInstanceVariable.html

Ruby Programming/Syntax/Classes
http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes

Private class (not class method) in a Ruby module?
http://stackoverflow.com/questions/3496291/private-class-not-class-method-in-a-ruby-module

How can I initialize a module’s instance variables in Ruby?
http://stackoverflow.com/questions/698300/how-can-i-initialize-a-modules-instance-variables-in-ruby

Ruby …. un lenguaje con buena onda !
http://estebancarle.blogspot.com/2011/11/ruby-un-lenguaje-con-buena-onda.html

mojombo / tpw
https://github.com/mojombo/tpw
This is the data for my blog
It is automatically transformed by Jekyll into a static site whenever I push this repository to GitHub.

Is it possible to call from ruby to mono?
http://stackoverflow.com/questions/1932148/is-it-possible-to-call-from-ruby-to-mono

Can Ruby import a .NET dll?
http://stackoverflow.com/questions/265879/can-ruby-import-a-net-dll

Writing Ruby Extensions
http://www.slideshare.net/maraby/writing-ruby-extensions

How to create a Ruby extension in C in under 5 minutes
http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html

Writing Your Own Ruby Extension With C
http://www.rubyinside.com/writing-your-own-ruby-extension-with-c-366.html

Writing Ruby C extensions: Part 1
http://tenderlovemaking.com/2009/12/18/writing-ruby-c-extensions-part-1/

Extending Ruby
http://ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html

Programming Ruby
http://ruby-doc.org/docs/ProgrammingRuby/html/index.html

scanf for Ruby
http://rubydoc.info/stdlib/scanf/1.8.6/Scanf

brianmario / yajl-ruby
https://github.com/brianmario/yajl-ruby
A streaming JSON parsing and encoding library for Ruby (C bindings to yajl)

Lazy Streams for Ruby
http://chneukirchen.org/blog/archive/2005/05/lazy-streams-for-ruby.html

My Links

http://delicious.com/ajlopez/ruby

February 28, 2012

Ruby On Rails (2): Links, News and resources

Filed under: Links, Rails, Ruby, Ruby on Rails, Web Development — ajlopez @ 10:33 am

Previous Post

More links about this popular Ruby web framework (and some discussions):

Crazy, Heretical, and Awesome: The Way I Write Rails Apps
http://jamesgolick.com/2010/3/14/crazy-heretical-and-awesome-the-way-i-write-rails-apps.html

Rails Went Off The Rails: Why I’m Rebuilding Archaeopteryx In CoffeeScript
http://gilesbowkett.blogspot.in/2012/02/rails-went-off-rails-why-im-rebuilding.html

Frontend Code Doesn’t Have to Suck: 5 Tips for Rails Developers
http://starrhorne.com/2012/02/16/building-front-ends-that-dont-suck-five-tips-for-rails-developers.html

Moving from Sinatra to Rails
http://blog.steveklabnik.com/posts/2012-01-17-moving-from-sinatra-to-rails

ruby-debug in 30 seconds (we don’t need no stinkin’ GUI!)
http://pivotallabs.com/users/chad/blog/articles/366-ruby-debug-in-30-seconds-we-don-t-need-no-stinkin-gui-

What programming language is GitHub written in?
http://www.quora.com/What-programming-language-is-GitHub-written-in

Rails: Presenter Pattern
http://blog.jayfields.com/2007/03/rails-presenter-pattern.html

Ruby/Sinatra/Rails failing at Start
http://support.cloudfoundry.com/entries/515384-ruby-sinatra-rails-failing-at-start

Sinatra vs. Rails
http://stackoverflow.com/questions/3989438/sinatra-vs-rails

Rails Caching Benchmarked: MongoDB, Redis, Memcached
http://nosql.mypopescu.com/post/13493023635/rails-caching-benchmarked-mongodb-redis-memcached

r/CircleJerk
http://lostechies.com/ryanrauh/2012/01/04/circlejerk/
Lately there has been a lot posts about how Ruby on Rails might not follow the best practices.

ActiveRecord (and Rails) Considered Harmful
http://blog.steveklabnik.com/posts/2011-12-30-active-record-considered-harmful

Composition Of Responsibility vs Interface Implementation
http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/
ActiveRecord might truly be a horrible beast with far too many concerns in one given place. I haven’t dug into that source code very much. From what I remember of it, it’s huge and difficult for me to understand (but then, it does a metric-ton-squared of meta-programming, so I guess I’m not surprised that it’s hard for me to understand).

Rails Has Turned Me Into a Cannibalizing Idiot
http://wekeroad.com/2012/01/03/rails-has-turned-me-into-a-cannibalizing-idiot/
Some interesting posts flying around about how ActiveRecord is rotting people’s brains and how Rails is "pants on head retarded". I figured I might as well respond.

spree / spree
https://github.com/spree/spree
Spree is a complete open source e-commerce solution for Ruby on Rails
http://spreecommerce.com

Is it better to use routes or mod_rewrite to forward old URLs?
http://stackoverflow.com/questions/1876843/is-it-better-to-use-routes-or-mod-rewrite-to-forward-old-urls

How to make Rails do not ignore trailing slashes in the routes?
http://stackoverflow.com/questions/6486758/how-to-make-rails-do-not-ignore-trailing-slashes-in-the-routes

SEO, Heroku, Ruby on Rails and removing those darn trailing slashes
http://nanceskitchen.com/2010/05/19/seo-heroku-ruby-on-rails-and-removing-those-darn-trailing-slashes/

El maldito libro de los descarrilados
http://emanuelpeg.blogspot.com/2011/02/el-maldito-libro-de-los-descarrilados.html
Tutorial de Ruby on Rails en castellano

Using Redis with Ruby on Rails
http://jimneath.org/2011/03/24/using-redis-with-ruby-on-rails.html

To Redis or Not To Redis? (Key-Value Stores Part 4)
http://www.engineyard.com/blog/2009/key-value-stores-for-ruby-part-4-to-redis-or-not-to-redis/

Delivering email with Amazon SES in a Rails 3 app
http://robots.thoughtbot.com/post/3105121049/delivering-email-with-amazon-ses-in-a-rails-3-app

Activity Logs and Friend Feeds on Rails & pfeed
http://www.travisdunn.com/activity-logs-and-friend-feeds-on-rails-pfeed

Ruby On Rails español
http://www.youtube.com/cspmoreno

Entrenando con Ruby y RoR
http://recorriendootrosrumbos.blogspot.com/2011/12/entrenando-con-ruby-y-ror.html

Learning how to Learn Rails
http://rails.nuvvo.com/lesson/543-learning-how-to-learn-rails

nicksieger / refactoring-to-rails
https://github.com/nicksieger/refactoring-to-rails
Example of refactoring a Spring/Hibernate application to Rails

Configuration for Rails, the Right Way
http://blog.carbonfive.com/2011/11/23/configuration-for-rails-the-right-way/

Ruby clouds: Engine Yard vs. Heroku
http://www.computerworld.com/s/article/9222258/Ruby_clouds_Engine_Yard_vs._Heroku

Memcached Internals: Memory Allocation, Eviction Policy, Consistent Hashing
http://nosql.mypopescu.com/post/13506116892/memcached-internals-memory-allocation-eviction

Heroku and Rails 3.1
http://bostonrb.org/presentations/heroku-and-rails-31

Ruby on Rails 3.0 Release Notes
http://edgeguides.rubyonrails.org/3_0_release_notes.html

Instalar Ruby on Rails 3 en Windows
http://www.developeando.com/2010/12/instalar-ruby-on-rails-3-en-windows.html

Rails QRCode Generator
http://qrcode.heroku.com/

How do I add a field in Ruby on Rails?
http://stackoverflow.com/questions/1608751/how-do-i-add-a-field-in-ruby-on-rails

Why Bother With Cucumber Testing?
http://www.jackkinsella.ie/2011/09/26/why-bother-with-cucumber-testing.html

Mini reviews of 19 Ruby template engines
http://www.hokstad.com/mini-reviews-of-19-ruby-template-engines.html

Ruby on Rails Tutorial
http://ruby.railstutorial.org/chapters/beginning

Rails Searchable API Doc
http://railsapi.com/

Bundler
http://gembundler.com/
Bundler manages an application’s dependencies through its entire life across many machines systematically and repeatably.

Getting Started with Rails
http://guides.rubyonrails.org/getting_started.html

Updating Ruby / Rails
http://allaboutruby.wordpress.com/2009/08/30/updating-ruby-rails/

My Links
http://delicious.com/ajlopez/rubyonrails

More links about Ruby, Ruby web development, Sinatra, etc… are coming.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

February 7, 2012

Ruby on Rails, Demo Application (1) Creating the Application

Filed under: Ruby, Ruby on Rails, Web Development — ajlopez @ 11:25 am

I wrote a post series about my experience at the past Ruby Fun Day at Buenos Aires, in Spanish:

Mi Día en el Ruby Fun Day with @bendycode

Now, I want to write my learning steps following the chapter 2 of Michael Hartl book Ruby on Rails 3 Tutorial: Learn from Example.

I installed Ruby on my Windows box, using http://rubyinstaller.org/ (more options at http://www.ruby-lang.org/en/downloads/). In Windows, you should install DevKit (a minimalist GNU for windows (mingw)). See Ruby Installer page for link download. The instructions to install it are at http://github.com/oneclick/rubyinstaller/wiki/Development-Kit. (some details in Spanish).

Then, I executed the command (at any command prompt)

gem install rails

that installs Ruby on Rails, a web framework for Ruby. Go to a working directory (in my case c:\Git), and execute

rails

Output:

Then I executed

rails new RailsDemoApp

with output:

Change to the new directory:

cd RailsDemoApp

Now, you have a folder tree like:

Ruby manages gems (package to install and use). Rails itself is a gem. And Rails application have a GemFile that list the gems our new application will use. Just in case we have a new gem to install, execute:

bundle install

Bundle is the new package installer used in Ruby on Rails 3. It reads the GemFile and installs (in Ruby gem directory, in our machine, it’s not per application) the needed gems. Then, you can execute:

bundle show

I configured the current directory (Git\RailsDemoApp) to be a Git repo:

git init
git add .
git commit –m “Initial Commit”

I added a new repository in my GitHub Account using https://github.com/repositories/new:

The new repo: https://github.com/ajlopez/RailsDemoApp

I added and pushed to the remote repo:

git remote add origin git@github.com:ajlopez/RailsDemoApp.git
git push origin master

You can launch the initial server with

rails server

or its shortcut

rails s

See the result at http://localhost:3000

Next steps: adding a simple model (users, micropost), database, views, controllers, scaffolding, and Heroku deploy. Scaffolding (quick CRUD code generation) will be the approach to use in this series, but in a following post series I want to show (and learn ;-) the making of a Rails application, step by step, as in Hartl book.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

December 15, 2011

AjLisp in Ruby (2) Context with Name and Values

Previous Post

One of the first classes I implemented in AjLispRb is the environment. This time I called it a context: a dictionary where to save name/values, to store the atom values. The code:

module AjLisp
class Context
    def initialize(parent = nil)
        @parent = parent
        @values = Hash.new
    end
    
    def getValue(name)
        if @values.has_key?(name)
            return @values[name]
        end
        
        if @parent != nil
            return @parent.getValue(name)
        end
        
        return nil
    end
    
    def setValue(name, value)
        @values[name] = value
    end
end
end

The class was coded using TDD, the first tests at test/test_context.rb. Some tests:

def test_not_defined_is_nil
    context = AjLisp::Context.new
    assert_nil(context.getValue(:foo))
end
def test_set_and_get_value
    context = AjLisp::Context.new
    context.setValue(:foo, "bar")
    assert_equal("bar", context.getValue(:foo))
end
def test_get_value_from_parent
    parent = AjLisp::Context.new
    parent.setValue(:foo, "bar")
    context = AjLisp::Context.new(parent)
    assert_equal("bar", context.getValue(:foo))
end

Initially, I used strings for names, but now I'm using Ruby symbols like :foo. I have a test that ensures the independence of parent and child context values:

def test_override_value_from_parent
    parent = AjLisp::Context.new
    parent.setValue(:foo, "bar")
    context = AjLisp::Context.new(parent)
    context.setValue(:foo, "bar2")
    assert_equal("bar2", context.getValue(:foo))
    assert_equal("bar", parent.getValue(:foo))
end

Each context can have a parent. There is a top context, defined in lib/ajlisp.rb:

module AjLisp
@context = Context.new
@context.setValue :quote, FPrimitiveQuote.instance
@context.setValue :first, PrimitiveFirst.instance
@context.setValue :rest, PrimitiveRest.instance
@context.setValue :cons, PrimitiveCons.instance
@context.setValue :list, PrimitiveList.instance
@context.setValue :lambda, FPrimitiveLambda.instance
@context.setValue :flambda, FPrimitiveFLambda.instance
@context.setValue :mlambda, FPrimitiveMLambda.instance
@context.setValue :let, FPrimitiveLet.instance
@context.setValue :define, FPrimitiveDefine.instance
@context.setValue :do, FPrimitiveDo.instance
@context.setValue :if, FPrimitiveIf.instance
@context.setValue :definef, FPrimitiveDefinef.instance
@context.setValue :definem, FPrimitiveDefinem.instance
@context.setValue :+, PrimitiveAdd.instance
@context.setValue :-, PrimitiveSubtract.instance
@context.setValue :*, PrimitiveMultiply.instance
@context.setValue :/, PrimitiveDivide.instance
def self.context
    return @context
end
# ...
end

New context are created in many primitives. At the begin, there is a top context like:

If you have a defined form that returns the second element of a list:

(define second (a) (first (rest a)))

now you have a top context with the new slot:

The top context has a new slot named second with a lambda value (lambda (a) (first (rest a))

When you invoke:

(second (quote (one two three)))

during the invocation a new context is created, its parent set to the top context, and having a new name/value pair:

That context is discarded after second evaluation (unless the context were referenced by recently created closure, details in upcoming post). When you define a simple value:

(define one 1)

the top context is modified, to have a new name/value pair:

Next topics: primitives and special form primitives, their invocation, closures, macros, native methods invocation.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

December 2, 2011

AjLisp in Ruby (1) Structure, Classes and Tests

Filed under: AjLisp, Lisp, Programming Languages, Ruby, Test-Driven Development — ajlopez @ 10:57 am

Next Post

I’m learning and practicing Ruby writing my AjLisp interpreter, as usual (early this year, I ported it to Javascript). TDD is my friend: write a test, run in red, code, run in green, refactor, and so on. My code, work in progress, is at:

https://github.com/ajlopez/AjLispRb

Initially, I wrote a single file, following the great and simple example:

http://kanemar.com/2006/03/04/screencast-of-test-driven-development-with-ruby-part-1-a-simple-example/

Notice that Ruby has a ‘test/unit’ package, already in place, ready to use, after installation. After some research, I spitted the file in production code, and test code. I want to build a gem (Ruby package), so I studied the tutorial:

http://guides.rubygems.org/

I have pending readings:

http://speakerdeck.com/u/pat/p/cut-polish-a-guide-to-crafting-gems
http://blog.thepete.net/2010/11/creating-and-publishing-your-first-ruby.html

My code is not a gem, yet. But it have some gem structure:

The lib contains a single file:

require 'ajlisp/list.rb'
require 'ajlisp/named_atom.rb'
require 'ajlisp/context.rb'
require 'ajlisp/string_source.rb'
require 'ajlisp/token.rb'
require 'ajlisp/lexer.rb'
require 'ajlisp/parser.rb'
require 'ajlisp/primitive.rb'
require 'ajlisp/primitive_first.rb'
require 'ajlisp/primitive_rest.rb'
require 'ajlisp/primitive_cons.rb'
require 'ajlisp/primitive_list.rb'
require 'ajlisp/primitive_closure.rb'
require 'ajlisp/fprimitive.rb'
require 'ajlisp/fprimitive_quote.rb'
require 'ajlisp/fprimitive_lambda.rb'
require 'ajlisp/fprimitive_flambda.rb'
require 'ajlisp/fprimitive_let.rb'
require 'ajlisp/fprimitive_closure.rb'
require 'ajlisp/fprimitive_define.rb'
require 'ajlisp/primitive_add.rb'
module AjLisp
@context = Context.new
@context.setValue "quote", FPrimitiveQuote.instance
@context.setValue "first", PrimitiveFirst.instance
@context.setValue "rest", PrimitiveRest.instance
@context.setValue "cons", PrimitiveCons.instance
@context.setValue "list", PrimitiveList.instance
@context.setValue "lambda", FPrimitiveLambda.instance
@context.setValue "flambda", FPrimitiveFLambda.instance
@context.setValue "let", FPrimitiveLet.instance
@context.setValue "define", FPrimitiveDefine.instance
@context.setValue "+", PrimitiveAdd.instance
def self.context
    return @context
end
def self.evaluate(context, item)
    if item.is_a? List or item.is_a? NamedAtom
        return item.evaluate(context)
    end

    return item
end
end

I wrote some primitives (normal forms, and special forms: the latter don’t evaluate their parameters before apply, like quote or define). Notice that the additional files are in a subfolder ajlisp inside lib, why? Because when this code is installed as a gem, all lib file code could be include with require(‘thenameofrubyfile’). If I put other files than ajlisp.rb, i.e. list.rb or atom.rb, those file names could be required, and maybe a name collision with other gems could occur. Then, the recommended practice (see other gem code in your Ruby installation folder) is to put additional files below lib folder.

In the test folder there is a top test.rb file that includes other test files:

require 'ajlisp'
require 'test/unit'
require "test_list.rb"
require "test_named_atom.rb"
require "test_context.rb"
require "test_string_source.rb"
require "test_token.rb"
require "test_lexer.rb"
require "test_parser.rb"
require "test_primitive_first.rb"
require "test_primitive_rest.rb"
require "test_primitive_cons.rb"
require "test_primitive_list.rb"
require "test_primitive_closure.rb"
require "test_primitive_add.rb"
require "test_fprimitive_quote.rb"
require "test_fprimitive_lambda.rb"
require "test_fprimitive_let.rb"
require "test_fprimitive_closure.rb"
require "test_fprimitive_flambda.rb"
require "test_fprimitive_define.rb"
require "test_evaluate"

so you can run the tests from command line:

ruby –Ilib;test test\test.rb

If you have Windows, the runtest.cmd file contains this line.

Some test code:

require 'ajlisp'
require 'test/unit'
class TestList < Test::Unit::TestCase
#... 
    def test_create_with_first
        list = AjLisp::List.new("foo")
        assert_equal("foo", list.first)
        assert_nil(list.rest)
    end

    def test_create_with_first_and_rest
        rest = AjLisp::List.new("bar")
        list = AjLisp::List.new("foo", rest)
        assert_equal("foo", list.first)
        assert_not_nil(list.rest)
        assert_equal("bar", list.rest.first)
        assert_nil(list.rest.rest)
    end

    def test_create_from_array
        list = AjLisp::List.make [1, "a", "foo"]
        assert_not_nil list
        assert_equal 1, list.first
        assert_equal "a", list.rest.first
        assert_equal "foo", list.rest.rest.first
        assert_nil list.rest.rest.rest
    end
#..
end

Every list is an object of this class, list.rb:

module AjLisp
class List
    attr_reader :first
    attr_reader :rest

    def initialize(first=nil, rest=nil)
        @first = first
        @rest = rest
    end

    def evaluate(context)
        form = AjLisp::evaluate(context, @first)
        form.evaluate(context, self)
    end

    def self.make(array)
        if array and array.length > 0
            first = array.shift

            if first.is_a? Array
                first = make(first)
            elsif first.is_a? Symbol
                first = NamedAtom.new first.to_s
            end

            return List.new first, make(array)
        end 

        return nil
    end
end
end

The accessors first and rest are read-only. Thanks to the untyped nature of Ruby (like in Javascript) the implementation of this interpreter is straightforward, or without much code ceremony, at least.

In my new tests, I included the code into the AjLisp module, so I don’t need to write AjLisp:: prefix before referencing a class:

require 'ajlisp'
require 'test/unit'
module AjLisp
class TestLexer < Test::Unit::TestCase
    def test_get_atom_token
        source = StringSource.new "atom"
        lexer = Lexer.new source
        token = lexer.nextToken

        assert_not_nil token
        assert_equal "atom", token.value
        assert_equal TokenType::ATOM, token.type
        assert_nil lexer.nextToken
    end
    def test_get_atom_token_with_spaces
        source = StringSource.new " atom "
        lexer = Lexer.new source
        token = lexer.nextToken

        assert_not_nil token
        assert_equal "atom", token.value
        assert_equal TokenType::ATOM, token.type
        assert_nil lexer.nextToken
    end
#...
end

Next topics: some implementation details, primitives vs fprimitives, context (nested environments with name/values), lambda and closures, lexer and parser.

Next steps: complete primitives (let, letrec, definef, do, if…), macro (mlambda, definem, macro expansion…)

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

November 18, 2011

AjGenesis: Basis of its Implementation

Filed under: AjGenesis, Code Generation, Ruby — ajlopez @ 12:07 pm

I dedicated a lot of time to the development of AjGenesis, my open source code generation engine (from a free model). It’s time to write down what I consider the key points of its implementation, the parts that makes AjGenesis what it is.

First: the use of a free model on memory, that it’s managed like a common object in a programming language. You don’t need to traverse XML path or something else. You can visit and manipulated one or mode models  like any other dynamic object. I didn’t adopt a type model or a model with a schema: the model is free, you can put on each model what you want to have in it. The model is deserialized from XML or from text files, or it could be injected for your program: AjGenesis can be hosted as a library in your own application.

Second: the use of a dynamic, simple language, to execute simple or complex task, with access to rich class library. In AjGenesis, I use AjBasic, a interpreter that can access .NET. It can use, create and change dynamic objects, like the models.

Third: the use of templates, with expressions and commands (i.e. loops) written using the dynamic language.

(Some early alternatives were: use XML with schemas for models, and XSLT for transformations. I rejected them because I felt they had shortcomings that could affect the clear development of the system).

See:
Building an Application with AjGenesis
Code Generation with AjGenesis in a Real Project
Models for Code Generation in AjGenesis
AjBasic: An Open Source Basic-alike Interpreter
Generating Code Hello World with AjGenesis

Having these three pillars, I used AjGenesis for years, in different technologies, languages and framework (from Java to .NET, from JSP to ASP.NET to ASP.NET MVC, from PHP4 to PHP5 to .NET4 to .NET5, DDL for MySql, MS SQL Server database, and one user is generating code for Ruby and Rails!). Notably, I’m generating text artifacts for technologies that didn’t exist at the beginning of the project, with minimal changes to AjGenesis itself. And it can run in Linux and Mac OSX thanks to the Mono project (see Running AjGenesis Using Mono and Ubuntu).

Ideas to implement: the ability of inject the source of the model (you could write your own serializer); you could choose the dynamic language to use (I plan to add AjSharp as dynamic language for tasks and templates).

But if I have the three key points I enumerated above, I could implement AjGenesis. Then, as a proof of concept, I started to implement the same ideas under Ruby: dynamic objects, that can be loaded from YAML (or XML, or other formats), the use of ruby for task programming, and its template using ERB (or, maybe, other template engines).

You can check my progress at: https://github.com/ajlopez/AjGenesisRb

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

Older Posts »

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 28 other followers