Angel \”Java\” Lopez on Blog

October 26, 2013

TDD Rocks! (1) Playing with Ruby

Filed under: Google, Ruby, Test-Driven Development, Video — ajlopez @ 9:41 am

Next Post
Next Post with Ruby

Past July, I recorded a Google hangout, about on of my favorite topic: TDD (Test-Driven Development).

My first one:

TDD Rocks (1) Playing with Ruby
http://www.youtube.com/watch?v=L3SuNBDg2IM&feature=youtu.be

Well, I’m using Anglish, that is, Angel’s English ;-).

The idea is to show my TDD workflow, step by step, and in this video I’m using Ruby (I’m learning Ruby). In the second video I added more tests, like recognize numbers, words and symbols. I will apply internal refactoring, and a better implementation. I already applied that workflow in my public projects in Ruby:

AjLispRuby
https://github.com/ajlopez/AjLispRuby
My Lisp interpreter in Ruby, with access to gems

AjGenesisRuby
https://github.com/ajlopez/AjGenesisRuby
Code generation, like AjGenesis in .NET, but now using Ruby

In this video, I’m adding the minimal code to past the test. I don’t separate the class under development from the tests: they are in the same files. You can check project status:

https://github.com/ajlopez/TddRocks/blob/master/Ruby/tokenizer.rb

I will publish posts with more Google hangouts, with TDD using JavaScript, C#, and more Ruby.

Keep Tuned!

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

October 17, 2013

RubySharp, Implementing Ruby In C# (2)

Filed under: C Sharp, Open Source Projects, Programming Languages, Ruby, RubySharp — ajlopez @ 7:11 pm

Previous Post

I’m working on my Ruby implementation as interpreter written in C#

https://github.com/ajlopez/RubySharp

Today I would like to show that I have implemented many expressions that can be evaluated:

I have implemented commands, too. Initially they were separated:

But now, expressions and commands implement the same interface, to compy with Ruby moto “every is a value”

Evaluate method receives a Context:

I should review if I want or not that Context object has reference to self and other fields. But I wrote all with TDD, so, I could refactor it at any moment.

A code sample, NameExpression .Evaluate method:

public object Evaluate(Context context)
{
    var result = context.GetValue(this.name);

    if (result is IFunction)
        return ((IFunction)result).Apply(null, emptyvalues);

    return result;
}

Notice that I had to take into account the case: the name argument refers to a function. In Ruby, you can call a function simply using the name, the parenthesis are not mandatory.

Next steps: internal refactor, more commands and expressions.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

October 14, 2013

RubySharp, implementing Ruby in C# (1)

Filed under: C Sharp, Open Source Projects, Programming Languages, Ruby, RubySharp — ajlopez @ 12:02 pm

Next Post

Every day I write code and push it to my GitHub account. The purpose is training: practice programming, programming languages and TDD (don’t forget TDD!).

I’m working in RubySharp in my spare time:

https://github.com/ajlopez/RubySharp

It is a Ruby interpreter written in C# (like PythonSharp, see posts). There are two solutions, with and without tests, so you can compile the small solucion witn Visual Studio Express. The solucion with tests:

I have commands and expressions. But I learned that in Ruby every is an expression, so now expressions and commands implements the same interface. The programming language Mass derived from ideas in RubySharp.

My tests (now are more tests):

To give evidence about “put my money where my mouth is”, you can check my commits at:

https://github.com/ajlopez/RubySharp/commits/master

Next posts: implementation details, examples, scripting over .NET.

Keep tuned!

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

October 13, 2013

Exploring Ruby on Rails (1) Install

Filed under: Ruby, Ruby on Rails — ajlopez @ 1:39 pm

I’m playing with Ruby. As a dynamic language, it is one of the programming languages to explore. I like plain Ruby, and write small programs using TDD (see my video in Anglish Playing with Ruby).

Now, I want to explore Ruby on Rails. It’s not in my comfort zone, because I think it is a “big project”, now in version 4.0. But it could be interesting to see how easy or convoluted could be to program using Rails, and to study the internal implementation.

So, in my Windows machine, some weeks ago, I installed Rails 4.x, using

http://guides.rubyonrails.org/getting_started.html

Using:

gem install rails --no-rdoc --no-ri

I added –no-rdoc, –no-ri to skip the generation of local documentation.

It was a long output, see the gems that were installed:

