Skip to content

Instantly share code, notes, and snippets.

View rishiip's full-sized avatar
🎯
Focusing

Rishi Pithadiya rishiip

🎯
Focusing
View GitHub Profile
@rishiip
rishiip / first.html
Created February 7, 2015 19:10
Demo Gist
<h1><center>Rishi Pithadiya</center></h1>

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.

@rishiip
rishiip / hashes.md
Last active August 29, 2015 14:17 — forked from ryansobol/hashes.md

What's a Hash and why is it important?

A Hash is a collection of key-value pairs. To add, fetch, modify, and delete a value from a Hash, you refer to it with a unique key.

While an Array is indexed by Integers only, a Hash is keyed by any object -- Strings, Integers, etc.

In other programming languages, a Hash might be known as an 'associative array', 'dictionary', or 'HashMap'.

What does a Hash look like?

class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@rishiip
rishiip / arch.md
Last active August 29, 2015 14:23 — forked from mislav/arch.md

Create the partition:

sgdisk --zap-all /dev/sda
cgdisk /dev/sda
mkfs.ext4 /dev/sda1
mount /dev/sda1 /mnt

Edit the mirror list to bring the preferred mirror to the top:

@rishiip
rishiip / server.rb
Last active August 29, 2015 14:25 — forked from emad-elsaid/server.rb
require 'webrick'
Port = 3000
Directory = Dir::pwd
WEBrick::HTTPServer.new(
Port: Port,
DocumentRoot: Directory
).start
@rishiip
rishiip / nil_empty_blank_present_ffdierence_in_ruby
Last active December 8, 2015 10:56 — forked from pythonicrubyist/nil_empty_blank_present_ffdierence_in_ruby
Difference between nil?, empty?, blank? and present? in Ruby and Ruby on Rails.
# nil? can be used on any Ruby object. It returns true only if the object is nil.
nil.nil? # => true
[].nil? # => false
{}.nil? # => false
"".nil? # => false
" ".nil? # => false
true.nil? # => false
# empty? can be used on some Ruby objects including Arrays, Hashes and Strings. It returns true only if the object's length is zero.
nil.empty? # NoMethodError: undefined method `empty?' for nil:NilClass
@rishiip
rishiip / gist:bd36c65f85031e66ee56
Created December 8, 2015 11:08 — forked from mistrikushal/Rspec private methods.txt
RSpec - Testing private methods of a model
# RSpec allows us to test private methods of a model.
for example,
class User
def is_active?
true
end
private :is_active?
end
def get_array_max(one_dim_array)
one_dim_array.inject([0, 0]) do |(max_so_far, max_up_to_here), x|
new_max_up_to_here = [max_up_to_here + x, 0].max
new_max_so_far = [max_so_far, new_max_up_to_here].max
[new_max_so_far, new_max_up_to_here]
end.first
end
sample = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
p get_array_max(sample)
@rishiip
rishiip / bson.rb
Created March 10, 2016 06:11 — forked from rishi-amura/bson.rb
Return mongo `_id` bson object as regular `id` within Rails application
Save below code to `bson.rb` file within `config/initializers` directory and restart the server
module BSON
class ObjectId
def as_json(*args)
to_s
end
end
end