Skip to content

Instantly share code, notes, and snippets.

@craigmartin
Created August 2, 2011 19:24
Show Gist options
  • Save craigmartin/1120978 to your computer and use it in GitHub Desktop.
Save craigmartin/1120978 to your computer and use it in GitHub Desktop.
answers
# In Ruby...
#
# 1) Sum up 1 to 100
# sum = (1..100).inject(0){|cummulative,n| cummulative+n}
# puts sum
#
# 2) Using TestUnit, test #1
# Please see this Gist: git://gist.github.com/1120032.git
#
# 3) What's the difference between including a module & extending a module?
# When you include a module, you are including a module's implementation in any object.
# We also call these mixins which translates to mixing in a module's behaviors into our objects.
#
# When you extend a module, you are adding the methods of that specific module into the object instance you call "extend".
# So the methods of that module will only be available at that specific instance, other objects of the same class
# will not have the methods of the module available to them.
#
# Gotchas: Ruby has no method overloading mechanism so two rules: if a method being included is already defined
# in the class then the method in the class has presedence, If two modules define a method with the same name,
# then the method on the last module will be available to the class that included both modules.
#
# 4) What's the other construct in Ruby that's like a Proc?
# Show an example with a Rails controller before filter.
# blocks are Procs that can't be saved.
# blocks should be used as one-time solutions. note- if 2 or more closures are being passed, use a Proc.
# -- for more details please see this Gist: git://gist.github.com/1114742.git
#
# class HomeController < ApplicationController
# # use code block as filter
# before_filter do |controller|
# controller.send(:intruder?) # call intruder? method in the controller
# ...
# end
#
# def intruder?
# ...
# end
# end
#
# another example:
# class WeblogController < ActionController::Base
# before_filter { |controller| head(400) if controller.params["stop_action"] }
# end
#
# 5) What's the javascript equivalent of a Proc?
# Anonymous Functions are the js equivalent of a Proc.
#
# 6) Write a jQuery plugin that short circuits (link does not load)
# the links on a page & writes out the href to the console
#
# use the "preventDefault" method. = Please see list of gists at the bottom.
#
# 7) Explain from a high level how you would handle bulk loading of
# "widgets" from a dealer? A widget has a name, weight, price & wholesale price.
# A widget's wholesale price is optional.
#
# The goal will be to create a REST based API that is exposed internally as well as at least partially externally via a simple web front end.
# Users will be able to interact with the API programatically or through the web interface to create jobs for creating and uploading widgets,
# collections of data. Upon upload to the server the widgets (data) will be converted to JSON objects to be stored in a MongoDB. Server side a
# script, perhaps a ruby script or rails app, will execute instructions including error handling, validation, looping and data segmentation/collection
# in preparation for a mongoImport job as soon as more than 100 but less than 200 records/JSON objects are collected.
# Assumptions and questions required for success:
# Strong error handling within the application.
# Integration of Node.js or comet for long-polling processes, given very large bulk tasks.
# HTML5 or CouchDB solution to accomodate offline access or network connection drops.
# Enable deep logging and monitoring with integrated process to retry failed records.
# Process record in parallel? Again given very large bulk tasks.
# I would also consider a head-to-toe JavaScript solution using Node.js/JSON/and Mongo or Couch. One advantage with Couch is its ability to be embedded into apps.
#
# 8) What's the difference between a string & a symbol and why
# might you use one over the other?
# A string object holds and manipulates a sequence of bytes and is mutable and can be changed after assignment.
# Symbols are immutable so have to be overwritten to be changed.
#
# We use a symbol if the identity of an object is important.
# We use a string if the contents or the sequence of characters of an object are important.
# notes:
# Symbols are very useful when we're creating hashes with a need for distinction between keys and values.
# Symbols are more efficient when they can be used because they are a consistent name within code
# and are single reference values, initiated once. This saves memory.
# Since the release of 1.9 Symbols are no longer immediate objects and they aren't integer
# representations.
# A string typically represents characters.
#
# 9) Given the alphabet, print out "letter 1 is a, letter 2 is b..."
#
# short_enum = (1..26).to_enum
# long_enum = ('a'..'z').to_enum
#
# loop do
# puts "letter #{short_enum.next} is #{long_enum.next}"
# end
#
#
## Attachments / links to programs/and/or/extras:
#
# interview_answers.rb
# git://gist.github.com/1120978.git
#
# #1 answer:
# git://gist.github.com/1120034.git
#
# #2 answer: (Test/Unit for #1)
# git://gist.github.com/1120032.git
#
# #4 answer:
# git://gist.github.com/1120980.git -- answer
# git://gist.github.com/1114742.git -- extra info
#
# #6 answer:
# git://gist.github.com/1120069.git -- pre plugin
# git://gist.github.com/1121024.git -- as a plugin (coming soon)
#
# #9 answer:
# git://gist.github.com/1120956.git --- solution using print.
# git://gist.github.com/1120950.git --- solution using put for readability.
#
# A fairly recent jQuery plugin I did for social network links for a client:
# git://gist.github.com/1120023.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment