How to call Java from JRuby?

Calling Java
1
2
3
4
require 'java'
java_import my.package.CoolClass

obj1 = Java::CoolClass.new

Since I packaged my Ruby programs for the last time things changed a lot.

I’m going to refresh my knowledge and collect some useful links in the first step:

Suppose you have been working for a long time on a project, and now you want to delete some files from you project because … (the reason does not really matter at this point).

You may want to completely erase a file or a whole directory from your repository. The file or directory may be kept in the local copy or deleted as well.

If you want a complete removal use git rm:

Complete removal
1
2
3
4
$ git rm file_to_delete.rb
$ # file_to_delete.rb removed from both your working copy and repository tree.
$ git rm -r directory_to_delete
$ # directory_to removed from both your working copy and repository tree.

If you want to keep your local copy use git rm —cached.

Retaining local copy
1
2
3
4
$ git rm --cached file_to_delete.rb
$ # file_to_delete.rb removed only from repository tree.
$ git rm --cached -r directory_to_delete
$ # directory_to removed only from your repository tree.

In the latter case don’t forget to add the file or directory to your .gitignore file, otherwise Git will bother you with annoying status messages.

One last thing you should keep in mind is that erasing data from a repository means only that the information is not present in the actual commit and in all future incarnations of the code. The data can be restored from the previous states of your repository. If you want to wipe your sensitive data consider reading the appropriate GitHub Help page on this topic.

Capistrano is a tool for remote server automation and deployment. We have to underline these two task as they will remain two different areas for a long time. Historicaly Capistrano was a deployment tool, but since then many server administration tools have been created for remote server administration. Software installation, package upgrade, data base management can be arranged using Capistrano.

Capistrano supports the idea of deployment strategies. Strictly speaking they are the way, how the source code goes to the remote machine. We can distinguish between local and remote strategies.

Local strategies have only one member, the copy strategy. Remote strategies split into export, checkout and remote_cache variants.

If you have a static site or do not want to use a SCM for deployment look at the following code snippet:

A fragment from Capfile
1
2
3
4
5
6
7
8
set :repository,  "./source_dir" # This is our directory with the content to be deployed.
set :scm, :none # Do not use any SCM.

set :deploy_to, '/var/www/mysite/htdocs' # This is a place on the remote machine.
set :deploy_via, :copy # We are going to deploy using the copy strategy.

set :copy_dir, './tmp/capistrano' # Here we create a temporary archive with our content.
set :copy_remote_dir, "#{deploy_to}/tmp/capistrano" # There the archive will be copied.

You have to ensure that both local and remote directories for archives exist.

If you need some additional readings on Capistrano, try out the following:

Berkeley Parser is one the best open source syntactic parsers for today. It uses a sofisticated split-merge algorithm to learn a constituent grammar started with a simple x-bar grammar.

The parser itself and a grammar for one of provided languages here from its repository at Google code. For now pretrained grammars are offered for English, German, French, Bulgarian, Arabic and Chinese.

We’ve downloaded the parser archive and the English grammar. Let’s try to produce some meaningful output:

Berkeley Parser Invocation
1
2
$ echo "The horse raced past the barn fell ." | \
$ java -jar BerkeleyParser-1.7.jar -gr eng_sm6.gr

The resulted analysis is by far not ideal but it is a good beginning:

Garden path sentence

Anki is a great software piece dealing with Spaced Repetition.

The second generation of Anki offers a different view on cards, notes, facts and layouts. Compared to the first version of this program, one may be confused by alternating definitions. But after a short period everything gets clear and logical.

I learn German nouns with my custom note type GermanNoun. It exposes the following fields:

  • Wortform;
  • Artikel;
  • Aussprache;
  • Paradigma;
  • Bedeutung;
  • Beispiel.

The trick is to combine these field with the help of card layouts. Using only 6 fields (many of them can be ommited) we are going to generate a lot of useful card.

Here the examples of the front card side:

1
2
3
{{Wortform}}
<br>
{{#Beispiel}}{{Beispiel}}{{/Beispiel}}

The corresponding back side can be encoding as follows:

1
2
3
4
5
6
{{Artikel}} {{Wortform}}
<span style='color: red; font-size: 16px'>{{Paradigma}}</span>
<br>
{{#Aussprache}}{{Aussprache}}{{/Aussprache}}
<hr id=answer>
{{Bedeutung}}

You may want to experiment with colors and font properties. HMTL to rescue :)

There are a lot of good and excellent introductions and advanced books on algorithmic design. Many of them describe the topic in a language agnostic way, some others concentrate on a particular language (e.g. Java).

The following resource is an attempt to introduce beginners how to implement basic algorithms and data structures in Ruby.

If you are interested in a programmatic way to learn some aspects of Ruby, your might want to look at Ruby Koans.

It is an awesome ressource for beginners and intermediate rubyists.