Skip to content

Instantly share code, notes, and snippets.

@sorokadima
sorokadima / index.rb
Last active January 2, 2020 09:49
Rails Catch Exception (Ruby On Rails try catch)
def res params
begin
# do something
Rails.logger.info "debug #{Time.now.to_datetime}"
Rails.logger.info params
rescue Exception => e
Rails.logger.info "debug_Exception #{Time.now.to_datetime}"
Rails.logger.info e.message
end
end
@sorokadima
sorokadima / Gemfile
Created January 2, 2020 13:08
Rails CORS (Ruby on Rails Cross-Origin Resource Sharing)
gem 'rack-cors'
@sorokadima
sorokadima / index.rb
Last active January 11, 2020 10:45
Ruby unless && statement (unless or and, Ruby Draft)
a = true
b = false
# if one of variable false run exception
if !a or !b
p 'ERROR 1' # +
end
unless a or b
@sorokadima
sorokadima / index.sh
Last active January 14, 2020 08:00
Ubuntu kill chromium (chrome, kill chromium process)
pkill -o chrome && pkill -o chromium
@sorokadima
sorokadima / index.sh
Last active January 15, 2020 08:13
sudo apt install Error (E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?)
# E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
# E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
sudo lsof /var/lib/dpkg/lock
sudo kill -9 <PID> && sudo dpkg --configure -a
// Show log
tail -f /var/log/mysqld.log
@sorokadima
sorokadima / index.rb
Last active January 16, 2020 16:12
Ruby add subdomain to URL
# WAY 1
url = 'https://www.example.com/post/hello-world'
subdomain = 'blog'
index = url.index('://www.') ? url.index('://www.') + 7 : url.index('://') + 3
url.insert(index, subdomain + '.')
p url
# WAY 2
url = 'https://www.example.com/post/hello-world'
@sorokadima
sorokadima / index.md
Last active February 7, 2020 10:35
Ruby include extend

RUBY extend include statement

extend - додає методи до самого класу.
include - додає методи до екземпляру класу.

extend

@sorokadima
sorokadima / index.rb
Created February 11, 2020 08:30
Ruby snake_case to CamelCase (snake case to camel case)
'my_name'.split('_').collect(&:capitalize).join
# => "MyName"
@sorokadima
sorokadima / index.php
Created February 12, 2020 20:05
PHP object
<?php
$obj = (object) ['a' => 'b'];
echo $obj->a;