Skip to content

Instantly share code, notes, and snippets.

@tinbka
tinbka / TrialAnswers4ashaleigh1.md
Last active July 2, 2018 13:16
Ruby expert trial Q&A

1. Review these translations

I have to say that you can't assess programmers by the coding style only.
People could have problems with software design and understanding of business logic even if they learned the style guides.
So the score is assigned based on the style and understanding of the language features only,
which is worth only for hiring people for translation of the code from other languages.

Also, I'd shuffle the links, so that the best code quality is found somewhere in the middle.

1.1. Review of https://gist.github.com/amanagrawal9/02e52ab62d09f2b2cd0d1e694f571385

@tinbka
tinbka / ngrok-rails.rb
Last active February 20, 2016 01:10
Run callback along with rails server
# Add these to the end of configuration file of your prefered web-server,
# e.g. config/unicorn.rb, config/thin.rb or config/puma.rb
# Use ./.ngrok or ~/.ngrok as a config file. DOn't forget to add it to `.gitignore' in the former case.
# See https://github.com/bogdanovich/ngrok-tunnel for available options.
unless ENV['RAILS_ENV'] == 'production'
require 'ngrok/tunnel'
options = {addr: ENV['PORT']}
if File.file? '.ngrok'
options[:config] = '.ngrok'
elsif File.file? ENV['HOME'] + '/.ngrok'
@tinbka
tinbka / skip_callback.rb
Last active January 27, 2016 12:37
Disable a model callback in a spec
# If you need to skip callbacks only for specific suite.
# You obviously should set a position and an event name of the callback.
before(:suite) do
ModelClass.skip_callback(:save_image, :after, :save)
end
after(:suite) do
ModelClass.set_callback(:save_image, :after, :save)
end
@tinbka
tinbka / before_render.rb
Created January 19, 2016 23:34
before_render class method for Rails controllers
# The MIT License (MIT)
#
# Copyright (c) 2015 <tinbka@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@tinbka
tinbka / void.rb
Created October 25, 2015 10:29
The object always returning itself
# abc = Void.new
# (abc.first.get {|_| !_}.something << 'blah blah')[123].raise!
# => #<Void:0xb66367b0>
#
# Think twice before using it. It may devour your code!
class Void < BasicObject
def method_missing(m, *args)
case m.to_s[-1,1]
when '?'; false
when '!'; nil
@tinbka
tinbka / config_versioning.rb
Created October 11, 2015 13:42
Dynamic config over RailsConfig and ActiveRecord.
# The MIT License (MIT)
#
# Copyright (c) 2015 <tinbka@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions: