Skip to content

Instantly share code, notes, and snippets.

@bbugh
bbugh / .overcommit.yml
Created June 25, 2017 18:59
Overcommit setup for Rails apps
# Use this file to configure the Overcommit hooks you wish to use. This will
# extend the default configuration defined in:
# https://github.com/brigade/overcommit/blob/master/config/default.yml
#
# At the topmost level of this YAML file is a key representing type of hook
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
# customize each hook, such as whether to only run it on certain files (via
# `include`), whether to only display output if it fails (via `quiet`), etc.
#
# For a complete list of hooks, see:
@bbugh
bbugh / spec_helper.rb
Last active September 14, 2017 20:25 — forked from anolson/spec_helper.rb
Profile ActiveRecord queries, output Markdown table of counts
# Originally referenced from https://medium.com/treehouse-engineering/continous-improvements-4741fc3c7daa
RSpec.configure do |config|
config.before(:suite) do
Thread.current[:query_counter] = Hash.new(0)
end
config.around(:example) do |procsy|
callback = lambda do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
@bbugh
bbugh / indifferent_hash_serializer.rb
Created October 6, 2017 14:24
IndifferentHashSerializer for Rails json/jsonb columns
# app/serializers/indifferent_hash_serializer.rb
# Used for converting a json or jsonb column into a useable Rails hash instead
# of the psuedo-json hash that is normally returned by Rails.
class IndifferentHashSerializer
def self.dump(hash)
hash.to_json
end
def self.load(hash)
@bbugh
bbugh / tinymce_spec_helper.rb
Created October 20, 2017 20:34
Improved handling of TinyMCE with error logging and guard checks
module TinyMCESpecHelper
# Fill in a TinyMCE editor with the specified value.
# Pass in the same id you give to TinyMCE, (such as "editorContent")
# *not* TinyMCE's generated one.
#
# NOTE: The first argument is not a css selector, just an element id.
#
# May require selenium chromedriver!
# Adapted from https://gist.github.com/eoinkelly/69be6c27beb0106aa555
#
@bbugh
bbugh / _icons.scss
Created September 26, 2018 11:08
iconfont-webpack-plugin setup on webpack 4
// use with <i class="svg-icon bank-icon"></i>
.svg-icon {
vertical-align: middle; // you may not need this line depending on your icons
}
// borrowed from icomoon's font output
.svg-icon::before {
font-weight: normal;
font-style: normal;
font-variant: normal;
@bbugh
bbugh / test.sh
Created March 19, 2019 16:29
Find out what process is using the "Too many open files" issue on Mac
# taken from this answer on stack exchange: https://superuser.com/a/1180084
# This will show the number of files open by all of the processes
sudo lsof -n | cut -f1 -d' ' | uniq -c | sort | tail
# When you find out which one is using the most files, see what files are being used by it
sudo lsof -n | grep java
# In my case, it's always java because elasticsearch doesn't clean up after being on for weeks, I guess
brew services restart elasticsearch
@bbugh
bbugh / waitForKeyElements.js
Created April 11, 2019 12:16 — forked from mjblay/waitForKeyElements.js
A utility function, for Greasemonkey scripts, that detects and handles AJAXed content.
/*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
that detects and handles AJAXed content. Forked for use without JQuery.
Usage example:
waitForKeyElements (
"div.comments"
, commentCallbackFunction
);
//--- Page-specific function to do what we want when the node is found.
function commentCallbackFunction (element) {
element.text ("This comment changed by waitForKeyElements().");
@bbugh
bbugh / gist:3882746
Created October 13, 2012 01:04
Accessing alert box in JavaScript with Capybara/rails/rspec
//Get a reference to the alert using the following:
alert = page.driver.browser.switch_to.alert
// and then hit OK with
page.driver.browser.switch_to.alert.accept
// or dismiss it with
@bbugh
bbugh / FormulateFieldset.vue
Last active October 14, 2020 18:38
vue-formulate fieldset for capturing slot data in a named subgroup object rather than array
<template>
<FormulateSlot
name="grouping"
:class="context.classes.grouping"
:context="context">
<FormulateRepeatableProvider
:index="0"
:set-field-value="(field, value) => setFieldValue(field, value)"
:context="context"
@bbugh
bbugh / gist:3909614
Created October 18, 2012 02:52
Ruby 1.9 passing arguments to define_method blocks