Showing posts with label gem. Show all posts
Showing posts with label gem. Show all posts

Wednesday, October 26, 2011

Rhodes

Rhodes is an open source Ruby-based framework to rapidly build native apps for all major smartphone operating systems (iPhone, Android, RIM, Windows Mobile and Windows Phone 7). These are true native device applications (NOT mobile web apps) which work with synchronized local data and take advantage of device capabilities such as GPS, PIM contacts and calendar, camera, native mapping, push, barcode, signature capture, Bluetooth and Near Field Communications (NFC).
Rhodes is the ONLY framework with: support for Model View Controller (other frameworks force you to put all business logic into the view as JavaScript), synchronized data (the price of entry for enterprise apps), support for ALL devices (Android and iPhone is not “crossplatform”), a hosted build service (RhoHub – which changes the game for mobile app development entirely) and true industrial device capabilities such as NFC. Rhodes has many other major advantages over every other framework and underlying SDK, which can be summarized as modern development goodness for mobile apps.

If you don’t need an IDE and have Ruby already, you can install Rhodes with: “gem install rhodes”. Instructions on how to build your first app are in our Rhodes Tutorial

http://rhomobile.com/products/rhodes/

Thursday, October 6, 2011

fog - The Ruby cloud services library


Whether you need compute, dns, storage, or a multitude of other services, fog provides an accessible entry point and facilitates cross service compatibility.
Just getting started working with cloud resources? You are not alone, and having so many complicated options makes it hard to know where to start. fog delivers the knowledge of cloud experts to you, helping you to bootstrap your cloud usage and guiding you as your own expertise develops.
By coding with fog from the start you avoid vendor lock-in and give yourself more flexibility to provide value. Whether you are writing a library, designing a software as a service product or just hacking on the weekend this flexibility is a huge boon.
With a rapidly expanding community and codebase the advantages of fog just keep coming. Join us and together we will realize the future of cloud computing.

http://fog.io/0.11.0/

Wednesday, August 31, 2011

defunkt/jquery-pjax - GitHub

what is it?

pjax loads HTML from your server into the current page without a full reload. It's ajax with real permalinks, page titles, and a working back button that fully degrades.
pjax enhances the browsing experience - nothing more.
You can find a demo on http://pjax.heroku.com/

browser support

pjax only works with browsers that support the history.pushState API.
For a table of supported browsers see: http://caniuse.com/#search=pushstate
To check if pjax is supported, use the $.support.pjax boolean.
When pjax is not supported, $('a').pjax() calls will do nothing (aka links work normally) and $.pjax({url:url}) calls will redirect to the given URL.

Tuesday, August 2, 2011

Constructable

Provides a powerful class macro for defining and configuring constructable attributes of a class.

https://github.com/mkorfmann/constructable

Sunday, July 31, 2011

enumerated_attribute

Easily code enumerations for your models and expose them as drop-down lists with the enum_select helper, or use any of enumerated_attribute features to simplify coding enumerations in any Ruby object.

Typically, in Ruby, enumerated attributes are implemented with strings, symbols or constants. Often the developer is burdened with repeatedly defining common methods in support of each attribute. enumerated_attribute provides a DRY implementation for enumerations in Rails. Repetitive code such as initializers, accessors, predicate and enumeration methods are automatically generated along with the following features:
  • ActiveRecord integration
  • ActionView form helpers
  • Scaffold generator integration
  • Definable enumeration labels
  • Enum helper methods
  • Dynamic predicate methods
  • Initialization
  • State pattern support (enumerated_state)
https://github.com/jeffp/enumerated_attribute

Thursday, May 5, 2011

RubyGems 1.8.1

After installing RubyGems 1.8.1 you will see deprecations when loading your exsting gems. Run gem pristine --all --no-extensions to regenerate your gem specifications safely.
Currently RubyGems does not save the build arguments used to build gems with extensions. You will need to run gem pristine gem_with_extension -- --build-arg to regenerate a gem with an extension where it requires special build arguments.
  • 1 minor enhancement:
    • Added Gem::Requirement#specific? and Gem::Dependency#specific?
  • 4 bug fixes:
    • Typo on Indexer rendered it useless on Windows
    • gem dep can fetch remote dependencies for non-latest gems again.
    • gem uninstall with multiple versions no longer crashes with ArgumentError
    • Always use binary mode for File.open to keep Windows happy
    http://blog.segment7.net/2011/05/05/rubygems-1-8-1

    Tuesday, February 22, 2011

    vestal_versions for Rails 3

    acts_as_versioned by technoweenie was a great start, but it failed to keep up with ActiveRecord’s introduction of dirty objects in version 2.1. Additionally, each versioned model needs its own versions table that duplicates most of the original table’s columns. The versions table is then populated with records that often duplicate most of the original record’s attributes. All in all, not very DRY.
    vestal_versions requires only one versions table (polymorphically associated with its parent models) and no changes whatsoever to existing tables. But it goes one step DRYer by storing a serialized hash of only the models’ changes. Think modern version control systems. By traversing the record of changes, the models can be reverted to any point in time.

    Wednesday, November 24, 2010

    Wirble: Tab-Completion and Syntax Coloring for irb

    Wirble
    If you haven't got tab-completion and syntax coloring in your irb, you owe it to yourself to follow these instructions right away (should work for Linux, OS X, and Cygwin users). First, install the Wirble gem:
    sudo gem install wirble
    Next, create or edit a file called .irbrc in your home folder (~/.irbrc), and make sure these lines are included there:
    require 'rubygems'
    require 'wirble'
    Wirble.init
    Wirble.colorize
    Now play with irb and see joy similar to that in the screenshot above. Try tab-completion too. It's great!

    Monday, November 8, 2010

    Social Stream

    Social Stream is a plugin for Ruby on Rails. It provides your application with social networking features and activity streams.

    Social networking

    Social networks are a new paradigm on web application design. Social networking platforms stand among the most popular websites, while many content oriented applications are supporting social networking features in order to improve engagement, enhance user awareness and stimulate communities around the website.
    Social Stream is based in Social Network Analysis concepts and methods, including social entities (actors), ties and relations. It also provides a new tie-based access control model.

    Activity Streams

    Activity Streams is a format for syndicating social activities around the web. It has already been adopted by some of the major social networking platforms.
    Social Stream provides a database schema based on the Activity Streams specification, leading your application towards a well-known compatible data model design.

    Installation

    Add to your Gemfile:
    gem 'social_stream'
    and run:
    bundle update
    Then, execute:
    rails generate social_stream:install
    This will generate the following:
    • A jquery:install generation for jQuery support
    • A devise:install generation for authentication support
    • An initializer configuration file for Social Stream.
    • A database seeds file for defining Social Stream relations, along with an entry
    in db/seeds.rb to load it.
    • A new application layout
    • A migration providing the database schema
    Do not forget to migrate and seed your database
    rake db:migrate
      rake db:seed
     
    http://rubydoc.info/gems/social_stream/0.1.0/frames
    

    Tuesday, October 5, 2010

    Using acts_as_archive instead of soft delete

    For the application I am working on right now, the ability to restore content that has been deleted is one of the requirements. A lot of people would just go ahead and add acts_as_paranoid or is_paranoid and be done with it, but I've had trouble with that approach before.
    I've been reading a lot about the trouble with "soft deletes" (flagging a record as deleted instead of deleting it). Using a plugin that monkey patches ActiveRecord can go a long way towards fixing thesee problems, but it's a leaky abstraction and will bite you in the ass in unexpected ways. For example, all your uniqueness validations (and indexes) become much more complicated.
    That's why Jeffrey Chupp decided to kill is_paranoid and Rick Olson doesn't use acts_as_paranoid any more.
    There are other problems too. If you delete a lot of records, and you keep them in the same table, your table can get quite large, and all your queries slow down. At this point you have to use partitioning or partial indexes to get acceptable performance.

    Alternatives to soft delete

    In my reading, I found two alternatives to soft delete to be compelling.
    The first was the suggestion to properly model your domain. Why do you want to delete a record? What does that mean? Udi Dahan puts it this way:
    Orders aren’t deleted – they’re cancelled. There may also be fees incurred if the order is canceled too late.
    Employees aren’t deleted – they’re fired (or possibly retired). A compensation package often needs to be handled.
    Jobs aren’t deleted – they’re filled (or their requisition is revoked).
    Keeping that in mind, what if the task at hand really is to delete the record? The other idea that I liked was to archive the records in another table.
    The first Rails plugin I came across that implemented this was acts_as_soft_deletable which besides being misnamed doesn't appear to be actively maintained. The author even disavows the plugin somewhat for Rails 2.3:
    Before using this with a new Rails 2.3 app, you may want to consider using the new default_scope feature (or named_scopes) with a deleted_at flag.
    Then I found acts_as_archive which is more recently maintained and used in production for a major Rails website.
    There was only one problem -- acts_as_archive didn't support PostgreSQL. Fortunately, that was easy enough to fix.

    Restoring deleted records with acts_as_archive

    acts_as_archive has the ability to restore a deleted record, but only that record, not associated records.
    I was troubled by this at first, but after thinking about it I came to the conclusion that restoring a network of objects is an application-dependant problem. Here's one way to achieve it.
    Imagine you have a model like this, with Posts having many Comments and Votes.
    Post model
    A Post can be deleted, and when it is, it should take the Comments and Votes with it:
    class Post
      acts_as_archive
    
      has_many :votes, :dependent => :destroy
      has_many :comments, :dependent => :destroy
    end
    
    (Assume Comment and Vote also have acts_as_archive.)
    Now, I can restore a Post with its associated Votes and Comments like this:
    def self.restore(id)
      transaction do
        Post.restore_all(["id = ?", id])
        post = Post.find(id)
    
        Vote.restore_all(Vote::Archive.all(:conditions => ["post_id = ?", id]).map(&:id))
        Comment.restore_all(Comment::Archive.all(:conditions => ["post_id = ?", id]).map(&:id))
      end
    
    In my real code, I've broken apart the two pieces of this into a class method restore and an instance method post_restore which the freshly restored object uses to find its associated records and restore them. post_restore also takes care of post-restore tasks like putting the object back in the Solr index.
    This all works great. But now let's say Comments can be deleted individually, and we want to restore them.
    Here the logic is a little different, because a Comment can't be restored unless its parent Post still exists (unless it's being restored by the Post, as above).
    I take care of this logic in the administrative controller, by only showing child objects that it's valid to restore, and my foreign key constraints prevent anyone from getting around that.

    I really wanted to delete that!

    Sometimes you don't want to archive a deleted object. For example, in the application I'm working on, votes are canceled by re-voting. I don't want to save those votes -- there's no point, and it can even cause problems with restoring. Imagine having several archived votes from a user for a Post, and then deleting and restoring that Post. The restoration will try to bring back all the votes. Again, I catch this with a uniqueness constraint, but I don't want it to happen in the first place.
    Fortunately acts_as_archive has me covered.
    To destroy a record without archiving it, you can use destroy!. Likewise for deleting, there is delete_all!.

    http://railspikes.com/2010/2/26/acts-as-archive?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+RailSpikes+%28Rail+Spikes%29

    Sunday, October 3, 2010

    SlowGrowl

    Rails 3 plugin which surfaces slow code paths in your Rails application by integrating with the new Notifications API in Rails 3 with your system Growl (OSX) or libnotify (Linux) notification service. By default, any activity which takes longer than one second, will generate a growl alert, with the description of the action, time taken, and other meta data. A preview in action:
    slowgrowl notification

    http://github.com/igrigorik/slowgrowl

    Monday, August 9, 2010

    To defeat Rails' conspiracy to have you not use the JSON gem.
    See activesupport-2.3.8/lib/active_support/json/encoding.rb line 92 gRRRRRRRRRRRRRRRR!!!
    Call UseJsonGemInRails.save_json_gem_to_json in your RAILS_ROOT/config/preinitializer.rb file.
    Then set up an initializer and call UseJsonGemInRails.reload_json_gem_to_json in it.

    class UseJsonGemInRails
      class << self
        def save_json_gem_to_json
          require 'json'
          classes.each do |klass|
            klass.class_eval do
              alias_method :to_json_from_gem, :to_json
            end
          end
        end
        def reload_json_gem_to_json
          (classes + [ActiveSupport::JSON::Variable]).each do |klass|
            klass.class_eval do
              alias_method :to_json, :to_json_from_gem
            end
          end
        end
        def classes
          [
            Object,
            Hash,
            Array,
            String,
            Numeric,
            Float,
            Integer,
            Regexp,
          ]
        end
      end
    end

    http://gist.github.com/461938

    Friday, July 30, 2010

    Scraping with style: scrAPI toolkit for Ruby

    There’s a lot of ways to scrape HTML.
    There’s regular expression, they deal well with text. But HTML is not just text, it’s markup. So you have to deal with elements that are implicitly closed, or out of balance. Attributes are sometimes quoted, sometimes not. Nested lists and tables are a challenge. Good regular expressions take a lot of time to write, and are impossible to read.
    Or you can clean up the HTML with Tidy, get a DOM and walk the tree. The DOM is much easier to work with, it’s a clean markup with a nice API. But you have to do a lot of walking to find the few elements you’re scraping. That’s still too much work.

    Monday, July 19, 2010

    Whenever

    Whenever is a Ruby gem that provides a clear syntax for defining cron jobs. It outputs valid cron syntax and can even write your crontab file for you. It is designed to work well with Rails applications and can be deployed with Capistrano. Whenever works fine independently as well.
    Ryan Bates created a great Railscast about Whenever: railscasts.com/episodes/164-cron-in-ruby
    Discussion: groups.google.com/group/whenever-gem

    http://github.com/javan/whenever
     

    Wednesday, July 14, 2010

    Making urls look memorable

    Bluga.net WebThumb provides a white-label web service API for generating web thumbnails and full size snapshots of websites.
    WebThumb offers more features and quicker response times then any other service.
    • Real-time thumbnails
    • Flash 10 Support
    • PDF Support
    • Quick response times
    • REST API
    • API clients for PHPRubyPython
    • Cache the thumbnails on your server or Webthumbs
    • Browser windows from 75x75 to 1280x2048
    http://snippets.dzone.com/posts/show/3621
    http://www.paulhammond.org/webkit2png/
    http://stackoverflow.com/questions/726660/how-do-i-make-beautiful-screenshots-of-web-pages-using-ruby-and-a-unix-server
    rbwebkitgtkhttp://github.com/danlucraft/rbwebkitgtk/tree/master

    Moz snap shooterhttp://www.lilik.it/~mirko/Ruby-GNOME2/moz-snapshooter.rb
    http://www.hackdiary.com/2004/06/13/taking-automated-webpage-screenshots-with-embedded-mozilla/

    Selenium RC has a Ruby interface and can grab a screenshot using: http://release.seleniumhq.org/selenium-remote-control/1.0-beta-2/doc/ruby/classes/Selenium/Client/GeneratedDriver.html#M000220

    PageGlimpse is a service providing developers with programatic access to thumbnails of any web page. The thumbnails can be virtually used in any kind of applications that require the display of website screenshots: web sites, windows/linux/mac applications, iPhone/mobile utilities, browser plugins, etc. 
    Including web site thumbnails in your application will dramatically improve the user experience. The service is easy to use, fast and reliable, no restriction on thumbnail sizes or number of hits. Click here to see how it works.
    http://www.pageglimpse.com/



    Monday, June 14, 2010

    Deep_merge: Ruby Recursive Merging for Hashes

    Ruby provides some nice merge capabilities in hash and array. But it rightly doesn’t give us recursive merging, because it’s too poorly defined to standardize. However, recursive merging sometimes solves problems that can’t be solved other ways.
    Take this code:
    h1 = {:x => {:y => [4,5,6], :z => [7,8,9]}}
    h2 = {:x => {:y => [1,2,3], :z => 'xyz'}}
    If you want to merge these two hashes, what should happen? Well there are several possibilities. Let’s see how deep_merge handles it:
    h2.deep_merge!(h1)
    # results: h2 = {:x=>{:z=>[7, 8, 9], :y=>[1, 2, 3, 4, 5, 6]}}
    # notice we overwrote 'xyz'! (That's what the bang means)
    # Let's try it without the bang:
    h1 = {:x => {:y => [4,5,6], :z => [7,8,9]}}
    h2 = {:x => {:y => [1,2,3], :z => 'xyz'}}
    h2.deep_merge(h1)
    # results: h2 = {:x=>{:z=>"xyz", :y=>[1, 2, 3, 4, 5, 6]}}
    # notice 'xyz' didn't get overwritten this time. No bang.
    Let’s get a little more complicated with a “knockout” merge. We introduce a special string “–” which can “knockout” an element in an existing hash or array element:
    h1 = {:x => {:y => ["d","e","--c"]}}
    h2 = {:x => {:y => ["a","b","c"]}}
    h2.ko_deep_merge!(h1)
    # h2 = {:x=>{:y=>["a", "b", "d", "e"]}}
    # notice no "c" any more!
    Many of these features are configurable to your needs – feel free to read up in the source code. Home page and installation instructions are here: http://trac.misuse.org/science/wiki/DeepMerge

    http://www.misuse.org/science/2008/05/19/deep_merge-ruby-recursive-merging-for-hashes/

    Monday, June 7, 2010

    BackgrounDRb

    BackgrounDRb is a Ruby job server and scheduler. Its main intent is to be used with Ruby on Rails applications for offloading long-running tasks. Since a Rails application blocks while serving a request it is best to move long-running tasks off into a background process that is divorced from http request/response cycle.

    http://backgroundrb.rubyforge.org/

    Monday, April 26, 2010

    DrX


    DrX, the good doctor, is a small object inspector for Ruby.
    DrX is for newbies and gurus alike.
    Instead of focusing on the contents of your object, DrX instead focuses on its object model. As a result, DrX is most suitable for programmers wishing to understand Ruby's object model better. It's especially adept at showing you how a "magical" library works (e.g., DataMapper).

    Key features:

    • See everything about a Ruby object: its 'klass', 'super', 'iv_tbl', 'm_tbl'. See your singletons with your very own eyes!
       
    • Double-click a method to launch an editor and position the cursor on the exact line where the method is defined!

    Installation

    At your system prompt type:
    gem install drx

    Requirements 

    require 'drx'
    Errors and solutions:
    1. MissingSourceFile: no such file to load -- tk
      - require 'tcltklib' (install Tcl/Tk interface for Ruby)
    2. RuntimeError: TkPackage can't find package tile
      - install themed widget set provider library for Tk
    3. RuntimeError: ERROR: Failed to run the 'dot' command. Make sure you have the GraphViz package installed and that its bin folder appears in your PATH.
      - install rich set of graph drawing tools (
      GraphViz)

    Thursday, March 25, 2010

    Monitoring delayed_job with bluepill

    Bluepill is a pure-ruby process monitoring library similar to god/monit. Unlike god, bluepill doesn’t leak memory (according to the bluepill authors anyway :] .)

    To set up delayed_job, please have a look at this asciicast (note that you should use the collectiveidea-delayed_job fork for this!)

    http://rails.co.za/2009/11/14/monitoring-delayed-job-with-bluepill.html

    Thursday, March 11, 2010

    Enigmamachine

    Enigmamachine is a video processor which queues and encodes videos according to target profiles that you define. Videos must be on a locally mounted filesystem. The processor takes the path to the video, and executes multiple ffmpeg commands on the video. There is a handy web interface for defining encoding tasks, and a restful web service which takes encoding commands.

    Enigmamachine is written using Sinatra, Thin, and Eventmachine.

    http://github.com/futurechimp/enigmamachine