Developing Storm
Posts tagged RAILS
Blog Woes Part 2
Writing your own blog tools is fun until you get the rug pulled out from under you by your hosting service when you don't have any spare time to fix things.

Finally, I think everything is working again. Now if I only had something to say.


New Comment
Blog Woes
Sorry about that folks. My hosting service updated the Rails version on the shared server and this update removed a bunch of deprecated methods my blog application relied on. My Rails skillz were rusty and it took me some time to fix but it's back up now. This sucks on multiple levels but I guess it's par for the course.

Comments(2)  New Comment
Defending Ruby and Rails
In general I like the blog HackNot but in a recent post Mr. Ed's made an argument that I think is fundamentally wrong.

The post in question is an essay about the dangers of hype and how one would be better served by "turning one's focus to the principles and techniques of software development, which transcend any technology fashion". He goes one to say "Your time and energy is better invested in improving your abilities and skills than in adding another notch to your technology belt." The problem with these assertions are that they assume that learning the new technology neither offers new insight into the 'principles or techniques of software development' nor would 'improve your ability and skill'.

In the post Mr. Ed uses Ajax, Ruby and Rails as his primary examples of over hyped technologies to be avoided. I'm not an Ajax guy so I can't talk about it but I've been a Ruby fan for a long time and have been playing with Rails for the last year; and while I don't think I qualify as what he refers to as a 'fan boy' I have certainly enjoyed working with and learning from both technologies.

Now, I can't guarantee you would have the same learning experience I had learning Ruby and Rails, because your background may include exposure to previous technologies that I never learned (and this would be true whether the technology was hyped or not), but I'm willing to bet you would learn a lot of new things, especially if you've not already ventured into the world of scripting languages and their web frameworks. To be a bit more concrete, if you come from a C, C++, Java, C# background, you will learn new ideas about control flow, abstraction, modularity, loose coupling and information hiding - all very core principles of software engineering.

It's certainly true that people look to these new technologies as if they are the silver bullet that will slay their wooly coding problems. And I agree with Mr. Ed that that they certainly are not. But again, just because a technology can't live up to it's over the top hype doesn’t mean it doesn't have real value.

As a final point, I'd like to take issue with the posts over simplification of Rails as just an ORM library for Ruby. While it's true that the Rails ORM layer, Active Record, is a powerful and important part of Rails, it's certainly not the only thing the framework offers. What bothers me most is Mr. Ed was both ignorant of this fact and using something as an example that he didn't know enough about or he was purposely distorting the facts for dramatic effect. I suspect the latter and am disappointed because I had come to expect more.


Comments(2)  New Comment
Don't hate me
Don't hate me because I'm a genius. I get things like Ruby and Rails, things that most mainstream developers only dream of understanding. I got Java too. Oh, the days when those first Basic developers tried to use Java and faced case-sensitivity for the first time. Many a chuckle was had at their expense. I wonder what happened to those poor sots. Now we get to cull the herd once more with a move to Ruby. What great fun it will be watching the dim witted masses struggle with closures and full OO behavior. My, my what a sorry bunch they'll be. Maybe then they'll finally understand how special we few gifted developers are and maybe then, just maybe they will not hate me because...I'm a genius.

Comments(4)  New Comment
Speedier Blog
Everyone has been too polite to point this out but the blogs been rather slow since I switched to my Rails based solution. This is through not fault of Ruby or Rails however, I just wanted to keep things simple and I've been running under a CGI setup. My hosting service offers SCGI however and I've finally had them set me up. If you don't care, you don't need to do anything, the existing URLs will continue to work albeit at the current speed. If you want to see how the blog works when the entire application and the db connections aren't being ripped down and rebuilt continuously, you can use the URL: http://www.developingstorm.com/dog/blog/ instead of http://www.developingstorm.com/pete/blog/

Comments(2)  New Comment
Rails deploy script
I like to tinker with my blog's code so I'm always pushing updates to my hosting server. Unfortunately, I can't just blast the whole application directory up to the server because a few files are different between machines. That means I usually hand pick files in my FTP client to send up individualy and that's real a pain. This morning I finally got sick enough of doing that and wrote myself a script to do the update that's smart enough to know to skip certain files and directories. I figured someone else might like it too so I'm posting it here.
require 'net/ftp'

TextFileMatches = [/\.rb$/,
        /\.js$/,
        /\.yml$/,
        /\.css$/,
        /\.sql$/,
        /\.html$/,
        /\.txt$/,
        /\.rhtml$/,
        /\.xml$/,
        /\.rxml$/,
        /^READ/]

def textfile?(file)
 TextFileMatches.each do |matcher|
    return true if file =~ matcher 
 end
 return false
