Updates from August, 2014 Toggle Comment Threads | Keyboard Shortcuts

  • ThomasPowell 5:47 pm on August 29, 2014 Permalink
    Tags: hdtv, over the air   

    The Mohu Leaf worked so well, I upgraded to a Mohu Sky 

    Ok, I had the Mohu Leaf working for almost the entire house using the DirecTV cable in and with 2 indoor antenna amplifiers on the HDTVs. The signal was almost strong enough just by putting it against the side of the house facing the station antennae (according to AntennaWeb, even though we’re about 20 miles out from the station broadcasts. One downside was that the paper thin design was too prone to being blown around by storms.

    Decided to upgrade to the Sky and have it “mounted” on the inside of our privacy fence (with open air in the direction of the antennae). I plugged the amp into the 4-way splitter and removed all other amps. We’re now even getting the obscure channels.

     
  • ThomasPowell 4:56 pm on August 14, 2014 Permalink
    Tags: refinements, , ruby2.0   

    Refinements in Ruby: in map: super: no superclass method 

    I was trying out refinements to see if they would help clean up some parsing code. I liked defining a couple of methods for the String class to respond to, but really didn’t want them as permanent monkey patches on String.

    And so, I had a pipe mapping module with refinements:

    module PipeMapping
      refine String do
        def only_lines_with_pipes
          self.lines.select { |s| s =~ /\|/ }
        end
        def pipes_to_array
          self.split('|').map(&:strip)
        end
      end
    end
    

    I added the following to my class to allow it to load itself:

      using PipeMapping
      def self.initalize_mappings
        data_to_load.only_lines_with_pipes.map(&:pipes_to_array).each do |mapping|
          # do stuff
        end
      end
    

    I got the following output:

    ...in `map': super: no superclass method `pipes_to_array' for "A|B|C\n":String (NoMethodError)
    

    The problem is that Symbol#to_proc will end up operating outside of the scope of the refinement using invocation, and will, therefore, have no knowledge of the method.

    A quick change to a block works:

      using PipeMapping
      def self.initalize_mappings
        data_to_load.only_lines_with_pipes.map{|s| s.pipes_to_array}.each do |mapping|
          # do stuff
        end
      end
    

    I’m still trying to decide if this is a satisfactory trade-off.

     
  • ThomasPowell 4:00 pm on August 11, 2014 Permalink
    Tags: generators, migrations,   

    rails (4) generate migration behaviors I forget to use 

    When I’m generating a migration, I usually don’t go any deeper than specifying column_name:data_type on the command line, and often I only use the command line to generate the file itself.

    I don’t know that the other options really save all that much typing, but stopping to think about the other options for a few seconds might just help avoid having to go back later and add things.

    Elementary things I don’t make enough use of:

    • rails g migration AddXXXtoYYY automatically creates an add_column for table YYY for every column name specified.
    • rails g migration RemoveXXXtoYYY automatically creates a remove_column for table YYY for every column name specified.
    • Specifying column_name:data_type:index also adds an index to the new column.
    • rails g migration CreateJoinTableXXXYYY will produce a join table.
     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel
%d bloggers like this: