Posts tagged with "ruby"


Install jekyll-import with --pre for now

Updating to the latest version of Jekyll, I got the following error when attempting to migrate a WXR file:

You must install the 'jekyll-import' gem before continuing.
* Do this by running `gem install jekyll-import`.
* Or if you need root privileges, run `sudo gem install jekyll-import`.

Sure enough, along with an entirely new site, Jekyll now uses importers instead of migrators, which reside in their own gem. Unfortunately, attempting to install this resulted in a new error.

ready % gem install jekyll-import
ERROR:  Could not find a valid gem 'jekyll-import' (>= 0) in any repository
ERROR:  Possible alternatives: jekyll-ebook, jekyll-epub, jekyll-reposter, module-import

It turns out that jekyll-import is still technically in beta, so needs to be installed thusly:

ready % gem install jekyll-import --pre

At the time of writing, this works in my bog standard RubyGems environment on Mac OS X 10.8.3, with the following dependencies and docs installed:

Fetching: fastercsv-1.5.5.gem (100%)
Fetching: nokogiri-1.5.9.gem (100%)
Building native extensions.  This could take a while...
Fetching: jekyll-import-0.1.0.beta1.gem (100%)
Successfully installed fastercsv-1.5.5
Successfully installed nokogiri-1.5.9
Successfully installed jekyll-import-0.1.0.beta1
3 gems installed
Installing ri documentation for fastercsv-1.5.5...
Installing ri documentation for nokogiri-1.5.9...
Installing ri documentation for jekyll-import-0.1.0.beta1...
Installing RDoc documentation for fastercsv-1.5.5...
Installing RDoc documentation for nokogiri-1.5.9...
Installing RDoc documentation for jekyll-import-0.1.0.beta1...

RVM: It's the little things

The Ruby Programming Language

If you make a habit of deploying Ruby code (^_^), I've found the RVM to be the easiest way to install the specific versions of Ruby and rubygems you need.

A lot of this is technical, but also because of this after installing. It's the little things.

Ruben Schade,

Thank you for using RVM!

I sincerely hope that RVM helps to make your life easier and more enjoyable!!!

~Wayne


Hacker News are such trolls

A letter from _why

In other news, the reason why their site looks crap on *nix is due to their use of Verdana in their CSS with no fallbacks, not even the standardised sans-serif identifier. Perhaps their web designer is a hipster, and knowing their target market did it ironically.


You're probably right, Matz

I think that it does not copy in the same process oldwave duh, because such a meaning wasn't. Was simply a misunderstanding?


Oniguruma for Ruby 1.8.x

The Ruby Programming Language

Want Ruby 1.9's default regular expression library in your existing Ruby 1.8.x series code?

# gem install -r oniguruma

According to the project's site, its mature. Wish I was.

s/Ruben is super witty/Ruben probably isn't/


Okay okay, I'll start using Ruby again!

With this huge move and all the unexpected problems we've had, I've had very little time these last couple of months to do much programming... or blogging! I can't wait, I'm posting this from my phone.

More history you don't care about

When I left high school in 2005, my first proper job was to write Perl scripts for possibly the friendliness boss I've ever had. He absolutely loved the language, and his enthusiasm rubbed off on me! I learned to LOVE CPAN and though I never did submit any of my own ACME modules I sure created lots of them! If I were learning the language today, I'd write one that just prints The Bird is The Word until the hapless user types Papa Ooom Maw Maw Maw. ACME::Trashmen, I can just see it now!

Anyway after that I started part one of my studies and was inundated with Java. I use the word inundated because it did feel like a flood! I could understand what was going on and appreciated how the language was in some ways self documenting, but the huge, narly long lines of camel case drove me batty. Features like linked lists and generics<T> seemed nice, but felt more like a tacked on after thought in an attempt to look more like C#, a language I did in high school when I was a .net guy and didn't really care for.

Then my mum really went south and programming took a back seat to amateur nursing. Then when she left I went through what I've retroactively dubbed The Ruben Troubles. But enough about that.

Yukihiro Matsumoto is really cute

Around that time while I was taking a break from university for aforementioned family reasons, I picked up the second edition of the pickaxe book and fell in love. Ruby was like Perl but was so schweet... to the point where I was thinking "this can't be healthy!" If you'd been reading my blog for a while you would have read that I came this close to implementing my site in Rails at the time.

I don't quite know why, but as if my brain is terrified of becoming specialised (and therefore successful) despite really liking Ruby I kept tinkering around with Python as well, and eventually grew to like it more. Despite the terrible design of my site here and the fact I like to ramble on continuously without not so much as one cohesive thought or succinct statement, I'm a huge fan of minimalism and Python is such a clean language. Not only that, it uses the white space for something! I mean, we all indent our code, it makes SO MUCH SENSE to USE it! Ruby still needs end statements or braces just like C and Basic, what's up with that!?

Oh yeah now I remember why I got into Python: Django. Django is one of the nicest frameworks I've ever used. We just clicked. I really tried to like Rails and did my fair share of work with it, but we didn't click. Despite what some mathematicians and computer scientists say, I think programming is a deeply personal thing, and sometimes things just click, and sometimes they don't. I've done equal amounts of work in Ruby and Python (and WAY MORE in Perl and Java, groan!) and it just makes more sense to me.

This heading is just as useless as the other two

Ruby has some very beautiful language constructs (the iteration block is so friggen elegant and nice I want to give it a huge hug), but an equivalent Python application will [often] be smaller, a boon for people like me who do most of their development hunched over a small ThinkPad at a coffee shop or an Apple computer that has a screen that sacrifices vertical space to make it wider.

Nonetheless, for its lucrative advertising potential (RUBEN DOES RUBY!) and to shut you all up (Ruben... why don't you do Ruby? Hey Ruben, do Ruby! Hey Ruben, Python isn't for you, Ruby is! Hey Ruben, your name is a total fit! Ruben, where did I leave my keys?) I've decided to give it another shot and submit my next assignment in it instead of Python. Who knows, it'd be great to do some RubyCocoa stuff :).

#!/usr/pkg/env ruby -w

class MugiChan
  def to_s
    return "Can Yui have this guitar cheaper?"
  end
end

if __FILE__ == $PROGRAM_NAME
  waifu = Mugichan.new
  puts waifu
end

Sent from my iPhone
(one of these days I'll get rid of this thing)


Main methods in Python, Ruby, Java stuff

Main Street

I've decided to put my code snippets blog idea on hold because I don't have time to be maintaining a separate blog right now. Had I started it, this would have gone there.

Not having main methods never used to worry me, but since studying Java again I really like being able to have an application kick into action without having to create an instance of it manually.

To illustrate what I mean, here's a crappy Java application that I merely have to execute from the command line for it to display Bender's favourite words.

MainInJava.java:
public class MainInJava
{
  public static void main(String[] args)
  {
    System.out.println("Kiss my shiny metal arse");
  }
}

Now here are roughly equivalent applications written in Ruby (my formerly favourite scripting language) and Python (my formerly favourite scripting language, and now my favourite scripting language again!):

MainInRuby.rb:
#!/usr/bin/env ruby -w

class MainInRuby
  def initialize()
    puts("Hello, world!")
  end
end

MainInPython.py:
#!/usr/bin/env python -3t

class MainInPython:
    def __main__(self):
        print("Hello, world!")

If you were to run either of these example applications, nothing would happen. The initialize and __main__ methods aren't run because merely running the application doesn't do any instantiation. Ruby and Python expect you to create and run an instance of the application in the source.

The proposed workarounds if you really want Java-ish main method equivalents in these languages are to write these lines of boilerplate outside the class.

MainInRuby.rb:
if __FILE__ == $PROGRAM_NAME
  # Put "main" code here
end

MainInPython.py:
if __name__ == "__main__":
    main()

I understand what these functions do, but for scripting languages that pride themselves on making life easier compared to heavy languages like Java, these don't seem all that intuitive or elegant.

I suppose one could argue that I've been corrupted into thinking I need a main method and that I haven't bothered to learn the Ruby or Python way of doing things. They may be onto something ^_^.

__EXIT__


Can't work Qt4-QtRuby on Snow Leopard

Yesterday I wrote a longwinded post about choosing Ruby/Tk or Java Swing to create a silly Monopoly clone for the family. Alex reminded me of Qt which is still just as easy as ever to install on Mac, but I still haven't got the Qt4-QtRuby bindings working because of a problem with Smoke.

First I got the latest complete Qt SDK from Nokia/Trolltech, then built cmake from MacPorts:

# port -v selfupdate
# port -v install cmake

Then downloaded a copy of Qt4-QtRuby and was able to get passed the cmake stage:

# tar xzvf qt4-qtruby-2.0.3.tgz
# cd qt4-qtruby-2.0.3
# cmake -DENABLE_QTWEBKIT_SMOKE=off \
-DENABLE_QTWEBKIT_RUBY=off .

But when I got to the make stage it reported an error in smokedata.cpp and proceeded to print a laundry list of errors.

Writing smokedata.cpp...
FATAL ERROR "com.trolltech.Qt.QGraphicsItem") inline void \
QGraphicsItem::setPos(qreal \
"com.trolltech.Qt.QGraphicsItem") \
inline void QGraphicsItem::setPos(qreal \
"com.trolltech.Qt.QGraphicsItem") \
inline void QGraphicsItem::setPos(qreal isn't a known type \
(type="com.trolltech.Qt.QGraphicsItem") inline void \
QGraphicsItem::setPos(qreal)

This was the reason why I was going to stick with Tk with Ruby because it comes bundled with the language and you don't need to go through all these hoops. Python works great with Qt though, so I might give that a shot instead. Or I'll just keep soldiering on with Swing.


Choosing between Ruby/Tk or Java Swing

Java Swing code

UPDATE: Alex has suggested I try Ruby with Qt. Genius!

My family has always had an obsession with the Monopoly board game, and since my mum died the remaining Schade clan has clung onto it even more as a family tradition. Because I have some spare time over the holidays I thought I'd create a computer version of Monopoly but with the place names and chance cards to do with places and experiences we've been to and had. Trouble is, I'm not sure what graphical toolkit and language to use!

The problem is we'll (hopefully) be taking this game to Europe, but our laptops have a smattering of different operating systems and configurations. My sister has a MacBook with Snow Leopard, I have a MacBook Pro with Snow Leopard and FreeBSD, and my dad is still forced to use Windows on his work laptop. Ideally I'd like to have my crappy little game being able to run on each.

Tickle Ruby with Tk or be the King of Java Swing?

Given I've been dabbling in Ruby again and have relearned the joys of Smalltalk like blocks, my first choice was to use Ruby with Tk because its fast to develop, seems to be relatively simple and comes with the default Ruby environment without installing anything extra, but I have far more experience with Swing in Java. As with everything in Java (and with me, ha!) its incredibly verbose to do even simple things, but its not terribly complicated unless you desperately want to do it the "correct" OOP way.

Judge me if you will, but for some reason I also really, really like the Metal Java Swing interface. Some people avoid it like the plague and allow their Swing applications to resemble the host operating system, but I reckon it looks classy.

Example Java Swing window with metal interface

I suppose I could come right out of left field and use JRuby with Swing, that way I have the familiar widgets and layout engines I'm [relatively] used to with a quicker to develop, RAD and Agile friendly language. Perhaps I'm getting a bit too ahead of myself though, would it be easier just to stick with Java on this one? Object serialisation (which I know how to do in Java but not Ruby) would make it great for saving and loading existing games too. Then again, perhaps I should force myself to branch into something new to learn something different.

Looks like I won't be deciding tonight!


Prevent [Ruby/]Tk window resizing

I had some trouble finding how to prevent Tk windows from being resized by users at runtime, so now that I've found out how I'm putting it here and passing it off as a legitimate post. Clever, right? :). Entirely pointless introductory paragraphs aside, simply set the resizable attribute of the TkRoot to (0, 0). Looks like a guy with a crooked nose.

For example, if you're a Rubyist using a beautiful block to create your new TkRoot window:

rootMain = TkRoot.new |main| do
  [..]
  resizable 0, 0
end

Or if you're doing it the more traditional way with hash parameters:

rootMain = tkRoot.new{ 'resizable' => '0, 0', [..] }

And because I used to be a Perl Guy and still use it for some stuff:

$rootMain->resizable(0, 0);

The next thing I need to find out is how to allow only horizontal resizing while vertical resizing is locked, and vica versa. Any ideas?