Skip to content

Instantly share code, notes, and snippets.

@bbugh
bbugh / draw.io_export.bttpreset
Created December 15, 2023 16:14
BetterTouchTool Cmd+/- zooming for draw.io
[
{
"BTTAppBundleIdentifier" : "com.jgraph.drawio.desktop",
"BTTAppName" : "draw.io",
"BTTAppAutoInvertIcon" : 1,
"BTTAppProcessMatchMode" : 2,
"BTTAppProcessName" : "draw.io",
"BTTTriggers" : [
{
"BTTLastUpdatedAt" : 1702656741.3490081,
@bbugh
bbugh / earthly.plugin.zsh
Created August 18, 2022 13:23
Earthly aliases
alias 'e'="earthly"
alias 'ealias'="alias | grep --color=never earthly"
alias 'ea'='earthly account'
alias 'eac'='earthly account create'
alias 'eah'='earthly account help'
alias 'eai'='earthly account invite'
alias 'ealp'='earthly account list-permissions'
alias 'eals'='earthly account ls'
alias 'ear'='earthly account revoke'
@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 / union_scope.rb
Created July 29, 2019 20:46
Rails ActiveRecord UNION scope extension - adds chainable union functionality to ActiveRecord
# MIT License, Copyright (c) 2019 Brian Bugh
# Do a UNION on two or more scopes, combining the results. Unlike Rails arel
# unions/`or`, this will preserve the ActiveRecord_Relation and allows for
# `joins` and `references`. It can also be chained with a scope without issue.
#
# NOTE: the scope `select` for each union must match; you can't select a smaller
# column subset and UNION it (this is a limitation of SQL).
#
# ==== Examples
@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 / 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 / _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 / apollo.js
Last active August 11, 2022 07:42
Apollo Action Cable setup
import { ApolloClient } from 'apollo-client'
import { split } from 'apollo-link'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { getMainDefinition } from 'apollo-utilities'
import { createPersistedQueryLink } from 'apollo-link-persisted-queries'
import { setContext } from 'apollo-link-context'
// AC: IMPORT ACTIONCABLE
import ActionCable from 'actioncable'
@bbugh
bbugh / results.txt
Created March 8, 2018 16:04
Benchmarking for checking if one array contains another in Ruby
Warming up --------------------------------------
subtract 233.432k i/100ms # higher is better
bitwise & == 164.352k i/100ms
bitwise & size 218.548k i/100ms
bitwise & [] 200.794k i/100ms
contains_all 74.648k i/100ms
contains_all_count 112.634k i/100ms
set 19.238k i/100ms
set cached 194.675k i/100ms
all? include? 144.048k i/100ms
@bbugh
bbugh / array_inclusion_validator.rb
Last active November 6, 2023 14:53
Rails Postgres Array Column Validator
# app/models/validators/array_inclusion_validator.rb
class ArrayInclusionValidator < ActiveModel::EachValidator
include ActiveModel::Validations::Clusivity
def validate_each(record, attribute, values)
values.each do |value|
unless include?(record, value)
message = (options[:message].try(:gsub, '%{value}', value) || "#{value} is not included in the list")
record.errors.add(attribute, :array_inclusion, message: message, value: value)
end