Skip to content

Instantly share code, notes, and snippets.

View lukin-io's full-sized avatar
🏠
Working from home

Lukin Max lukin-io

🏠
Working from home
View GitHub Profile
@lukin-io
lukin-io / gist:154043cdb99d94ef6344
Created September 29, 2015 14:31 — forked from ryansobol/gist:5252653
15 Questions to Ask During a Ruby Interview

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

@lukin-io
lukin-io / sorts.rb
Last active September 16, 2015 13:11
Ruby - sorts, bubble_sort, insertion_sort, quicksort, mergesort
module Algorithms::Sort
# Bubble sort: A very naive sort that keeps swapping elements until the container is sorted.
# Requirements: Needs to be able to compare elements with <=>, and the [] []= methods should
# be implemented for the container.
# Time Complexity: О(n^2)
# Space Complexity: О(n) total, O(1) auxiliary
# Stable: Yes
#
# Algorithms::Sort.bubble_sort [5, 4, 3, 1, 2] => [1, 2, 3, 4, 5]
def self.bubble_sort(container)
@lukin-io
lukin-io / module.rb
Last active August 29, 2015 14:22
Ruby module hooks
module Fr
module Base
def self.included(base)
base.class_eval do
validate :validate_it
protected
def validate_it
return true if something?
end
  • Dynamic Dispatch
  • Dynamic Method
  • Ghost Methods
  • Dynamic Proxies
  • Blank Slate
  • Kernel Method
  • Flattening the Scope (aka Nested Lexical Scopes)
  • Context Probe
  • Class Eval (not really a 'spell' more just a demonstration of its usage)
  • Class Macros
@lukin-io
lukin-io / dsl
Created April 26, 2015 22:08
dsl
class User
attr_accessor :name, :pet_name
end
class Factory < BasicObject
def initialize
@attributes = {}
end
attr_reader :attributes
@lukin-io
lukin-io / fib
Created March 30, 2015 14:40
fib
def fib(n)
n < 2 ? n : fib(n-1) + fib(n-2)
end
@lukin-io
lukin-io / agent.rb
Last active August 29, 2015 14:17 — forked from regedarek/agent.rb
require 'faraday'
require 'forwardable'
module Soup
class Agent
extend Forwardable
def initialize(domain = 'https://www.soup.io/')
@agent ||= faraday(domain)
end
# I was considering how I might want to further implement my gem and incorporate configuration settings for it. I wanted only one instance of my configuration and it needed to be part of my module. So I’ve come up with a solution I like that allows me to do this and even have a true “sense” of untouchable constants.
# I’ve found OpenStruct to be for my liking in this situation as it allows for any configuration (variable) to be set on it. I’ve also found I can set “unalterable” variables… at least through standard assignment options.
# The reason I created the class MyProject::MyConfig just to inherit OpenStruct is that I want my configuration to be identified by a class name that indicates it is a config object that belongs to my project. In module MyProject I use attr_reader for config because we are getting the OpenStruct instance handed back to us and we can still invoke method/value assignment on it. I use the single class variable @config for the internal singleton value because it’s not going a
my_hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
@lukin-io
lukin-io / Gemfile
Last active August 29, 2015 14:10 — forked from jodosha/Gemfile
source 'https://rubygems.org'
gem 'rake'
gem 'lotus-router'
gem 'lotus-controller'
gem 'lotus-view'
group :test do
gem 'rspec'
gem 'capybara'