Skip to content

Instantly share code, notes, and snippets.

View mindaslab's full-sized avatar

Karthikeyan A K mindaslab

View GitHub Profile
array = [<<TEXT]
# ## ## ## ### ### ## # # ### ## # # # # # ### # ## # ##
## ### # # # # # # # # # # ### ###
# # # # # # # # # # # # # # # # # ### # # # # # # # # #
# # # # # # # # # # # # # # #
### ## # # # ## ## # # ### # # ## # ### # # # # ## # # ##
# # # # # # ### # # # ##
# # # # # # # # # # # # # # # # # # # # # # # # # # ## #
# # # # # # # ### # # # #
# # ## ## ## ### # ## # # ### # # # ### # # # # # # # #
def closest_to_zero(numbers)
numbers = numbers.split.map(&:to_i) if numbers.is_a? String
numbers.min_by {|t| [t.abs,-t]}
end
# lib/tasks/custom_seed.rake
namespace :db do
namespace :seed do
Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].each do |filename|
task_name = File.basename(filename, '.rb').intern
task task_name => :environment do
load(filename) if File.exist?(filename)
end
end
end
@mindaslab
mindaslab / manual_auth_devise.rb
Created February 8, 2016 06:09
Manually authentication in devise
class AuthController < ApplicationController
def auth
user = User.find_by(email: params[:email])
if user.valid_password? params[:password]
# user login is right
else
# user login is wrong
end
end
end
@mindaslab
mindaslab / count.rb
Created February 3, 2016 13:20
A program to do food count for Zanec
# count.rb
# A kinda array to hoistogram application
string = """
VEGETABLE BRIYANI, VEGETABLE FRIED RICE
COCONUT RICE
KASHMIRI PULAO, JEERA PULAO
KASHMIRI PULAO
VEGETABLE BRIYANI
KASHMIRI PULAO
@mindaslab
mindaslab / ruby_questions.md
Last active November 27, 2015 09:33
Ruby Questions for Zanec

Create a file called your_name_zanec_math.rb

When I require it in code, following things must happen

1.prime? #=> true
7.prime? #=> true
27.prime? #=> false
13.fibo? #=> true
16.fibo? #=&gt; false
memo = []
(0..n).each do |i|
memo[i] = i < 2 ? i : memo[i-1] + memo[i-2]
end
@cache = [0,1]
def fib(n)
return @cache[n] if @cache[n]
@cache[n] = fib(n-1) + fib(n-2)
end
(1..20).each { |n| puts fib(n) }
def fib(n)
return n if n < 2
fib(n-1) + fib(n-2)
end