Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View BitOfUniverse's full-sized avatar

Alexey Nikolaev BitOfUniverse

View GitHub Profile
@BitOfUniverse
BitOfUniverse / gist:6079302
Created July 25, 2013 12:50
Configure rails mailer
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => '',
:password => '',
:authentication => 'plain',
:enable_starttls_auto => true
}
@BitOfUniverse
BitOfUniverse / .bashrc
Created April 22, 2016 14:34 — forked from randsina/.bashrc
Prompt for bash
ESC="\033" # This is the escape sequence
NO_COLOR="$ESC[0m"
IRED="$ESC[1;31m" # ANSI color code for intense/bold red
IGRN="$ESC[1;32m" # ANSI color code for intense/bold green
# From http://railstips.org/blog/archives/2009/02/02/bedazzle-your-bash-prompt-with-git-info/
# I had to change 'git-symbolic-ref' to 'git symbolic-ref'
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo " ["${ref#refs/heads/}"]" # I wanted my branch wrapped in [], use () or <> or whatever
@BitOfUniverse
BitOfUniverse / better_errors.rb
Created May 17, 2016 11:48
Open file in RubyMine at line from better errors
BetterErrors.editor = ->(file, line) { "x-mine://open?file=#{file}&line=#{line}" }
@BitOfUniverse
BitOfUniverse / bm_hash_to_json.rb
Created September 1, 2016 17:27
Benchmark: Hash to JSON convertation methods
require 'benchmark'
require 'json/ext'
iterations = 1_000_000
hash = { who: 'Me', first_name: 'Alexey', last_name: 'Black', title: 'Doctor',
birthdate: Time.now, favorite_color: 'transparent', car: 'BMW', hands: 2,
city: 'Quanzi', planet: 'Third' }
Benchmark.bm(27) do |bm|
# 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
@BitOfUniverse
BitOfUniverse / db.rake
Created March 15, 2017 10:38 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# 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
@BitOfUniverse
BitOfUniverse / ssh.rake
Created March 20, 2017 09:09
SSH to capistrano server
# 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
@BitOfUniverse
BitOfUniverse / coverage_reporters.rb
Created April 10, 2016 18:21
Use CodeClimate + Coversall + SimpleCov locally at the same time
# Allows to post coverage data to remote services like Codeclimate & Coversall and use simplecov locally
# to view coverage locally, run: rake spec COV=true
# add file on the top for spec_helper: require 'coverage_reporters.rb'
require 'simplecov'
require 'coveralls'
require "codeclimate-test-reporter"
reporters = [
(Coveralls::SimpleCov::Formatter if Coveralls.will_run?),
(CodeClimate::TestReporter::Formatter if CodeClimate::TestReporter.run?),
@BitOfUniverse
BitOfUniverse / iffe.rb
Last active March 7, 2018 15:03
Ruby IIFE
# def returns symbol
# 1
send def me; puts "iffy" end
# 2
method(def me; puts "iffy" end).call
# 3
(->{ puts "iffy" }).()
@BitOfUniverse
BitOfUniverse / benchmark_block_passing.rb
Created March 8, 2018 14:45
Ruby benchmark [2.4 vs 2.5]: Lazy Proc allocation for block parameters
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