Sunday, March 19, 2017

Rails Deployment Without

30/52 - Step(s)
30/52 - Step(s) (Photo credit: whatmattdoes)
A while back I had to deploy a Rails app to a remote machine without access to the Internet.  That means the gem and bundle commands are unable to download gems from

Fortunately, you can upload gem files and install them from the current directory.

gem install -f -l *.gem

When you run bundler in your app's root directory, tell it to use gems that are already locally installed:

bundle install --local

But if you put your gems are in the vendor/cache directory, no need to --install.  Bundler looks in vendor/cache first.

Uploading works when both machines have the same OS.  But what if the target machine is a different platform?  Maybe you develop on Mac OS, but deploy on Linux.

Fortunately, the  gem install command lets you specify what platform to target with the "--platform" option

gem install rails --platform x86_64-linux -i vendor/cache
Note that an install directory is specified with the "-i" option.  This puts the new gems in a specific directory rather than overriding the gems you want to keep using in your development environment.

You'll need to determine the platform of the target machine.  Its the second half of the colon-separated string returned with this command.

$ gem env platform

This gem install command needs to be executed for every gem mentioned in your app's Gemfile.  All the gems these are dependent on will get installed in the process.

To execute the install command for the exact version of each dependency, execute this code from the rails console for the application:

where = "~/apps/tardir"
x ={|d|}
y = do |s|
  if x.include? 
    system "sudo gem install #{} -v #{s.version}#{s.git_version}\
    --platform x86_64-linux -i #{where} --no-rdoc --no-ri"

How you get your gems to the production machine will depend on how you deploy.  At some point your deployment will need to install the gems on the linux machine with this command:

gem install --force --local *.gem --no-rdoc --no-ri

When deployment is happening on a regular basis, gems can change as new features are implemented.  You'll probably want to run the code above periodically.

Friday, February 22, 2013

Partition and Splat in Quick Sort

The Ruby Array has a partition method that takes a block and returns an array of elements for which the block evaluates to true, and a second array of elements for which the block evaluates to false.

This method can be used in a quick sort, which involves selecting one element to be a pivot and putting all other elements into either a "less than" array or "greater than" array and sorting each other those the same way.

This is a recursive sort, which means it calls itself.

def quick_sort number_array
  return number_array unless number_array.size > 1
  pivot, *the_rest = number_array
  less, more = the_rest.partition { |number| number < pivot }
  quick_sort(less) + [pivot] + quick_sort(more)

this_array = [22,66,4,44,5,7,6,8,77,33,8,99,6]

puts "unsorted: #{this_array.inspect}"

puts "sorted: #{quick_sort(this_array).inspect}"

Also interesting is the splat operator (the asterisk), which enables the new variable to take more than one parameter.  When an array is assigned to multiple variables, the splat operator allows an item to take enough elements to make the assignment work.  Above it is assigning one element to be the pivot and the rest to be partitioned.

When defining a method, the splat operator can be used with one of the parameters, enabling it to accept multiple parameters as an array.  Although it can be anywhere in the parameter list, using splat on the final parameter is preferred because extra parameters will all go into the array instead of changing how other parameters are assigned.

As used above, elements are used arbitrarily so the order doesn't matter as long as the_rest gets all but the element assigned to pivot.  I guess you could think of the left side of the assignment as the method definition's parameter list and the right as a call to that method.

Friday, September 14, 2012

Fixed vs. Growth Mindset

You are, indeed, stretchable....

Sunday, July 17, 2011

Learning Git

Scott Chacon: Getting GitImage by fraserspeirs via FlickrTo learn a challenging topic, first find someone who knows both the topic and how to teach.  For git, Scott Chacon is one of those guys.  Scott is a Rails developer working for github, THE place to host your open source git repository.  Here's Scott:

I recommend trying everything discussed yourself as the video progresses, stopping when you need more time or need to google what you don't understand.
Enhanced by Zemanta

Friday, July 8, 2011

Become a Learning Machine

BinaryImage by Xerones via FlickrIf you find your education lacking, its now easier than ever to learn your way out of it. Universities all over the world put their lectures online. You can find one that teaches the topic of interest in a way that works for you.

And if you don't understand something, you can STOP the lecture and google it until you do. Replay the few seconds of video to make sure you heard it right. Do whatever it takes. You're in control.

Become a learning machine. Then no one can stop you.

Case in point. I lack a computer science background and get stumped when asked about basic software engineering concepts like sorting algorithms.  And I'm a software engineering. Or at least I play one on TV. :-)

So I finally decided to do something about it. I've found several courses on the topic. Here's a great one from Australia:

All the world's knowledge is being made accessible to you. Seize the opportunity!
Enhanced by Zemanta

JavaScript Semicolon Insertion

Code reviewImage by richardmasoner via FlickrHere's a good discussion of when a Javascript developer should use semicolons.

Basically, semicolons are statement separators and there are situations where a line break won't be interpreted as the end of a statement.

Many Javascript developers put them at the end of every line, but this is unnecessary.  Its better to actually understand the cases where a line break won't end a statement.

If you use a minification tool that doesn't interpret line breaks correctly, bugs could be introduced.  But if you use semicolons only where you need to, a bad tool will probably break most things right away. And that will be obvious.  Use semicolons ALMOST everywhere and then you won't discover the problems until you test specific lines that don't have them.
Enhanced by Zemanta

Saturday, April 17, 2010

Color Tools That Will Make Your Web Shine

Creative Arts Matthew Boulton CollegeImage by jisc_infonet via Flickr

Haven't checked all of them out yet, but it looks like a very useful list of color tools.

I'm creating a new resume tool and looking for something that will let me find a professional color scheme.
Reblog this post [with Zemanta]