Skip to content

Instantly share code, notes, and snippets.

View thermistor's full-sized avatar
🏠
Working from home

Weston Triemstra thermistor

🏠
Working from home
View GitHub Profile
@thermistor
thermistor / bulk_insert.rb
Created March 14, 2018 17:38 — forked from maxjustus/bulk_insert.rb
Simple SQL bulk insert in Rails
# Takes a table name, and an array of hashes where keys are column names and values are values.
# Expects hashes to all contain the same keys.
def bulk_insert(table, rows)
columns = rows.first.keys
to_insert = rows.map do |d|
vals = columns.map {|k| d[k] }
ActiveRecord::Base.send(:replace_bind_variables, "(#{vals.length.times.collect {'?'}.join(',')})", vals)
end
@thermistor
thermistor / interactor_ext.rb
Created February 23, 2018 22:00
Re-open Interactor and add method to validate context
module Interactor
def require_in_context(*names)
context_keys = context.keys
names.each do |name|
if !context_keys.include?(name)
raise "Interactor #{self.class.name} requires #{name.inspect} but it wasn't found in context."
end
end
names.map do |name|
self.send(name)
@thermistor
thermistor / gist:bbb43eb76a3b164f69611bff2338b2bc
Created December 19, 2017 22:55 — forked from giannisp/gist:ebaca117ac9e44231421f04e7796d5ca
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
@thermistor
thermistor / set_param.js
Last active September 14, 2016 00:11
Set/update a query param via javascript function
// from https://gist.github.com/stinoga/8101816#gistcomment-1842990
function setParam(uri, key, val) {
return uri
.replace(new RegExp("([?&]"+key+"(?=[=&#]|$)[^#&]*|(?=#|$))"), "&"+key+"="+encodeURIComponent(val))
.replace(/^([^?&]+)&/, "$1?");
}
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
@thermistor
thermistor / pedantically_commented_playbook.yml
Created May 29, 2016 05:21 — forked from marktheunissen/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.

Keybase proof

I hereby claim:

  • I am thermistor on github.
  • I am thermistor (https://keybase.io/thermistor) on keybase.
  • I have a public key ASBiX2KnZb1zYnuWNsGrScjM7ZlOaPVS0bjWdF99-UlV3go

To claim this, I am signing this object:

@thermistor
thermistor / gist:08e039f912795166d567
Last active January 29, 2016 00:39
Rollbar deploy notification using ENV variable from dotenv
require 'dotenv/tasks'
task notify_rollbar: :dotenv do
on roles(:app) do |h|
revision = `git log -n 1 --pretty=format:"%H"`
local_user = `whoami`.chomp
rollbar_token = ENV['ROLLBAR_ACCESS_TOKEN']
rails_env = fetch(:rails_env, 'production')
execute :curl, "https://api.rollbar.com/api/1/deploy/ -F access_token=#{rollbar_token} -F environment=#{rails_env} -F revision=#{revision} -F local_username=#{local_user} >/dev/null 2>&1", :once => true
end
/**
* Source: http://nicolasgallagher.com/micro-clearfix-hack/
*
* For modern browsers
* 1. The space content is one way to avoid an Opera bug when the
* contenteditable attribute is included anywhere else in the document.
* Otherwise it causes space to appear at the top and bottom of elements
* that are clearfixed.
* 2. The use of `table` rather than `block` is only necessary if using
* `:before` to contain the top-margins of child elements.
@thermistor
thermistor / delayed_job.cap
Created October 24, 2013 19:22
Delayed Job tasks for Capistrano 3, save in lib/capistrano/tasks.
namespace :delayed_job do
def args
fetch(:delayed_job_args, "")
end
def delayed_job_roles
fetch(:delayed_job_server_role, :app)
end