Fetching: i18n-0.6.5.gem (100%)
Fetching: tzinfo-0.3.37.gem (100%)
Fetching: minitest-4.7.5.gem (100%)
Fetching: atomic-1.1.14.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Fetching: thread_safe-0.1.3.gem (100%)
Fetching: activesupport-4.0.0.gem (100%)
Fetching: builder-3.1.4.gem (100%)
Fetching: actionpack-4.0.0.gem (100%)
Fetching: activemodel-4.0.0.gem (100%)
Fetching: arel-4.0.0.gem (100%)
Fetching: activerecord-deprecated_finders-1.0.3.gem (100%)
Fetching: activerecord-4.0.0.gem (100%)
Fetching: mail-2.5.4.gem (100%)
Fetching: actionmailer-4.0.0.gem (100%)
Fetching: thor-0.18.1.gem (100%)
Fetching: railties-4.0.0.gem (100%)
Fetching: bundler-1.3.5.gem (100%)
Fetching: sprockets-2.10.0.gem (100%)
Fetching: sprockets-rails-2.0.0.gem (100%)
Fetching: rails-4.0.0.gem (100%)
Successfully installed i18n-0.6.5
Successfully installed tzinfo-0.3.37
Successfully installed minitest-4.7.5
Successfully installed atomic-1.1.14
Successfully installed thread_safe-0.1.3
Successfully installed activesupport-4.0.0
Successfully installed builder-3.1.4
Successfully installed actionpack-4.0.0
Successfully installed activemodel-4.0.0
Successfully installed arel-4.0.0
Successfully installed activerecord-deprecated_finders-1.0.3
Successfully installed activerecord-4.0.0
Successfully installed mail-2.5.4
Successfully installed actionmailer-4.0.0
Successfully installed thor-0.18.1
Successfully installed railties-4.0.0
Successfully installed bundler-1.3.5
Successfully installed sprockets-2.10.0
Successfully installed sprockets-rails-2.0.0
Successfully installed rails-4.0.0
20 gems installed

It is interesting to note there were native extensions, something to explore.

Now, the rails command is in my path. How the install program added the command? Simply. If you have Ruby in your path, you have the bin folder in that list of directories. In my case, c:\Ruby193\bin. Every gem that has global commands, can put in that folder new files. In my case, rails, and rails.bat.

This is the content of the .bat file:

@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"ruby.exe" "C:/Ruby193/bin/rails" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"ruby.exe" "%~dpn0" %*

It detects if it can use or not a ‘cmd trick’, see

http://www.robvanderwoude.com/ntfor.php

http://www.msfn.org/board/topic/122357-dpn0/

It launch the ‘rails’ file in the same bin directory, using ruby.exe. The rails file has:

#!C:/Ruby193/bin/ruby.exe
#
# This file was generated by RubyGems.
#
# The application 'railties' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
  version = $1
  ARGV.shift
end

gem 'railties', version
load Gem.bin_path('railties', 'rails', version)

It use rubygems, the Ruby packaging system, see:

http://rubygems.org/

It imports, not directly rails, but railties, using the gem method.

The Gem.bin_path returns the path for ‘railties’, see

http://apidock.com/ruby/Gem/bin_path/class

In my case, the bin-path returns ‘c:\Ruby193\lib\ruby\gems\1.9.1\railties-4.0.0\bin\rails’. The second parameter ‘rails’ indicates the script to run. It is executed using the ‘load’ command:

http://www.ruby-doc.org/core-2.0.0/Kernel.html#method-i-load

load(filename, wrap=false) ? true

Loads and executes the Ruby program in the file filename. If the filename does not resolve to an absolute path, the file is searched for in the library directories listed in $:. If the optional wrap parameter is true, the loaded script will be executed under an anonymous module, protecting the calling program’s global namespace. In no circumstance will any local variables in the loaded file be propagated to the loading environment.

I should study the difference with ‘require’:

http://www.ruby-doc.org/core-2.0.0/Kernel.html#method-i-require

require(name) ? true or false

Loads the given name, returning true if successful and false if the feature is already loaded.

If the filename does not resolve to an absolute path, it will be searched for in the directories listed in $LOAD_PATH ($:).

If the filename has the extension “.rb”, it is loaded as a source file; if the extension is “.so”, “.o”, or “.dll”, or the default shared library extension on the current platform, Ruby loads the shared library as a Ruby extension. Otherwise, Ruby tries adding “.rb”, “.so”, and so on to the name until found. If the file named cannot be found, a LoadError will be raised.

For Ruby extensions the filename given may use any shared library extension. For example, on Linux the socket extension is “socket.so” and require ‘socket.dll’ will load the socket extension.

The absolute path of the loaded file is added to $LOADED_FEATURES ($"). A file will not be loaded again if its path already appears in $". For example, require ‘a’; require ‘./a’ will not load a.rb again.

require "my-library.rb"

require "db-driver"

Any constants or globals within the loaded source file will be available in the calling program’s global namespace. However, local variables will not be propagated to the loading environment.

That ‘rails’ file contains:

#!/usr/bin/env ruby

git_path = File.join(File.expand_path('../../..', __FILE__), '.git')

if File.exists?(git_path)
  railties_path = File.expand_path('../../lib', __FILE__)
  $:.unshift(railties_path)
end
require "rails/cli"

Apparently, the gem loader alters the require path, and the require of ‘rails/cli’ is resolved to ‘c:\Ruby193\lib\ruby\gems\1.9.1\railties-4.0.0\lib\rails’.

Ok, enough for today. Next steps: explore the load of rails, parameters, and create a site.

Keep tuned!

Angel "Java" Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

September 3, 2013

New Month’s Resolutions: September 2013

My past month’s resolutions status:

- Update SimpleProlog [complete] see repo
- Update Mass [pending]
- Update AjTalkJs [complete] see repo
- Update AjTalk [complete] see repo
- Update SimpleLisp [pending]
- SimpleLisp web server sample [pending] 
- New Google Hangout using Ruby and TDD [complete] see post 
- New Google Hangout using C# and TDD [complete] see post

Additional items:

- Another Google Hangout using C# and TDD [complete] see post
- Google Hangout using JavaScript and TDD [complete] see post
- Google Hangout about Exploring MongoDB [complete] see post
- Google Hangout about Code generation with AjGenesis for Ruby [complete] see post
- Update AjGenesis for Ruby [complete] see repo
- Update AjGenesis for Node.js [complete] see repo
- New AjGenesisNode module for Entities [complete] see repo
- Start new AjGenesisNode module for Express [complete] see repo
- New SimpleUnit node module for testing [complete] see repo
- Start ScalaSharp, Scala-like interpreter in C# [complete] see repo
- Improve left recursion in GrammGen [complete] see repo
- Update SimpleMongo [complete] see repo
- Give a talk about code generation with AjGenesis for Ruby [complete] see talks

and many node modules refactoring, using SimpleUnit

This month’s resolutions:

- Update SimpleForth
- Give a talk about SimpleMongo, SharpMongo
- Update SimpleMongo
- Update SharpMongo
- Update PageJs
- Update ScalaSharp
- Update JPyScript
- Update AjTalkJs
- Update Mass scopes
- Start Web Server example with AjTalkJs
- Update AjTalk
- Update AjLispJs
- Web Server example with AjLispJs
- Prepare a talk about Scala

Keep tuned!

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

September 2, 2013

End Of Iteration 2013w35

Filed under: C Sharp, Code Generation, Express, Iteration, JavaScript, Open Source Projects, Ruby — ajlopez @ 9:41 am

Previous Post
Next Post

Many tasks in many projects. Some notes:

Google Hangouts

Code Generation with Ruby

using AjGenesis for Ruby

http://www.youtube.com/watch?v=y8DxmSgxKow

AjGenesis

I updated my implementation in Ruby

https://github.com/ajlopez/AjGenesisRuby

But more important, there is a new version of my implementation using JavaScript/Node.js, the 0.0.5 version

https://github.com/ajlopez/AjGenesisNode

with support for:

- Load models from .json file or from .json files in a directory
- Copy files, copy directories
- Invoke local tasks from local ajgenesis/tasks
- Invoke local modules:verb from local ajgenesis/modules

There are two new modules

https://github.com/ajlopez/AjGenesisNode-Entity published, version 0.0.1

to add entities and propertis inside ajgenesis/models

And a Work in progress module to generate Express sites:

https://github.com/ajlopez/AjGenesisNode-Express

SimpleUnit

I added test.async() and test.done() functions for asynchronous processing

https://github.com/ajlopez/SimpleUnit

New version 0.0.2 published

ScalaSharp

First steps in my Scala interpreter for C#, lexer, parser first tests:

https://github.com/ajlopez/ScalaSharp

Others

GrammGen, Improved left recursion, more tests https://github.com/ajlopez/GrammGen

SimpleProlog, parse “and” structure https://github.com/ajlopez/SimpleProlog

SimpleMongo, find with query and projection https://github.com/ajlopez/SimpleMongo

A new talk about Ruby code generation with AjGenesis https://github.com/ajlopez/Talks/tree/master/RubyCodeGeneration

Cuba hello sample, in Ruby Samples https://github.com/ajlopez/RubySamples

Published version 0.0.1 https://github.com/ajlopez/SimpleArgs argument processor, refactored to use SimpleUnit.

I worked on two non-public projects, one involving Node.js, JSON, Ajax, good experience to add to my personal projects.

Keep tuned!

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

August 21, 2013

End Of Iteration 2013w33

Previous  Post

This week was extended up to Monday August 19th, public holiday here, Argentina.

Google Hangouts

I recorded one Google Hangout, playing with Ruby and TDD (2):

TDD Rocks! (6) Playing with Ruby
http://www.youtube.com/watch?v=X-mTCyhm7ds

 

SimpleUnit

This is an interesting code kata, written on Sunday late morning. I wrote my Node.js modules using TDD. I do it calling builting module assert, or using node-unit. But sometimes, node-unit is GREATER than the module I want to write. So, I wrote my simple implementation, and published it in NPM as version 0.0.1:

https://github.com/ajlopez/SimpleUnit

I refactored my tests in projects:

https://github.com/ajlopez/SimpleProlog
https://github.com/ajlopez/SimpleForth
https://github.com/ajlopez/Particulares
https://github.com/ajlopez/AjTalkJs

to start using simpleunit. Next steps: add asynchronous processing. The first candidate to use it is SimpleProlog: solve facts using callbacks.

AjTalkJs

My implementation of Smalltalk VM in JavaScript.

https://github.com/ajlopez/AjTalkJs

I have an implementation in C#

https://github.com/ajlopez/AjTalk

that compiles .st files to JavaScript. But now, I want to compile .st to JavaScript using JavaScript itself. So I added the first tests and implementations of lexer and parser to AjTalkJs. I hope I will present the result at Smalltalks 2013.

SimpleProlog

My implementation of Prolog language, in progress.

https://github.com/ajlopez/SimpleProlog

It started to have a lexer.

SharpContext

My C# implementation of SimpleContext ideas:

https://github.com/ajlopez/SharpContext

Now it has a new object, DynamicContext. I should add the inheritance use cases. Notice that C# version has more ceremony than the JavaScript one.

SharpMongo

My implementation of MongoDB in memory, using C#, in progress:

https://github.com/ajlopez/SharpMongo

Minor refactor/redesign to support read-only documents. Now it has dynamic objects, too. Dynamic documents are dynamic objects with an Id.

I also worked on two non-public projects. More fun is coming!

Keep tuned!

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

August 4, 2013

New Month’s Resolutions: August 2013

Time to review my July’s resolutions:

- Update Memolap [complete] see repo
- Update GrammGen [complete] see repo
- Update SimpleGrammar [complete] see repo
- Prepare a talk: Intro to Smalltalk [complete] see talk
- Start PHP compiler to JavaScript [complete] see repo
- Write PHP example with Node.js [pending]
- Update AjLispJs [[pending]
- Create a web site sample using AjLisp and Node.js [pending]

Instead of updating AjLispJs, I started another project:

- Start SimpleLisp, Lisp compiler to JavaScript [complete] see repo

Additionally, I worked on:

- Start SimpleContext, associate arbitrary data to simple JavaScript objects [complete] see repo
- Start SimpleProlog, Prolog language interpreter in JavaScript/Node.js [complete] see repo
- First version of KodeTokenizer [complete] see repo
- First version of KodeMutator [complete] see repo
- Publish Obops on Nuget [complete] see repo
- Publish my first Smalltalk samples [complete] see repo
- Create and pubish first version of Plagre, programming language recognizer [complete] see repo see demo
- Updated my TDD Rocks samples [complete] see repo
- Start SharpBase C# in-memory database [complete] see repo
- Start AjForce, applications in Node.js a la Force.com [complete] see repo
- Start OStore, in-memory JavaScript object store [complete] see repo
- Added Rack samples to my Learning Ruby [complete] see repo
- Write SimpleMule, simple Mule-like in JavaScript/Node.js [complete] see repo

Also, I published Google hangouts:

- TDD Rocks (1) Playing with Ruby
- TDD Rocks! (2) OStore with JavaScript/Node.js
- Exploring Smalltalk (1) (Spanish)
- TDD Rocks! (3) SharpBase in C#
- TDD Rocks! (4) SharpBase in C#

My new month’s resolutions, August 2013:

- Update SimpleProlog
- Update Mass
- Update AjTalkJs
- Update AjTalk
- Update SimpleLisp
- SimpleLisp web server sample
- New Google Hangout using Ruby and TDD
- New Google Hangout using C# and TDD

Lot of fun is coming ;-)

Keep tuned!

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

July 22, 2013

End Of Iteration 2013w29

Previous Post
Next Post

Many ideas and implementations! Summary:

SharpBase

I started to write a simple in-memory database in C#, using TDD

https://github.com/ajlopez/SharpBase

I recorded and published a Google Hangout, documenting my TDD process (in Anglish, Angel’s English ;-)

TDD Rocks! (3) SharpBase in C#
http://www.youtube.com/watch?v=N7zCTVZiWfo&feature=youtu.be

TDD Rocks

https://github.com/ajlopez/TddRocks

I renamed this project (previous name: TddOnTheRocks). I updated Energy problem for an Spanish post:

https://github.com/ajlopez/TddRocks/tree/master/Energy
http://msmvps.com/blogs/lopez/archive/2013/07/21/tdd-kata-7-manejando-su-energ-237-a.aspx

I implemented a new problem/algorithm

https://github.com/ajlopez/TddRocks/tree/master/MatrixSet

Given a boolean matrix, it returns a list of the greatest sets of cells having true value, that comply with the problem criteria. If a cell X, Y is in the set, for all the other cells X2, Y2, the cells X, Y2 and X2, Y are in the set, too.

AjForce

I started to write an open source Force.com-alike in JavaScript/Node.js

https://github.com/ajlopez/AjForce

OStore

In order to practice TDD with JavaScript, I started to write an in-memory simple JavaScript object store in memory:

https://github.com/ajlopez/OStore

I recorded my initial TDD process as a Google Hangout:

TDD Rocks! (2) OStore with JavaScript/Node.js
http://www.youtube.com/watch?v=Uica74QlfxQ&feature=youtu.be

Plangre

I improved my programming language recognizer, written in JavaScript:

https://github.com/ajlopez/PLangRe

I managed to have a Node.js and a browser versions. The browser versions is running at:

http://ajlopez.github.io/PLangRe/

Smalltalk

I’m preparing a talk about Intro to Smalltalk. I recorded a Google Hangout. It includes my first steps with Pharo 2.0. In Spanish

Explorando Smalltalk (1)
http://www.youtube.com/watch?v=mcvYXz2nZts&feature=youtu.be

Ruby and TDD

I recorded a Google Hangout, in Anglish, with a simple example written using Ruby 2.0 and TDD:

TDD Rocks (1) Playing with Ruby
http://www.youtube.com/watch?v=L3SuNBDg2IM&feature=youtu.be

I worked on two private projects.

Keep tuned!

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

July 5, 2013

New Month’s Resolutions: July 2013

Review of my June’s resolutions:

- Update Mass [complete] repo
- Update RubySharp [complete] repo
- Update PythonSharp [complete] repo
- Update ClojSharp [complete] repo
- Update AjSharp [pending]
- AjGenesis Node.js examples [pending]
- Update Learning Ruby [pending]
- Update Learning Python [complete] repo
- Write a Node.js/Express/MongoDb sample [complete] repo
- New posts about RubySharp [pending]
- New posts about TDD [complete] post post
- New posts about Mass [pending]

Also, I give a talk about Intro to Python see repo. And:

- Start a Forth compiler to JavaScript [complete] repo
- Start a generic parser in C# [complete] repo
- Start a generic parser in JavaScript [complete] repo
- Start AjLisp in Python [complete] repo
- Start task runner in C# [complete] repo
- Update AjLisp in JavaScritp [complete] repo
- Update ObOps [complete] repo
- Start Learning Java [complete] repo
- Update AjErl [complete] repo
- Update AjGenesisNode [complete] repo
- Update RunIt [complete] repo
- Post about ObObjs [complete] post

July resolutions:

- Update Memolap
- Update GrammGen
- Update SimpleGrammar
- Prepare a talk: Intro to Smalltalk
- Start PHP compiler to JavaScript
- Write PHP example with Node.js
- Update AjLispJs
- Create a web site sample using AjLisp and Node.js

Keep tuned!

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

« Newer PostsOlder Posts »

The Shocking Blue Green Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 56 other followers