Skip to content

Instantly share code, notes, and snippets.

Avatar

John Bolliger skunkworker

View GitHub Profile
@skunkworker
skunkworker / example.rb
Last active Jun 13, 2020
How to append to a json column array in Rails 5.
View example.rb
# 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 Nov 16, 2018
AutoHotkey mac keyboard play/pause, back/next, volume up, down, mute
View VolumeMac.ahk
#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 Oct 18, 2018
Generate clean sql migrations from lol_dba
View migrations.rake
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 Oct 11, 2018
Add custom models to Annotate Gem
View config annotate.yml
Foo:
- interactions/foo/
- interactions/user/bar/
- interactions/baz.rb
Bar:
- interactions/bar/
- interactions/user/bar/
@skunkworker
skunkworker / readme.txt
Last active Sep 20, 2018
How to fix valgrind ignoring sigreturn errors on mac os x high sierra.
View readme.txt
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 Feb 17, 2018
fixed dotenv.zsh for loading and excluding comments.
View dotenv.zsh
#! /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 Feb 25, 2018
TruffleRuby is insanely fast. 641s on MRI 2.5.0, (302s on MRI 2.6-preview1 --jit) vs 16.2s on TruffleRuby.
View nbody.rb
# 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 Dec 30, 2017
ActiveJob run enqueued jobs without block for testing.
View test_job_helper.rb
# 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 Nov 26, 2017
How to extend annotate gem for more models.
View annotate_models.rb
# 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 Sep 2, 2017
Compile Vips 8.5.8 on Travis CI
View .travis.yml
dist: trusty
before_install:
- chmod +x travis_compile_vips.sh
- ./travis_compile_vips.sh
cache:
directories:
- vips-8.5.8