Skip to content

Instantly share code, notes, and snippets.

# Copied from http://blog.salsify.com/engineering/tearing-capybara-ajax-tests
# https://gist.github.com/jturkel/9317269/raw/ff7838684370fd8a468ffe1e5ce1f3e46ba39951/rack_request_blocker.rb
require 'atomic'
# Rack middleware that keeps track of the number of active requests and can block new requests.
class RackRequestBlocker
@@num_active_requests = Atomic.new(0)
@@block_requests = Atomic.new(false)
@mkllnk
mkllnk / pre-commit
Last active April 1, 2016 04:49
Git pre-commit hook for Rubocop offenses
#!/bin/sh
# This script only checks the total number of offenses in modified files.
# If you removed old offenses, it may not warn you about new ones.
# Other scripts check all modified files for offenses.
# They don't ignore old offenses.
NUMBER_BEFORE=`git diff --cached --diff-filter=CMRTUXB --name-only -- '*.rb' | sed 's/^\(.*\)$/HEAD:\1/' | xargs git show | rubocop -s head -f o | tail -n 2 | head -n 1 | cut -d ' ' -f 1`
NUMBER_NOW=`git diff --cached --diff-filter=ACMRTUXB --name-only -- '*.rb' | xargs cat | rubocop -s now -f o | tail -n 2 | head -n 1 | cut -d ' ' -f 1`
{
"IcoMoonType": "selection",
"icons": [
{
"icon": {
"paths": [
"M521.216 0.064l-9.472-0.064c-277.088 0-506.688 225.568-511.648 502.688-2.624 136.736 48.352 266.176 143.232 364.736 94.944 98.432 222.56 154.016 359.328 156.544l9.472 0.032c277.088 0 506.656-225.536 511.648-502.624 2.528-136.8-48.352-266.208-143.264-364.704-94.944-98.56-222.56-154.048-359.296-156.608zM512.128 987.296l-8.864-0.128c-126.848-2.208-245.312-53.856-333.376-145.248-88.192-91.36-135.36-211.616-133.088-338.496 4.608-257.344 217.632-466.656 474.944-466.656l8.736 0.096c126.976 2.176 245.344 53.856 333.504 145.312 88.096 91.328 135.36 211.552 133.088 338.368-4.64 257.408-217.728 466.752-474.944 466.752z",
"M754.72 498.016l-440.576-7.968 214.848-207.328c7.36-7.040 7.52-18.72 0.544-25.952-7.008-7.328-18.72-7.488-25.984-0.48l-260.032 250.752 12.672 13.216c0.096 0 0.096 0.096 0.096 0.096l238.048 246.912c3.584 3.68 8.416 5.568 13.216 5.568 4.576 0 9.184-1.696 12.768-5.184 7.296-7.040 7.424-18.688 0.448-25.952l-207.328-214.97
@mkllnk
mkllnk / deploy-www
Created December 4, 2016 03:38
Deploy with Git and sshfs
#!/bin/sh
#
# This is an experimental approach to deploying local changes to a remote server.
# It assumes that you can mount the remote directory into your filesystem.
#
# You make local changes on the master branch while keeping the state of the
# deployed version on the production branch.
set -ex
@mkllnk
mkllnk / post-receive
Created December 7, 2016 23:50
Git post-receive hook example for push deploy
#!/bin/sh
# GIT_DIR='.'
#
# on stdin:
# oldrev: old commit id like 0000000000000000000000000000000000000000
# newrev: new commit id like d26d82b03fbe38646941b6efb89827c88efa81e5
# refname: branch reference like refs/heads/master
# Deploy only the master branch and ignore the rest
@mkllnk
mkllnk / watch-html-php.sh
Created January 22, 2017 06:46
Watch PHP files and convert them to HTML when they change
#!/bin/bash
dir="${1-.}"
inotifywait -r -m -e CLOSE_WRITE "$dir" |
grep '\.html\.php$' --line-buffered |
while read path _ file; do
dstfile="$path${file%.php}"
echo "Processing $path$file $dstfile"
php "$path$file" > "$dstfile"
@mkllnk
mkllnk / fairfood-deploy-prod
Created March 23, 2017 04:10
Fairfood deploy sripts
#!/bin/sh
set -xe
git status | grep -F '# On branch master'
last_tag="$(git tag | grep -E '^[0-9]{4}\.' | tail -1)"
next_tag="$1"
# Check that a tag is given
@mkllnk
mkllnk / certbot-ssl-renewal
Created April 9, 2017 03:07
Certbot SSL renew script for cron
#!/bin/sh
# This script is to be placed in /etc/cron.daily/. Make it executable:
#
# chmod +x /etc/cron.daily/certbot-ssl-renewal
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
export PATH
#!/bin/sh
#
# Pre-conditions:
# - You have SFTP access.
# - You have sshfs installed.
# - You have certbot installed.
domain='example.org'
mkdir -p "/tmp/$domain"
@mkllnk
mkllnk / github-pull
Last active June 29, 2023 04:40
Checkout pull requests from other repositories in Github
#!/bin/bash
#set -ex
usage=" Usage: $0 <repo> <branch>
or: $0 user:branch
Example: $0 Em-AK/openfoodnetwork.git i18n-tests
$0 Em-AK:i18n-tests"