Skip to content

Instantly share code, notes, and snippets.

/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
@shuber
shuber / csrf-lua.conf
Created March 30, 2018 10:01 — forked from shrikeh/csrf-lua.conf
A simple nginx host file that, using the lua module, handles CSRF, rather than the backend having to (and thus generally breaking caching by having to use Set-Cookie). Here, the front end takes care of CSRF, and sends an X-CSRF-Valid header to the backend regarding the validity of the POST, so that it is advisory (the backend then choose whether…
server {
listen 80;
root /root/to/your/docroot;
proxy_redirect off;
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@shuber
shuber / gist:7aa1eb9faf1a3a559f6b29730f1b4110
Created February 16, 2018 19:02 — forked from mgreenly/gist:1109325
database cleaner multiple connections single orm outside of rails
RSpec.configure do |config|
config.before(:suite) do
ActiveRecord::Base.establish_connection database['one']
DatabaseCleaner.strategy = :deletion
ActiveRecord::Base.establish_connection config.database['two']
DatabaseCleaner.strategy = :deletion
end
config.before(:each) do
@shuber
shuber / gist:d221d0776ff5d3fb06cdb4fdb6b33ca3
Created November 29, 2017 23:21 — forked from dnagir/gist:1573414
Run Postgres Specs in Ramdisk
  • This creates a 560mb ramdisk. Adjust the size accordingly. I think the number at the end of the command is the number of disk blocks. They are 2kb in size for me.
  • Restarting postgres is not necessary; you can create the ramdisk and tablespace while postgres is running.
  • You will lose all data in the ramdisk tablespace when you shut your machine down

  $ diskutil erasevolume HFS+ "postgres_ramdisk" `hdiutil attach -nomount ram://1165430`
  Started erase on disk1
  Unmounting disk
  Erasing
 Initialized /dev/rdisk1 as a 569 MB HFS Plus volume
@shuber
shuber / migrate_postgresql_database.md
Created November 29, 2017 06:18 — forked from olivierlacan/migrate_postgresql_database.md
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X

This guide assumes that you recently run brew upgrade postgresql and discovered to your dismay that you accidentally bumped from one major version to another: say 9.3.x to 9.4.x. Yes, that is a major version bump in PG land.

First let's check something.

brew info postgresql

The top of what gets printed as a result is the most important:

@shuber
shuber / gist:14f6f9df63d758faab47c7426f327554
Created September 13, 2017 18:07 — forked from oslego/gist:f13e136ffeaa6174289a
create self-signed certificate for localhost
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@shuber
shuber / sqitch_alternatives.txt
Created February 10, 2017 21:29 — forked from begriffs/sqitch_alternatives.txt
sqitch alternatives
https://github.com/flyway/flyway
https://github.com/mattes/migrate
https://bitbucket.org/liamstask/goose
https://github.com/tanel/dbmigrate
https://github.com/BurntSushi/migration
https://github.com/DavidHuie/gomigrate
https://github.com/rubenv/sql-migrate
@shuber
shuber / find_unused_images.rake
Created August 17, 2016 23:47 — forked from rafaelp/find_unused_images.rake
Rake task to find unused images on Rails project to deletion.
# It requires ACK - http://betterthangrep.com/
task :find_unused_images do
images = Dir.glob('app/assets/images/**/*')
images_to_delete = []
images.each do |image|
unless File.directory?(image)
# print "\nChecking #{image}..."
print "."
result = `ack -1 -G '(app|public)' --ruby --html --css --js #{File.basename(image)}`
@shuber
shuber / buildkite-agent.service
Created July 5, 2016 21:35 — forked from sj26/buildkite-agent.service
Starting multiple buildkite-agents per-machine with systemd
[Unit]
Description=Buildkite Agents
Documentation=https://buildkite.com/agent
Wants=buildkite-agent@1.service
Wants=buildkite-agent@2.service
# ...
[Service]
Type=oneshot
ExecStart=/bin/true
@shuber
shuber / add_index_patch.rb
Created April 1, 2015 07:43
ActiveRecord `add_index` patch for PostgreSQL JSONB GIN indexes
# This patch detects {index_columns} that match something like
# the example below, then strips the surrounding double quotes.
#
# "(settings->'example')"
#
# The resulting CREATE INDEX sql looks something like:
#
# CREATE INDEX "idx_users_on_settings_example" ON "users" USING gin ((settings->>'example'))
#
# Your {add_index} call should looks something like: