This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RailsController | |
helper_method def current_user | |
User.current | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
some_method def another_method; end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
send def execute_right_now | |
puts "That's nice!" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(->{ puts "Hey, I'm IIFE" }).() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in React after 15.6 | |
const triggerInputChange = (node, value = '') => { | |
const inputTypes = [ | |
window.HTMLInputElement, | |
window.HTMLSelectElement, | |
window.HTMLTextAreaElement | |
]; | |
if (inputTypes.indexOf(node.__proto__.constructor) > -1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
def with_block(&block); end | |
Benchmark.bmbm(10){|x| | |
x.report("with_block") { 1_000_000.times{ with_block{} } } | |
} | |
# Using /Users/alexey/.rvm/gems/ruby-2.4.2 | |
# ➜ ruby ruby benchmark_ruby_block_passing.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# def returns symbol | |
# 1 | |
send def me; puts "iffy" end | |
# 2 | |
method(def me; puts "iffy" end).call | |
# 3 | |
(->{ puts "iffy" }).() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/capistrano/tasks/ssh.rake | |
# | |
# Usage: cap staging ssh | |
desc 'Connects thru SSH to server' | |
task :ssh do | |
on roles(:app) do |server| | |
ssh_command = nil | |
with_props(server) do |host, user| | |
ssh_command = "ssh #{user}@#{host}" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/tasks/db.rake | |
namespace :db do | |
desc "Dumps the database to db/APP_NAME.dump" | |
task :dump => :environment do | |
cmd = nil | |
with_config do |app, host, db, user| | |
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump" | |
end | |
puts cmd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Base on this article: https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04 | |
sudo fallocate -l 1G /swapfile | |
sudo chmod 600 /swapfile | |
sudo mkswap /swapfile | |
sudo swapon /swapfile | |
sudo swapon --show | |
free -h | |
# Make the Swap File Permanent |