Skip to content

Instantly share code, notes, and snippets.

@kadru
kadru / safe_nav_op_enum_dig.rb
Created November 11, 2018 03:11
safe navigation operator & and Enumerable #dig (ruby 2.3 and up)
#Safe navigation operator
if account && account.owner && account.owner.address
#your code here
end
#could be rewritten like
account&.owner&.address
#more examples
account = Account.new(owner: nil) # account without an owner
#
@kadru
kadru / commands_related_to_processes.sh
Last active January 30, 2019 21:27
Command related to processes
@kadru
kadru / private_public_protected_example.rb
Created October 19, 2018 02:01
Explain ruby protected, private and public methods
#dwarf.rb
class Dwarf
include Comparable
def initialize(name, age, beard_strength)
@name = name
@age = age
@beard_strength = beard_strength
end
@kadru
kadru / webpacker_rails.md
Created October 15, 2018 04:41 — forked from maxivak/webpacker_rails.md
Webpack, Yarn, Npm in Rails
@kadru
kadru / strategy_pattern.rb
Created October 14, 2018 18:58
strategy pattern dynamic behavior example
module RunStrategies
class RunStrategyInterface
def self.run(name)
raise "Run method has not been implemented!"
end
end
class Jog < RunStrategyInterface
def self.run(name)
puts "#{name} is now jogging at a comfortable pace."
@kadru
kadru / data_type_columns.sql
Last active November 14, 2018 21:02
sql meta queries
SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'yourTableName'
COLUMN_NAME = 'yourColumnName'
@kadru
kadru / stored_procedure_service.rb
Last active September 14, 2018 18:22 — forked from ys/stored_procedure_service.rb
Execute stored procedure
class DatabaseHelper
def self.select name, *args, &blk
execute "select", name, *args, &blk
end
def self.call name, *args, &blk
execute "call", name, *args, &blk
end
def self.execute via, name, *args, &blk
@kadru
kadru / singleton.rb
Created September 6, 2018 14:59 — forked from mssola/singleton.rb
Different ways to create the Singleton pattern in Ruby.
##
# This files shows some possible implementations of the Singleton pattern
# in Ruby. I'm not a huge fan of the Singleton pattern, but it's nice
# in some cases. In this file I'm going to implement a simple logger.
#
##
# The first implementation that can come to our minds is to create a class
# that holds an instance as a class variable that can be accessed through
#With the macOS El capitan
#check git version
git --version
#Backup (or remove) Apple git (Optional)
sudo mv /usr/bin/git /usr/bin/git-apple
#Install Homebrew if you didn’t have
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
#Or update if you already have
brew update && brew upgrade
#Install Git with Homebrew
@kadru
kadru / autofix_and_other_utilities_sql_server.sql
Last active January 28, 2019 15:56
autofix and other utilities sql server.sql
EXEC sp_change_users_login 'Auto_Fix', 'user', NULL, 'pass'
-- constraints information
SELECT * FROM sys.objects
WHERE type_desc LIKE '%CONSTRAINT'
SELECT *
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where CONSTRAINT_NAME = 'constraint_name'