• Home

  • Custom Ecommerce
  • Application Development
  • Database Consulting
  • Cloud Hosting
  • Systems Integration
  • Legacy Business Systems
  • Security & Compliance
  • GIS

  • Expertise

  • About Us
  • Our Team
  • Clients
  • Blog
  • Careers

  • VisionPort

  • Contact
  • Our Blog

    Ongoing observations by End Point Dev people

    Rails Recursive Sorting for Multilevel Nested Array of Objects

    Selvakumar Arumugam

    By Selvakumar Arumugam
    October 6, 2014

    Whenever you display data as a list of records, sorting them in a particular order is recommended. Most of the time, Rails treats data as an array, an array of objects, or as a nested array of objects (tree). We would like to use a general sorting mechanism to display the records in ascending or descending order, to provide a decent view to end users. Luckily, Rails comes with a sorting method called ‘sort_by’ which helps to sort the array of objects by specific object values.

    Simple Array:

    Trivially, an array can be sorted just by sorting using the “sort” method:

    my_array = [ 'Bob', 'Charlie', 'Alice']
    
    my_array = my_array.sort;  # (or just my_array.sort!)
    

    This is the most basic way to sort elements in an array and is part of Ruby’s built-in API.

    Array of Objects:

    Usually, the result set of the Rails will have an array of objects and should be sorted based on specific attributes of the object in the array. Here is a sample array of objects which need to be sorted by date and fullname.

    s_array =
    [  
        {
            "date"=> "2014-05-07",
            "children"=> [],
            "fullname"=> "Steve Yoman" …

    ruby rails

    Liquid Galaxy at UNC Chapel Hill

    Dave Jenkins

    By Dave Jenkins
    October 3, 2014

    End Point has brought another academic Liquid Galaxy online! This new display platform is now on the storied campus of University of North Carolina - Chapel Hill. With a strong background in programming and technology, UNC wanted a premiere interactive platform to showcase the GIS data and other presentations the school researchers are putting together.

    Neil Elliott, our hardware manager for Liquid Galaxy, first assembled, preconfigured, and tested the computer stack at our facility in Tennessee, bringing together the head node, display nodes, power control units, switches, and cases to build a “Liquid Galaxy Express”: an entirely self-contained Liquid Galaxy unit that fits in just under 1-meter cubed. From there, Neil drove the computers and custom-built frame directly to Chapel Hill. Our install manager Neil described it as: “It’s a great drive from our office in Tennessee over the mountains to Chapel Hill. When I arrived, the UNC staff was on-hand to help assemble things, lay out the space, and it all went very quickly. We were live by 4pm that same day.”

    Overall, the installation took just over 6 hours, including assembly and final configuration. The University’s library …


    visionport

    Parsing Email Addresses in Rails with Mail::Address

    Patrick Lewis

    By Patrick Lewis
    October 3, 2014

    I’ve recently discovered the Mail::Address class and have started using it for storing and working with email addresses in Rails applications. Working with an email address as an Address object rather than a String makes it easy to retrieve different parts of the address and I recommend trying it out if you’re dealing with email addresses in your application.

    Mail is a Ruby library that handles email generation, parsing, and sending. Rails’ own ActionMailer module is dependent on the Mail gem, so you’ll find that Mail has already been included as part of your Rails application installations and is ready for use without any additional installation or configuration.

    The Mail::Address class within the library can be used in Rails applications to provide convenient, object-oriented ways of working with email addresses.

    The class documentation provides some of the highlights:

    a = Address.new('Patrick Lewis (My email address) <patrick@example.endpoint.com>')
    a.format       #=> 'Patrick Lewis <patrick@example.endpoint.com> (My email address)'
    a.address      #=> 'patrick@example.endpoint.com
    a.display_name #=> 'Patrick …

    email rails

    MediaWiki minor upgrade with patches

    Greg Sabino Mullane

    By Greg Sabino Mullane
    October 2, 2014

    One of the more mundane (but important!) tasks for those running MediaWiki is keeping it updated with the latest version of the software. This is usually a fairly easy process. While the offical upgrade instructions for MediaWiki are good, they are missing some important items. I will lay out in detail what we do to upgrade MediaWiki installations.

    Note that this is for “minor” upgrades to MediaWiki, where minor is defined as not moving more than a couple of actual versions, and not requiring anything other than patching some files. I will cover major upgrades in a future post. For this article, I assume you have full shell access, and not simply FTP, to the server that MediaWiki is running on.

    The first step in upgrading is knowing when to upgrade - in other words, making sure you know about new releases. The best way to do this is to subscribe to the low-volume mediawiki-announce mailing list. The MediaWiki maintainers have a wonderful new policy of sending out “pre-announcement” emails stating the exact time that the new version will be released. Once we see that announcement, or when the version is actually released, we open a support …


    mediawiki

    RSpec’s Anything Argument Matcher Trickery

    Brian Gadoury

    By Brian Gadoury
    September 29, 2014

    If you’re like me, and I know I am, then you’ve used RSpec’s “anything” argument matcher to test that a method is getting called with the expected arguments. If you haven’t, then I strongly recommend you check it out. Here’s a basic example:

    expect(object).to receive(:message).with(:foo, anything)
    

    That test will pass if object.message() is called with :foo as its first argument, and any non-nil value as its second argument. The “anything” matcher can be used anywhere in the argument list, as well as multiple times. For example:

    expect(object).to receive(:message).with(anything, :bar, anything)
    

    That test will pass if object.message() is called with a non-nil value for its first argument, :bar for its second argument, and any non-nil value for its third argument.

    I recently made one of those discoveries where the happiness of making the discovery quickly turned into the sneaking suspicion that I was actually the last person on the planet to make this discovery. So, I told a co-worker about my discovery. She hadn’t heard of it before, which meant at worst I was the second to last person on the planet. “There could be others,” I thought. “I must set alight our grail shaped beacon!” And …


    ruby rails testing

    Using jQuery Migrate plugin

    Marina Lohova

    By Marina Lohova
    September 26, 2014

    We all know these tricky situations, like introducing a new feature on top of old code, when it seems we’re about to step into a tedious swamp of workarounds and dirty hacks. Fortunately, jQuery Migrate plugin is here to make these situations easier, at least in JavaScript. So for any of you who wondered about a real-life example of using jQuery Migrate plugin I have one!

    My task was to add an editable combomonster, oh sorry, combobox (even though editable comboboxes remind me of UX Frankenstein’s Monster, they are still requested a lot) to a rather old website built on jQuery v1.4.2.

    I downloaded the most recent jQuery UI (at that time it was v1.10.4) and a very neat editable combobox component to go with it. It was expected that it wouldn’t work out of box with the rather outdated jQuery we had. It didn’t work and the page produced the following JavaScript error:

    TypeError: t.cssHooks is undefined
    
    ...t(" ");f(i,function(e,i){t.cssHooks[i]={set:function(e,n){var a,o,r="";if("trans...
    

    No problem, I grab the newer compatible jQuery v1.10.2 from the website and yield it into head in that particular page.

    <% content_for  :head do %>
      javascript_include_tag …

    javascript jquery

    Solving pg_xlog out of disk space problem on Postgres

    Greg Sabino Mullane

    By Greg Sabino Mullane
    September 25, 2014


    pg_xlog with a dummy file
    (image by Andrew Malone)

    Running out of disk space in the pg_xlog directory is a fairly common Postgres problem. This important directory holds the WAL (Write Ahead Log) files. (WAL files contain a record of all changes made to the database—​see the link for more details). Because of the near write‑only nature of this directory, it is often put on a separate disk. Fixing the out of space error is fairly easy: I will discuss a few remedies below.

    When the pg_xlog directory fills up and new files cannot be written to it, Postgres will stop running, try to automatically restart, fail to do so, and give up. The pg_xlog directory is so important that Postgres cannot function until there is enough space cleared out to start writing files again. When this problem occurs, the Postgres logs will give you a pretty clear indication of the problem. They will look similar to this:

    PANIC:  could not write to file "pg_xlog/xlogtemp.559": No space left on device
    STATEMENT:  insert into abc(a) select 123 from generate_series(1,12345)
    LOG:  server process (PID 559) was terminated by signal 6: Aborted
    DETAIL:  Failed process was running: insert into abc(a) select …

    postgres

    Some metaprogramming examples from RSpec

    Miguel Alatorre

    By Miguel Alatorre
    September 25, 2014

    I’m quite the curious cat and one thing that has interested me for a while has been how RSpec and its describe and it methods work. In digging through the rspec-core gem source code (v3.1.4), specifically the example_group.rb file, I came across some syntax that I had not been exposed to:

    # https://github.com/rspec/rspec-core/blob/v3.1.3/lib/rspec/core/example_group.rb
    
    module RSpec
      module Core
        class ExampleGroup
          # ...
    
          def self.define_singleton_method(*a, &b)
            (class << self; self; end).__send__(:define_method, *a, &b)
          end
    
          # ...
    
          def self.define_example_method(name, extra_options={})
            define_singleton_method(name) do |*all_args, &block|
    
              # ...
    
            end
          end
    
          # ...
    
          define_example_method :it
    
          # ...
    
        end
      end
    end
    

    “What’s with all this passing around of blocks? And what’s :define_method doing?” I asked. The documentation for the define_method is straightforward enough, yet I still wondered what was being accomplished in the code above. In pursuit of answers, here’s what I found out.

    Metaprogramming

    Metaprogramming is the writing of code that acts on other code instead of …


    ruby testing
    Previous page • Page 90 of 220 • Next page