Skip to content

Instantly share code, notes, and snippets.

View skunkworker's full-sized avatar

John Bolliger skunkworker

View GitHub Profile
@skunkworker
skunkworker / append_json_column_rails_5.rb
Last active October 11, 2022 16:13
How to append to a json column array in Rails 5.
# assuming Model is your model and options is a json/jsonb column.
# This uses the Postgres json append || operator.
# And wraps the option inside an array.
# producing [{},{}] multiple hashes inside a top level json array.
# It is very important that the hash is [{}] NOT {} as not having the array on the
# outside will cause the hash to replace the contents instead of appending to them.
new_option = [{
name: option_name,
@skunkworker
skunkworker / VolumeMac.ahk
Last active November 16, 2018 02:34
AutoHotkey mac keyboard play/pause, back/next, volume up, down, mute
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;F10
^F10::
Sendinput, {F10}
Return
@skunkworker
skunkworker / migrations.rake
Created October 18, 2018 20:45
Generate clean sql migrations from lol_dba
namespace :migrations do
desc 'Generate clean SQL migrations from lol_dba'
task clean_sql: :environment do
Rake::Task["db:migrate_sql"].invoke
sql_migration_files = Dir[Rails.root.join("db", "migrate_sql")+"*.sql"]
sql_migration_files.each_with_index do |sql_file,i|
@skunkworker
skunkworker / config annotate.yml
Last active October 11, 2018 18:08
Add custom models to Annotate Gem
Foo:
- interactions/foo/
- interactions/user/bar/
- interactions/baz.rb
Bar:
- interactions/bar/
- interactions/user/bar/
@skunkworker
skunkworker / readme.txt
Last active September 20, 2018 06:31
How to fix valgrind ignoring sigreturn errors on mac os x high sierra.
git clone https://sourceware.org/git/valgrind.git;
cd valgrind/
# time to edit some files (see below)
./autogen.sh
./configure --disable-dependency-tracking --enable-only64bit --build=amd64-darwin
./make
./make install
# done.
@skunkworker
skunkworker / dotenv.zsh
Created February 17, 2018 21:17
fixed dotenv.zsh for loading and excluding comments.
#! /bin/zsh
function dotenv () {
regex="DOT_ENV\=(\w+)"
if [[ $1 =~ $regex ]]; then
env="${match[1]}"
file_name=".env.${env}"
if [[ -f $file_name ]]; then
source_env $file_name
return
@skunkworker
skunkworker / nbody.rb
Last active February 25, 2018 03:27
TruffleRuby is insanely fast. 641s on MRI 2.5.0, (302s on MRI 2.6-preview1 --jit) vs 16.2s on TruffleRuby.
# The Computer Language Benchmarks Game
# http://benchmarksgame.alioth.debian.org
#
# Optimized for Ruby by Jesse Millikan
# From version ported by Michael Neumann from the C gcc version,
# which was written by Christoph Bauer.
require 'benchmark'
puts Benchmark.measure {
@skunkworker
skunkworker / test_job_helper.rb
Created December 30, 2017 03:02
ActiveJob run enqueued jobs without block for testing.
# this pulls out each job and runs it, then clears the job queue.
# helpful when you don't want to run inside a block.
def perform_enqueued_jobs_now
enqueued_jobs = ActiveJob::Base.queue_adapter.enqueued_jobs
enqueued_jobs.each do |item|
item[:job].perform_now(*item[:args])
ActiveJob::Base.queue_adapter.performed_jobs << item
end
@skunkworker
skunkworker / annotate_models.rb
Created November 26, 2017 02:46
How to extend annotate gem for more models.
# add to app/initializers/annotate_models.rb
module AnnotateModels
class << self
# add your type
MATCHED_TYPES = %w(test fixture factory serializer scaffold controller helper serializable).freeze
# the directory they live in, can be more than 1 here
SERIALIZABLE_DIR = File.join('app', "serializers")
@skunkworker
skunkworker / .travis.yml
Created September 2, 2017 18:30
Compile Vips 8.5.8 on Travis CI
dist: trusty
before_install:
- chmod +x travis_compile_vips.sh
- ./travis_compile_vips.sh
cache:
directories:
- vips-8.5.8