Skip to content

Instantly share code, notes, and snippets.

# In your Gemfile
gem "localhost"

# Then, depending on your desired server
gem "falcon"
gem "puma"
@zhukovpe
zhukovpe / install_homebrew_m1.sh
Created January 2, 2023 12:05 — forked from Molin-L/install_homebrew_m1.sh
Install Homebrew on Apple silicon device/M1.
# Install ARM Homebrew to /opt/homebrew
# 安装ARM版本的Homebrew 到 /opt/homebrew
mkdir /opt/homebrew
sudo chown -R $(whoami) /opt/homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C /opt/homebrew
# Install x86 Homebrew
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
@zhukovpe
zhukovpe / docker-cleanup-resources.md
Created March 28, 2019 11:49 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@zhukovpe
zhukovpe / pre-commit
Created October 13, 2018 11:41
Rubocop pre-commit hook
#!/usr/bin/env ruby
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
if ARGV == ["install"]
exec "ln", "-sf", __FILE__, ".git/hooks/pre-commit"
else
raise unless ARGV == []
end
@zhukovpe
zhukovpe / prepare-commit-msg
Last active August 17, 2018 13:10
Simple git prepare-commit-msg hook, which adds current branch name to the beginning of the commit message. So if your flow is to make a new branch for each task (for ex: your branch name `CCD-914`), this will add a branch name (task name) to every commit message. `git commit -m 'Super cool'` message will be auto appended like `CCD-914 Super cool`.
#!/bin/bash
# Put it into '.git/hooks/prepare-commit-msg'
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master development)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"
@zhukovpe
zhukovpe / gist:9346a836bdcc5f923e884e49d0941cc9
Created August 16, 2018 14:47 — forked from tychobrailleur/gist:5712504
Capybara/Selenium/Firefox/Proxy.
require 'capybara/firebug'
# Disable Webmock if needed.
WebMock.disable_net_connect!(allow_localhost: true)
# Same thing for VCR if it has been imported somewhere.
VCR.configure do |c|
c.ignore_localhost = true
end
ENV['NO_PROXY'] = ENV['no_proxy'] = '127.0.0.1'
@zhukovpe
zhukovpe / flatten.rb
Created April 23, 2018 14:05
Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
class Flatten
def self.call(input_array)
memo = Array.new
flatten(input_array, memo)
end
def self.flatten(array, memo)
array.each do |element|
if element.kind_of?(Array)
@zhukovpe
zhukovpe / psql-with-gzip-cheatsheet.sh
Created September 18, 2017 11:08 — forked from brock/psql-with-gzip-cheatsheet.sh
Exporting and Importing Postgres Databases using gzip
# This is just a cheat sheet:
# On production
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz
# On local
scp -C production:~/database.sql.gz
dropdb database && createdb database
gunzip < database.sql.gz | psql database
@zhukovpe
zhukovpe / factory_girl_strategy_find_or_create.rb
Created September 4, 2017 11:35 — forked from hiasinho/factory_girl_strategy_find_or_create.rb
FactoryGirl strategy for adding find & find_or_create
## http://stackoverflow.com/questions/7145256
module FactoryGirl
module Strategy
class Find
def association(runner)
runner.run
end
def result(evaluation)
build_class(evaluation).where(get_overrides(evaluation)).first