Skip to content

Instantly share code, notes, and snippets.

@kadru
kadru / rails http status codes
Created November 22, 2018 03:34 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
#Date Formatting I
'%Y' #Year with century (e.g. 2015, 1995, etc)
'%m' #Month of the year, zero-padded (01..12)
'%B' #The full month name (e.g. January)
'%b' #The abbreviated month name (e.g. Jan)
'%d' #Day of the month, zero-padded (01..31)
'%j' #Day of the year (001..366)
@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