Archive for the 'ruby' Category

03
Jul

svnbackup-restore.rb, svnbackup’s handy companion tool

Doug Hellman’s svnbackup script tool is a really handy tool for setting up automated backups for a subversion repository.

However, the non-fun time comes when one wants to restore a subversion repository that has way too many dumpfiles parts. The instructions for restoration are basically ‘roll your own’ if you want to try to automate the restore procedure. What would be nicer is if there was the converse tool that made it easier to not have to figure out how to re-order the backup files in the proper manner in order to perform the restore.

I spent a few minutes thinking about it and wrote a small Ruby script to help with this that I call svnbackup-restore.rb. Here is the (hastily written) source code. (Download here)

#!/usr/bin/ruby
# Program Name: Restore the restore
# Purpose:      Take all the svn dumpfiles generated from svnbackup
#               sort them and try loading them via svnadmin
# Usage:        1. Create the new repo path with svnadmin create
#               2. Set repo_name to the repo backup file names
#               3. Set restore_path to the new path to restore to
#               4. Run it ./svnbackup-restore.rb
# Assumptions:  svnrestore-backup.rb is in the same dir as the svn dump files

# CHANGE PARAMETERS HERE
repo_name = 'myrepo'
restore_path = '/path/to/myrepo'

# Print out debugging?
DEBUG = true

# DON'T CHANGE BELOW

