Skip to content

Instantly share code, notes, and snippets.

View AleksandrKudashkin's full-sized avatar

Aleksandr Kudashkin AleksandrKudashkin

  • Montreal, Canada
View GitHub Profile

Keybase proof

I hereby claim:

  • I am aleksandrkudashkin on github.
  • I am alexkudashkin (https://keybase.io/alexkudashkin) on keybase.
  • I have a public key ASDBvGcGsX1q8d7L16Ke_s7ePcue_PNoFX72K6NUw4e-qAo

To claim this, I am signing this object:

@AleksandrKudashkin
AleksandrKudashkin / passenger_standalone.rb
Created November 11, 2018 02:04 — forked from reu/passenger_standalone.rb
Capistrano recipe for passenger standalone
set :rails_env, "production"
set :passenger_port, 9292
set :passenger_cmd, "#{bundle_cmd} exec passenger"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{passenger_cmd} start -e #{rails_env} -p #{passenger_port} -d"
end
task :stop, :roles => :app, :except => { :no_release => true } do
@AleksandrKudashkin
AleksandrKudashkin / install-docker.sh
Created May 8, 2018 20:01 — forked from dweldon/install-docker.sh
Install docker CE on Linux Mint 18.3
#!/usr/bin/env bash
# https://docs.docker.com/install/linux/docker-ce/ubuntu/
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
sudo apt-get update
sudo apt-get install docker-ce
# https://docs.docker.com/compose/install/
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates -y
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo echo deb https://apt.dockerproject.org/repo ubuntu-xenial main >> /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get purge lxc-docker
sudo apt-get install linux-image-extra-$(uname -r) -y
sudo apt-get install docker-engine cgroup-lite apparmor -y
sudo usermod -a -G docker $USER
sudo service docker start
@AleksandrKudashkin
AleksandrKudashkin / gist:27decd870e1138796cf4892d8cb2d030
Created January 18, 2018 13:32 — forked from ezotrank/gist:3910281
Paperclip(ImageMagic) resize, crop and other action sheet cheat
'400x300' # resize, maintain aspect ratio
'400x300!' # force resize, don't maintain aspect ratio
'400x' # resize width, maintain aspect ratio
'x300' # resize height, maintain aspect ratio
'400x300>' # resize only if the image is larger than this
'400x300<' # resize only if the image is smaller than this
'50x50%' # resize width and height to 50%
'400x300^' # resize width, height to minimum 400,300, maintain aspect ratio
'2000@' # resize so max area in pixels is 2000
'400x300#' # resize, crop if necessary to maintain aspect ratio (centre gravity)
@AleksandrKudashkin
AleksandrKudashkin / install.sh
Created September 12, 2017 15:30 — forked from ziadoz/install.sh
Install Chrome, ChromeDriver and Selenium on Ubuntu 16.04
#!/usr/bin/env bash
# https://developers.supportbee.com/blog/setting-up-cucumber-to-run-with-Chrome-on-Linux/
# https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
# http://stackoverflow.com/questions/10792403/how-do-i-get-chrome-working-with-selenium-using-php-webdriver
# http://stackoverflow.com/questions/26133486/how-to-specify-binary-path-for-remote-chromedriver-in-codeception
# http://stackoverflow.com/questions/40262682/how-to-run-selenium-3-x-with-chrome-driver-through-terminal
# http://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04
# Versions
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
@AleksandrKudashkin
AleksandrKudashkin / factory_doctor.rb
Created September 7, 2017 01:09 — forked from palkan/factory_doctor.rb
FactoryDoc: detect useless data generation in tests
module FactoryGirl
module Doctor
module FloatDuration
refine Float do
def duration
t = self
format("%02d:%02d.%03d", t / 60, t % 60, t.modulo(1) * 1000)
end
end
end
@AleksandrKudashkin
AleksandrKudashkin / sanitize.rb
Created September 6, 2017 20:06
Loofah custom scrubber for youtube and vimeo iframes
class CustomScrubber < Loofah::Scrubber
ALLOWED_IFRAME_ATTRS = %w[allowfullscreen frameborder height src width].freeze
ALLOWED_VIDEO_REGEX = %r{\A(?:https?:)?//(?:www\.)?youtube|vimeo(?:-nocookie)?\.com/}
def scrub(node)
if node.name == 'iframe' && node['src'] =~ ALLOWED_VIDEO_REGEX
node.attribute_nodes.each { |a| a.remove unless ALLOWED_IFRAME_ATTRS.include?(a.name) }
return CONTINUE
end
return CONTINUE if html5lib_sanitize(node) == CONTINUE
@AleksandrKudashkin
AleksandrKudashkin / qna
Created October 27, 2016 17:53
my monit config for qna
### Nginx ###
check process nginx with pidfile "/opt/nginx/logs/nginx.pid"
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if memory usage > 80% for 5 cycles then restart
if failed host 127.0.0.1 port 80 protocol http request "/terms.html" then restart
if 3 restarts within 5 cycles then timeout
module Commented
extend ActiveSupport::Concern
included do
before_action :load_commentable, only: :add_comment
end
def add_comment
@comment = @commentable.comments.new(commentable_params)
if @comment.save