end


#
# A watcher that copies the files being walked
# into mirror directories on an FTP server.
#
class FtpMirrorWatcher

  def initialize(session)
    @session = session;
  end
  
  def pushdir(dir)
    puts "pushdir: " << dir
    list = @session.nlst
    if not list.include?(dir)
      @session.mkdir(dir)
    end
    @session.chdir(dir)    
  end
  
  def popdir()
    puts "popdir"
    @session.chdir("..")
  end
  
  def dofile(file)
    if textfile?(file)
      puts "copying text file: " << file
      @session.puttextfile(file, file)
    else
      puts "copying bin file: " << file
      @session.putbinaryfile(file, file, 1024)
    end
  end 

end

#
# A files system scanner that walks a directory tree and
# calls an observer on the following events
#
# 1. pushdir(dir): when we follow a directory branch
# 2. dofile(file): called for every file in every directory except
#     those in those listed in skip_dirs, skip_files or any file or
#     directory name that begins with a period.
# 3. popdir: when we return from a branch
#
# Set watcher= an instance of a watcher class to observer
#  the tree scan
#
# Set skip_dirs= to an array of simple directory names to skip.
#   Wildcards and containment relationships are not supported.   
#   For example: skip_dirs = ["foo", "lib", "logs"].
# 
# Set skip_files= to an array of simple file names to skip.  
#   Wildcards and containment relationships are not supported.  
#   For example: skip_dirs = ["app.rb", "foo.cgi"].
# 
class DirScanner
  def initialize(watcher = nil, skip_dirs = nil, skip_files = nil)
    @skip_dirs = []
    @skip_fils = []
    
    @watcher = watcher
    @skip_dirs = skip_dirs if skip_dirs != nil
    @skip_files = skip_files if skip_dirs != nil
  end
  
  def watcher=(sf)
    @watcher = sf
  end
  
  def skip_files=(sf)
    @skip_files = sf if sf != nil
  end
  
  def skip_dirs=(sd)
    @skip_dirs = sd if sd != nil
  end

  def scan(path)
    pwd = Dir.pwd
    Dir.chdir(path)
    scandir
    Dir.chdir(pwd)
  end

  private 
  
  def pushdir(dir)
    @watcher.pushdir(dir) if @watcher != nil
  end
  
  def popdir()
    @watcher.popdir if @watcher != nil
  end
  
  def dofile(file)
    @watcher.dofile(file) if @watcher != nil
  end   
  
  def scandir(root = nil)
    pwd = Dir.pwd
    if root != nil
      Dir.chdir(root)
      pushdir(root)
    end
    files = Dir["*"]
    files.each do |file|
      if File.directory?(file)
        if not @skip_dirs.include?(file)
          scandir(file)
        end
      else
        if not @skip_files.include?(file)
          dofile(file)
        end
      end
    end
    Dir.chdir(pwd)
    popdir() 
  end
end

To run this to update my rails application I do the following:

scanner = DirScanner.new

scanner.skip_files = ["dispatch.cgi", 
                    "dispatch.fcgi", 
                    "database.yml"]
                    
scanner.skip_dirs = ["log", 
                    "test", 
                    "doc", 
                    "vendor", 
                    "lib", 
                    "script"]
                
session = Net::FTP.new("(my ftp server)",
                   "(my user)", 
                   "(my password)") 
				
session.chdir("(remote dir)")
scanner.watcher = FtpMirrorWatcher.new(session)
scanner.scan("(local dir)")
session.close

New Comment
Adventures of Scaling
Even if you're not a Ruby head I think you will like this series of post from poocs.net on how they got their Rails application to scale to the same level of their previous PHP application. Link: The Adventures of Scaling

Our mission was to rewrite the codebase behind the online community network eins.de since the former PHP-based codebase was both bloated and poorly architected. Being an online community site, eins.de has everything you’d expect from such a term: user forums, galleries with comments, user profiles, personal messaging, editorial content, and more. Additionally, eins.de has local partners that are the driving forces behind all of the available sub-communities, mostly forming around the bigger German cities. User interaction is possible globally, as such there’s only a single dataset behind everything.

The old codebase roughly consisted of around 50.000 lines of PHP code (plus a closed-source CMS that’s not included in this calculation). We’ve rewritten most of it (some features were left out on purpose) in about 5.000 lines of Rails code.

eins.de serves about 1.2 million dynamic page impressions on a good day. The new incarnation is serving up the 25 sub-communities on different domains in a single Rails application. It was, however, not before Febuary of this year when our iterative optimizations of both system configuration and application code lead to a point where we were able to deal with this amount of traffic.


New Comment