Skip to content

Instantly share code, notes, and snippets.

View leemour's full-sized avatar

Viacheslav Ptsarev leemour

View GitHub Profile
@leemour
leemour / time_spec.rb
Created April 26, 2014 15:16
RSpec time stubbing without Timecop
#Timecop is fun, but you don't need a whole gem for that. Just use
#Time.stub(:now), e.g.
describe "time" do
before do
@fake_time = Time.now
Time.stub(:now) { @fake_time }
end
it "is equal" do
Time.now.should == Time.now # now it passes
@leemour
leemour / rubocop.sh
Created August 2, 2019 07:43
Rubocop run on only changed files
git diff --staged --name-only | xargs rubocop -a
@leemour
leemour / app.conf
Last active January 16, 2019 15:12
Monit with Puma, Sidekiq, Nginx, PostgreSQL, Disk space and Memory limits, using rbenv and nvm
# /etc/monit/conf.d/app
set daemon 30 with start delay 60
set log "/srv/www/app/shared/log/monit.log" # syslog facility log_daemon
set httpd port 2812
allow localhost
allow login:password
# with ssl {
# pemfile: /etc/ssl/certs/app_com.pem
# }
@leemour
leemour / monit-and-gmail
Last active January 16, 2019 12:47 — forked from jcdarwin/monit-and-gmail
How to allow monit to use gmail as a smtp relay to send out alert emails
# visit https://accounts.google.com/DisplayUnlockCaptcha and click to allow access
# edit /etc/monit/monitrc to include the following
set mailserver smtp.gmail.com port 587
username "whoever@gmail.com" password "whatever"
using tls
with timeout 30 seconds
# run the following to validate access
@leemour
leemour / spree_carrierwave.rb
Created January 15, 2019 18:48
Spree Carrierwave replacement
# app/models/spree/image.rb
module Spree
class Image < Asset
mount_uploader :attachment, Spree::ImageUploader,
mount_on: :attachment_file_name
validates :attachment, presence: true
end
end
@leemour
leemour / format_ruby_hash.rb
Last active January 11, 2019 14:22
Format Ruby hash with left indent and awesome print
# add `gem 'awesome_print` to Gemfile
rails c
# cl = Scryfaller::Client.new
# hash = cl.cards.search(q: "Aberrant Researcher // Perfected Form").body[:data].first
ap hash, ruby19_syntax: true, index: false, indent: 2
# Copy and paste output into https://www.cleancss.com/ruby-beautify/
@leemour
leemour / listen_ports.sh
Created December 14, 2018 17:08
Ubuntu network stat check ports listen
# sudo apt install net-tools
sudo netstat -ntlp | grep LISTEN
@leemour
leemour / .rubocop.yml
Last active December 3, 2018 11:06
Rubocop config
# inherit_from: .rubocop_todo.yml
AllCops:
# Default formatter will be used if no `-f/--format` option is given.
DefaultFormatter: fuubar
# Cop names are displayed in offense messages by default. Change behavior
# by overriding DisplayCopNames, or by giving the `--no-display-cop-names`
# option.
DisplayCopNames: true
# Style guide URLs are not displayed in offense messages by default. Change
@leemour
leemour / changelog.rake
Last active November 28, 2018 14:40 — forked from cdesch/rake task
Ruby git CHANGELOG generator
namespace :changelog do
# simple rake task to output a changelog between two commits, tags ...
# output is formatted simply, commits are grouped under each author name
#
desc "generate changelog with nice clean output"
task :generate, :since_c, :until_c do |t, args|
since_c = args[:since_c] || `git tag | head -1`.chomp
until_c = args[:until_c] || `git rev-parse --short HEAD`
cmd=`git log --pretty='format:%ci::%an <%ae>::%s::%H' --after=#{since_c} --before=#{until_c}`
@leemour
leemour / where_is.rb
Created October 24, 2018 18:07 — forked from wtaysom/where_is.rb
A little Ruby module for finding the source location where class and methods are defined.
module Where
class <<self
attr_accessor :editor
def is_proc(proc)
source_location(proc)
end
def is_method(klass, method_name)
source_location(klass.method(method_name))