# Filename format is 'dumpfile---.bzip2'
svn_dumpfiles = Dir["dumpfile-#{repo_name}*.bzip2"]
sorted_files = svn_dumpfiles.sort do |a, b|
  left_rev = a.split(’-')[2].to_i
  right_rev = b.split(’-')[2].to_i
  left_rev  right_rev
end
sorted_files.each do |dump_part|
  results = `bzcat #{dump_part} | svnadmin load #{restore_path}; echo $?`
  puts results if DEBUG
  res = results.split.last.to_i
  if res != 0
    puts “Error on trying to load up #{dump_part}!”
    exit 1
  end
end
22
Jun

RubyKaigi 2008 Day 1 The Lightning Talks

Lightning talks are one of the more interesting parts of a conference in my opinion since 5 minutes really forces the speaker to get to the point and it becomes painfully obvious if the presentation has no focus or if there has been real work to get across the main message in the shortest amount of time.

So here are some highlights

Kuwata on Java to Ruby

  • No, not the book Java to Ruby
  • Going from Java to Ruby requires a change in mindset. Not a change of code
  • Some historical example: COBOL in Java (ed. That sounds frightening) is like Java in Ruby
  • Don’t hold back experts and too many things spend too much time on beginners
  • Do not keep beginners as beginners (teach them!)
  • Bragging about the largeness of a project size is the wrong type of bragging (suggested large code + many devs == lack of ability

dRuby & Security by Nishiyama

  • druby is not built by default to handle the wild Internet
  • There is a feature called insecure method list that will help prevent certain methods from being invocated remotely
  • Use $SAFE however it won’t save against a DoS. Also don’t forget about rlimit

Ruby + ODE by Sasaki

  • Showed a very nice 3D demo walkthrough world controlled with a Wii-mote and looked like the Pitagora Switch world
  • Can summon objects pressing one of the buttons
  • Can stop time
  • The project should be on Code Repos
  • (ed. Seeing this in action was far more interesting than reading these notes)
  • Do Beginners Dream Enumerators? by Imai
    • Conclusion first: Sorry they don’t
    • Showed some very nice examples of using the Enumerator library for many bad cases (each_slice)
    • Beginning Ruby programmers really love each to the point of going overboard

    Folk programming with Ruby by mootoh

    • Folk Programming was introduced at YAPC Asia 2008 (See my notes)
    • Show examples outside of building web applications such as Rich UI exploration
    • Showed examples of Plugins to other programs since it’s easier than writing a big app (although with Ruby the apps should be nice and small)
    • Some examples: Safari + Hatena bookmark, Quicksilver + Twitter (looks dangerous), Quartz Composer + Gainer, Vim + Refe
    • Ruby is a very good glue

    Again as a Rubyist… toRuby by Ikezawa

    • (ed. I liked this talk a lot since it wasn’t by some uber-Ruby hacker)
    • Didn’t use Ruby until 2000
    • Background was as a consultant since 1984. Helped found a Wapro Kissaten!
    • Moving to Ruby hit the OOP barrier. Was not used to OOP methodologies at all
    • Stopped however after a long time in June 2007, found a local Ruby guru to help him out and that got the ball rolling again
    • Invites others to join in

    Ruby 1.9 with Rails 2.1 by matsuda

    • Went through the history of web programming (or his version of it)
      • Ancient History - PHP
      • Recent History - DB Framework with ORM (in Java… lots of these frameworks)
      • Current - Rails
    • However DB access is a Rails weakness
    • Introduced named_scope feature (Is this a Rails 2.1 specific feature? Need to review this myself
    • More info on this at blog.dio.jp

    Read code with Testing by Endoh

    • Rookie Ruby Committed
    • His suggestion on learning is by reading real code
    • Use TBCR (Test Based Code Reading)
      • Run make test-all
      • Find code paths that are never executed
      • Add tests (requires more code reading)
    • Using this method have increased Ruby’s test coverage to 85%
    • In contrast Python is 80%, Perl 63%, PHP is 51% (plans to target PHP next)
    22
    Jun

    RubyKaigi Day 1 The Matz Keynote

    Okay this is my notes from Matz’s Keynote. I was 5 minutes late since finding lunch took a really long time to find anything around the area unfortunately. Unfortunately, most of the visiting Rubyists decided to do KFC however Charles Nutter decided to stick it through and we finally found a nice Yakiniku restaurant to eat at but that ended up being the reason I was 5 minutes late… okay anyways here are my notes from in the middle of the talk…

    Matz was talking about sanctuaries and how some technologies have built their sanctuaries over time. Here are some sanctuaries he mentioned and some of their defining characteristics:

    • UNIX
      • The filter (wahoo!)
      • “Worse is better” aka the New Jersey School of Design (I always ask myself just how much worse though..)
      • Convenience over perfection
    • Smalltalk
      • OOP, deep OOP
      • Targeted at children (funny how only greybeards really use this language now discounting eToys)
      • Bytecode VM but not the first to have one but one of the more prominent ones
      • A dynamic language implementation with decades of hard-earned experience, wisdom and knowledge around it
    • java
      • Well Java seems to fulfill business and ‘enterprise needs’ (for now)
      • Java was originally slow however time has changed that perception. Java’s speed complaints have mostly faded away (But I still complain about a 30 second startup time for the VM)
      • Absorbed many other ideas from other languages (VM, Garbage Collection, Exception Handling)
      • Java has one of the fastest Garbage Collected VMs now (with the amount of engineering effort thrown at it I’d hope so)

      Matz then describes that Sanctuaries tend to go through the following phases

      • Hackers gathered
      • New technology is born
      • The world changed (because of the technology? Missed this…)

      Don’t forget about centripetal forces during these stages. The community matters quite a bit. According to Matz, 50% of the types of OSes out there in this world are some type of UNIX.

      Finally, he goes on to describe the Ruby Sanctuary and its defining characteristics

      • For Rubyists, feeling matters. Focus on the human and the joys programming
      • It inherited many things from the past. Lisp metaprogramming, Smalltalk OOP, UNIX text processing
      • Productivity matters. Machines are faster but people’s time is much more expensive
      • Agility matters. Environments change and embracing the changes is the right thing

      At this point a person from Rakuten comes up on stage and talks about some projects that Matz has been collaborating with.

      One is called ROMA which is some sort of distributed memory data storage (think memcached with some more ability for data integrity in case of failures)

      The other one is called fairy which is supposed to be a lightweight distributed programming framework.

      Unfortunately it seems that both projects are rather delayed and it doesn’t seem apparent if these projects will be Open Sourced or not. That is rather disappointing to me but can’t have everything for free now can we?

    22
    Jun

    RubyKaigi 2008 Day 1 Part 3 Notes

    Evan Phoenix on Rubinius

    Evan started off with a quick intro on Rubinius and proceeded to talk about some of the big pieces of Rubinius from a 10,000 feet high view.

    • The kernel of the system
    • The C Compatibility Layer
    • It’s a big project and Evan wants to have a conversation with anyone who wants to have one on it

    For the VM nerds here are some feature highlights…

    • Accurate generational Garbage Collector
    • Bytecode based VM
    • Capable of bootstrapping itself

    Evan suggested we should think of Rubinius sort of like an OS.

    Then he started diving right into a tour of some of the cool internals of Rubinius and explaining some of the internal objects that really are the heart of Rubinius (above the VM layer)

    BTW what is the <<? Evan coins it the left chevron.

  • MethodContext - Lets one see information regarding a method and the context surrounding it
  • CompiledMethod - Peek at the bytecodes of a method!
  • BlockContext - Tell me all the information about a block. Can capture a compiled block and inspect byte codes
  • SendSite - One per place where a call is performed. By caching information on this, can speed up method dispatch
  • With MethodContext and CompiledMethod it’s possible to implement eval in Ruby and follow the principle of Code as Data. Taking advantage of Ryan Davis’s ParseTree (included in Rubinius) one can take something like

    "1 + 1".to_sexp

    Which will take 1 + 1 and change it into an s-expression, convert it into an AST, and a User Visitor Pattern implementation can walk through this and spit out bytecode. (I might have recollected this wrong.. if so, sorry.. Not a VM implementor)

    Some other big features that Evan mentioned were

    • Extensions
      • Getting close to running Ruby C-extensions
      • However they are still 2nd-class citizens (they will take a performance hit but working is better than fast and broken)
      • MRI in this case is still faster
    • Multi-VM implementation
      • stdin and stdout are implemented as pipes
      • Functional but still highly experimental (can try calculating Pi across a multi-core machine)
      • args = ["-e", "puts", "hello"]
        vm = Rubinius::Vm.spawn args
        puts vm.stdout.gets
    • Channels
      • One of the main internal communication channels used in Rubinius
      • I/O events use channels for example

    Then Evan goes on to showing some cool demo of implementing Binding.of_caller in front of the audience. He also showed one neat thing about rbx. If you run a command it will load irb automatically assuming you want a REPL (cool!)

    Q & A

    • Q: What are your final goals with Rubinius?
    • A: Have an image like SmallTalk? The VM only knows about byte codes not Ruby. Could even write an implementation of SmallTalk on the Rubinius VM however Evan said he has no plans to
    • Q: Anything on shared benchmark testing?
    • A: (Matz) There has been movements to start collecting code as of last week. Trying to make sure that it is more ‘real world’ code benchmarks. There should be an Infoq article on this.
      (Evan) Started on this. Check out GitHub for more info
    • Q: How’s the performance?
    • A: No really hard numbers on Rubinius’ performance. Some things have gotten faster over time such as the generational part. Awhile ago Evan wrote a bunch of small benchmarks to test things out but seems to have misplaced them somewhere
    21
    Jun

    RubyKaigi 2008 Day 1 Part 2 Notes

    Here’s a continuation of my scribbled notes from the RubyKaigi. This one from the JRuby implementors. Some of my own thoughts and comments are inserted in parentheses.

    Charles Nutter on JRuby

    • Quick intro and the impressive live demos of JRuby in action (or as the IRC channel said Nice Live Coding (NLC))
    • This summer, work on Ruby 1.9 features (seems there’s an option flag to turn on 1.9 compatibility mode already)
    • Current 1.1.3 Progress Report
      • A new interpreter that is up to 30% faster
      • Compile-time performance enhancements
      • Many Rails Bottlenecks fixed
    • No new release of JRuby this year but…
    • Wanted to show some uses of JRuby
      • IDEs (NetBeans, Eclipse, INtelliJ use JRuby in their IDEs
      • Swing GUI development
        • Swing development can be very complex but Ruby helps to simplify it
        • Benefits from the ‘Write once, Run everywhere’
        • There are a plethora of options to choose from (why does this seem to happen in the Java world all the time?)
          • Cheri
          • Profligacy (by the infamous Rails Ghetto-man Zed Shaw)
          • MonkeyBars (Proceeded to show an impressive demo)
            • MonkeyBars leverages existing GUI utils (that’s a major plus)
            • MVC-like structure (hey looks like Rails…)
      • Graphics (Showed some really sweet demos of ruby-processing in action)
        • Processing had a way to interface to audio input devices
        • Remember to check out “A Face for Stephen Hawking”. Wow that code looked really clean…
      • Rails (the benchmark app that all implementors need to measure implementation readiness by)
        • There has been a shift in Java Web frameworks lately (but still happening at a glacial pace)
        • Deployment problem is “solved” (I keep hearing this…)
        • mongrel is “old school” (at least for JRuby-based deployments)
        • Made mention of Phusion/Passenger but it still had the issue of rails process spawning and how to manage that (Seems Jruby doesn’t have these issues)
        • Some war deployment demoes
          • A warbler demo (A tool to help create war files)
          • Will package in Jruby automagically into the war (That’s very nice)
          • Just run warble inside the rails application directory (Hopefully it doesn’t package up a gigantic development.log)
          • As simple as GLASSFISH_HOME/bin/asadmin deploy *.war
          • Has Rack supoprt (can handle Merb and anything else with Rack support
          • Can be configurable
          • From his demo, it seems that warble will make a war of anything (aka be careful what directory you run this command)
        • Showed some really nice benchmarks of rails and JRuby (I need to put this through the ringer when I get more time)
        • Showed another deployment tool called the glassfish gem
          • 3MB gem that had everything needed for JRuby on Rails
          • Tries to match the agile process
      • JRuby Users (in production): CSI’s Disease Surveillance, Oracle’s Mix website, Sun’s Media Cast, Thoughtworks Mingle

    Q & A

    • Q: The Parser Implementation seems hard. Any war stories
    • A: I hate parsers and refuse to write one. Someone wrote something that used J. I don’t know much about it but Tom’s pains dealing with it seem very hard. No plans to change parsers anytime in the near future.
    • Q: Object Space & Binding
    • A: On Jruby, this will incur an automatic performance penalty. binding & caller will be required each time which incurs a heavy cost
    • Q: Non-local break performance?
    • A: Implemented as a Java Exception. By doing this, the JVM can optimize that as a Jump. JRuby tries to use this as much as possible behind the scenes for performance
    21
    Jun

    RubyKaigi 2008 Day 1 Part 1 Notes

    Ruby Kaigi 2008 is happening. I’m sure there other posts on the Ruby Kaigi happening however here are some of my own hasty scribbles for anyone that cares…

    Introduction Speech

    • This is the 3rd year of the conference
    • One theme of this year is multiple implementatios
    • More people coming into the Ruby community and we need to greet the (Dave Thomas’ speech from last year)
    • Two tracks this year (I mostly followed the main track)

    The first set of presentations from the main track were from the Ruby implementors.

    Koichi SASADA - Ruby VM Development

    • 1.9.0-2 released as of 6/20/2008 (mainly bug fixes)
    • A little discussion of 1.9.1 Roadmap (Something about 1.9.1 being the more stable release?)
    • A plethora of interpreters available now (lists all of them)
    • Sasada-san felt a little sheepish over Matz mentioning taking only about technology is ‘boring’ since his talk focused on mainly technology
    • University of Tokyo has become a haven for since Sasada-san now has a laboratory (wahoo!) which means…
      • Ruby related research-projects
      • Student Research Projects on Ruby
    • Parallel Thread Execution
      • Better multi-core support
      • Memory resource usage (or was that resource contention?) can be a problem
    • Multiple-VMs
      • Run Multiple VMs in same Ruby process
      • Jruby + Nakada-san are the primary drivers
      • The JRuby guys are ready to implement it (waiting on API) and Rubinius seems to have one already
    • API done
    • bootstrap done
    • Creation of interpreter mostly done (seems to have some small issues?)
    • Still needs documentation (What project doesn’t?)
  • High Performance Computing (HPC) on Ruby
    • Ruby implementations needs FP optimization for HPC
    • Ruby 1.9.x quite fast compared to other implementations (according to the Benchmarks Sasada-san showed)
  • Atomic Ruby (aka Customizeable Ruby)
    • Create an Optimal interpreter for “you”
    • Make it easier for Ruby to be used in embedded environments
    • Make it easier for Ruby customized for specific environments (iPhone anyone?)
    • Make it possible to plug in and out the core pieces
    • Byte code serialization and embedded
    • Make the GC customizeable
  • More work memory optimizations (Sounded like there was the need for more profiling)
  • 19
    Jun

    mod_rails aka passenger == nice && easy

    I looked over mod_rails today and realized how nice and easy looking it was to install.

    The general install process is:

    1. Install rubygems
    2. Run gem install passenger
    3. passenger-install-apache2-module
    4. Follow the instructions and install any missing dependencies (it actually is smart enough to detect which ones you need before splatting itself into the filesystem)
    5. Add some lines into the apache conf somewhere, declare a virtual host and point DocumentRoot to the public folder of the desired Rails app

    By piggypacking onto the gems installation infrastructure they made it really simple to install even without support from native package managers (although my hope is that it will be as easy as apt-get install modrails one day).

    However, always the skeptic I decided to give it a quick and dirty test run and lo’ and behold it really is as easy as advertised and looks like it’s working okay.

    Impressive stuff. Now I just need to read a little more on how it actually works (seems to hand off to some sort of backend process that is intelligent enough to spawn a set number of backend rails processes as needed and kills any that are idle off or continue serving if things are busy). So for those of you looking to deploy rails within an apache setup, this might be a nice and simple way (assuming you have access to manage the apache server process) to integrate rails within Apache.

    I’m still unclear how many rails apps can be multiplexed on a realistic basis with one Apache installation with this method but a little bit of trial and error should give some ideas.

    Read more on mod rails

    30
    May

    The Rails Horde at RailsConf 2008

    Egads… so… many… Rails… zombies

    07
    Apr

    A quick survey of del.icio.us APIs for Ruby

    I had this task where I wanted to pull information from del.icio.us for some data processing so I decided to take a look at what was available for Ruby. Before, I say what path I took let’s go over the choices I dug up.

    Ridiculous

    First up was Ridiculous which labels it as a simple wrapper for the del.icio.us API. After looking at the API I definitely agree it is quite simple to use. So here are the highlights.

    The good

    • BSD Licensed
    • API really is simple
    • Has a rubygem (Any serious ruby tool should be available via rubygems)

    The bad

    • Seems to require logging into delicious
    • Only seems to manage a delicious user’s bookmarks

    Mirrored

    Next was mirrored which looks like it is modeled on Active Record.

    The Good

    • Acts like an Active Record Model (nice for Rails guys)
    • Supports both del.icio.us and ma.gnolia.com
    • Has a rubygem
    • MIT-ish licensed

    The Bad

    • A little more complex than ridiculous (counting # of classes)
    • Only handles a logged in user scenario
    • Requires logging in

    ruby-Delicious

    Next up was this blog post that pointed to ruby-Delicious. However, when I clicked on the link I got a Forbidden. I love abandon-ware. I decided not to look much farther since the author obviously wanted to talk about something he didn’t think about maintaining.

    What I wanted

    What I wanted was something a little more full-featured like Python’s pydelicious library. It handled both cases of being logged in and wanting to update bookmarks AND just the lazy joe who wanted to yank data from delicious without having to stuff it into a data structure by hand.

    In the end I ended up using none of the above since none of them did what I really wanted and after a little of Googling saw many snippets [1], [2], [3] that showed how one could do it with just open-uri. In the end I decided to just use open-uri since it ended up being a big fat 3 lines of code to implement the base case of what I wanted with open-uri. With a few more lines I had exception handling and retrying on failure.

    However, hopefully someone else will be able to make use of the above libraries since they do like quite useful for programatically accessing delicious.

    [1] Use delicious API via HTTPS from Ruby
    [2] Ruby delicious snippet
    [3] Ruby, delicious and graphviz

    02
    Feb

    The Ruby Programming Language book out on Safari now

    I just noticed that The Ruby Programming Language Book by David Flanagan is out on Safari now. This looks like an update to Ruby in a Nutshell which has been a rather disappointing title for me personally.

    After a glance through the contents of this updated edition it looks like this one could be a real winner on hand for Ruby programmers wanting a organized and clean description of some of the deeper parts of Ruby without having to trawl through piles of blog posts or read through piles of source code just to get an explanation. While there is much to be said from learning through reading source code. Good explanations of concepts and code are something to be valued. Let’s hope this title really is what I think it is. Either way, I can’t possibly make a thorough judgement call on a book I’ve not really read through. So take my thoughts on the book with a grain of salt. I only spent 20 minutes glancing through the contents and skimming some sections to see if it had the type of content I would be interested in.

    On a side note it seems that the author rebukes a blogger denigrating the book before it’s even out yet. He also brings up the Ruby Fanboy / Club phenomenon that supposedly has been on the rise in the Ruby community. I guess popularity brings the ‘Club’ in no matter how hard you try to fend it off.

    14
    Nov

    Design Patterns in Ruby Sneak Preview Review

    I’ve been slowly reading the Design Patterns in Ruby: Rough Cuts on Safari and have been finding it a pretty good read so far. I have to admit I’ve slept through the original Gang of Four Design Patterns book since it looked so excruciatingly boring and I wasn’t really convinced I needed such patterns for most of my boring run of the mill scripts. (Sure sure, crucify me now)

    The book is roughly broken into

    * A quick quick intro to Ruby (thank the heavens he made this short since I am getting sick of reading so many of these Ruby intros)
    * The traditional Design patterns and how they would look like in Ruby
    * Design Patterns suited for Ruby

    I’m still reading through the traditional Design Patterns section but am enjoying how the author shows a small implementation with a pretty good example then goes on to refine it and point out how some features of Ruby make certain pieces of the implementation irrelevant or could be shortened. He also spends time explaining common gotchas and emphasizing the use cases for the particular pattern.

    I can definitely see this occupying a place on my bookshelf as a nice reference guide for Ruby. It’s getting nice seeing more books that cater to people who aren’t complete Ruby newbies (while that market is important too, don’t forget the journeymen if you want to sustain a community). I’ll add more as I read through more of it but even as a Rough Cut it has been an enjoyable read so far.

    Go get yourself a Safari account and start reading

    22
    Oct

    Book Review: Practical Ruby for System Administrators

    One of the things I do with Ruby is to use it to help handle some of my tasks when I am wearing my sys admin hat. I can’t say I’m a Ruby expert by any means but when it comes to writing code, I always get the shivers looking at Perl which is a shame since any sys admin worth their salt should probably have an okay understanding of Perl.

    Anyways, when I saw Practical System Administration with Ruby I knew I had to pick up a copy to see if I could glean any really cool hints and tips for easing the tasks of system wrangling.

    The breakdown of the contents kind of goes like this:

    1. What Ruby can do for you and common tasks
    2. Performance and Metaprogramming
    3. Handling files and dealing with storage of data
    4. Networking and monitoring
    5. Ruby gems and testing

    The book itself isn’t so thick which is good for reading while on the train and I found Mr Hamou’s discussion of Ruby quite good however and he had a pretty explanation of meta-programming which is a topic I almost always completely forget right after I read about it, unfortunately. And in some cases, meta-programming seems like a heavy hammer when what I want is mostly a way to glue different components together in a more elegant way than writing a shell script. While it’s nice to see an explanation of meta-programming and some nifty ways to model users and whatever. Perhaps what might have been more interesting is to have some examples that show how one goes about migrating from that shell script that was written in haste under pressure and refactoring it into a more elegant Ruby script. Perhaps that is just me…

    What I liked was the chapter on how to take advantage of one-liners for Ruby. I imagine most seasoned Perl gurus will look at that and go ‘ha’ I can do write that even shorter! However, it is nice to have Ruby equivalents that can handle most of the same thing.

    The section on performance was so-so but most of the time I am looking at tools for gluing things together and performance tends not to be a big issue rather than finding a way to glue things together that doesn’t make me want to scream.

    The rest of the pieces, I can’t really remember much about them and was sort of disappointed with the Ruby gems chapter. While it’s nice having an explanation of gems… the documentation on the website for gems s adequate enough. What would have been more interesting is how to handle setting up private repositories for gems and some more techniques on how to have gems do a bit of heavy lifting.

    While I did get a chuckle at the author taking potshots at LDAP, I’m quite disappointed he didn’t offer much better solutions besides ‘home-grown that only the creator will ever figure out’. While LDAP is not something you can just pick up in a few minutes, it definitely fills a niche that can be sorely needed once you get past a certain level of systems that have some sort of authentication and you want to avoid the ad-hoc gazillion systems that are so easy to create but so
    hard to stomp out.

    Overall, I give this a book probably an average rating since I only found the one-liners chapter to be the most useful chapter out of all
    of what I’ve read sadly. The rails chapters I found mostly worthless since there is a way better book out there that can explain to you how Rails works for most of the cases. I don’t expect one book to fill all needs in the Ruby world but I was hoping for more than what I got. But overall, it didn’t suck and the reasonable price for the book doesn’t make it as hefty as picking up other books.

    Other Reviews

    21
    Feb

    Finally a gem release of ruby-opengl

    Just wanted to let folks know that I’ve finally figured out how to get the build system in place for ruby-opengl to:

    • Gemify itself
    • Build native extensions during Gem installation using mkrf

    Which means (I hope) that there should be an easier way to get OpenGL working with Ruby. Currently it should support installing in Linux and OS X. Installation should be as difficult as:

    gem install -y ruby-opengl

    Deinstallation should be similar.

    For win32 users, I’d suggest using the old bindings provided with the all-in-one installer although I’d like to get a gem built for win32 so hopefully it can get included in the all-in-one installer.

    References

    21
    Feb

    Messages like Warning: require_gem is obsolete. Use gem instead. driving you nuts?

    If you’re seeing tons of those messages like I’ve been and wondering what in the world that is all about. After Googling around I finally found a definitive answer on Jason Young’s Blog what it was all about.

    What is it

    Since rubygems 0.9.0 the command require_gem has been deprecated in favor of just plain gem. Part of the reasoning for it going the way of the dodo is tied to some
    problems with autorequire. I don’t know any of the deep voodoo that powers rubygems but uh.. okay.. sure.

    How to fix it

    If you’re still getting these warnings you’re recommended to try re-installing all gems you might have installed if you have a 0.9.0 or lower installation. Happy Ruby Hacking.

    References

    07
    Feb

    Migrating instiki from one database type to another

    The Rant

    Instiki is one of the premier wikis for Ruby on Rails which is another way of saying the other rails-based solutions don’t look that great so far from what I’ve seen. Here is an except from the instiki website:

    1. Download
    2. Run “instiki” with Ruby 1.8.4 or greater. (on windows, that’s instiki.cmd)
    3. Chuckle… There Is No Step Three™! :) (See note)

    Yeah, nice and simple… to install. Here’s some facts that instiki DOESN’T tell you without digging around:

    • It uses sqlite as its database backend to store all wiki information (except images and file uploads).
    • It’s NOT Rails 1.2.x ready
    • It was written BEFORE ActiveRecord and was migrated to ActiveRecord later
    • You can export your data but have no way to import your data easily (more later)
    • The documentation from a USER perspective is pretty sparse
    • Active development seems to be moving at a snail’s crawl

    So what does this all mean? Well, if you want to migrate your instiki instance to a different instance you’d like to think you have a couple of options.

    1. Just copy the whole application to the new server, kickstart done (This works)
    2. Dump out the wiki in some export friendly format and re-import it back in

    Option #1 works quite well however if you want to switch database backends you’re stuck with option #2. However save yourself hours of time (I didn’t) and DON’T try the following things (unless you’re a rails god. In which case why are you reading this?)

    • Try exporting the wiki in textile format and importing it…. oops import is busted. A stub is there (http://localhost:2500/wiki/import) but it is definitely broken
    • Dump the sqlite database with sqlite utilities then re-import them into target database. This doesn’t work with MySQL as far as I know. I bet it’s broken with Postgresql too
    • Look at the source code
      to find where the issue might be. Don’t worry, even the changelogs say import is busted and there is no other sign of some way to input data easily
    • Write some tool to import textile in. That would require reading the APIs, right? bleh
    • Write some sort of ActiveRecord translator? Well sort of… but it’d be nice if there was a tool available. And if you’re not a rails guru you’re sort of screwed in this case.

    Now I’m sure DHH (the creator of instiki) will grumble about something about this not being ‘appropriate’ for its original intentions and blah-blah. Gee that’s nice. Maybe you better put that down in the caveats, before I commit a whole bunch of data into it.

    The Fix

    Okay, enough ranting about half-baked Open Source Rails apps. Here’s the fix.

    1. Add plugin script to instiki app

    Most normal rails app will include a file called plugin inside $RAILS_ROOT/script/plugin. Unfortunately, instiki doesn’t include it. Luckily the script is really small since it just calls out to the rails framework to handle most of the hardwork. So try this:

    $ echo "
    #!/usr/bin/env ruby
    require File.dirname(__FILE__) + '/../config/boot'
    require 'commands/plugin'
    " >> $INSTIKI_HOME/script/plugins
    $ chmod +x $INSTIKI_HOME/script/plugin  # Make it executable
    
    2. Install the manage_fixtures plugin

    I’m afraid I don’t have time to explain what a Rails Fixture is in this post but just think of it as a portable way of representing data going into a database for rails. It works well but don’t try hundreds of megabytes of data.

    I also won’t go much into rails plugins except to say it’s a way of extending a rails application with more functionality (probably for a Rails developer rather than an end user of the application). We’re going to use a really sweet tool called manage_fixtures which allows us to move around data between different databases with ease (assuming the rails app isn’t doing weird SQL crap).

    $ cd $INSTIKI_HOME
    $ script/plugin discover    # Hit enter a gazillion times
    $ script/plugin install manage_fixtures
    
    3. Export the data into fixtures

    The following will export all your db entries as fixtures into $INSTIKI_HOME/test/fixtures. You need to set the RAILS_ENV to production because by default it will try to use the development database.

    $ cd $INSTIKI_HOME         # You SHOULD be here anyways
    $ RAILS_ENV='production' rake  db:fixtures:export_all
    
    4. Change the database connection to desired

    Now change the file in $INSTIKI_HOME/config/databases.yml from:

    production:
      adapter: sqlite3
      database: db/production.db.sqlite3
    

    to the following (adjust mysql parameters to suit your setup)

    production:
      adapter: mysql
      host: localhost
      database: instiki
      username: root
      password:
    
    4. Create database and the appropriate tables

    The following commands will create a database named instiki (or whatever you put in databases.yml) and make sure the database schema in the database matches instiki’s schema.

    $ echo "create database instiki" | mysql -u root
    $ RAILS_ENV='production' rake migrate
    
    5. Finally re-import the data from fixtures

    Whew! Finally we can re-import the data into MySQL (or whatever) and continue on using instiki for something.

    $  RAILS_ENV='production' rake db:fixtures:import_all
    



    Pages

     

    October 2008
    S M T W T F S
    « Sep    
     1234
    567891011
    12131415161718
    19202122232425
    262728293031  

    Badge Farm

    • Firefox 2
    • CSSEdit 2
    • Textmate
    • Powered by Redoable 1.0

    Protected by AkismetBlog with WordPress