Skip to content

Instantly share code, notes, and snippets.

@erikdstock
erikdstock / url_matchers.rb
Created April 20, 2017 14:34
Query param matchers for rspec/rails
# Match query params on some url somewhere in a text [actually a mail.body, hence the to_s]
# Not tested in production
RSpec::Matchers.define :include_query_params do |expected|
match do |actual|
query_finder = /http\S+\?(\S+)["\s'>]/
queries = query_finder.match actual.to_s
queries.captures.any? do |q|
q_hash = Rack::Utils.parse_nested_query(q).symbolize_keys
q_hash.merge(expected) == q_hash
end
@erikdstock
erikdstock / 0_reuse_code.js
Created April 24, 2017 14:48
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@erikdstock
erikdstock / lint-diff-package.json
Last active May 2, 2017 21:04 — forked from kadamwhite/lint-diff-package.json
Use `git diff` and `grep` to selectively lint changed files
{
"scripts": {
"jshint:branch": "jshint $(git diff --name-only --diff-filter=ACMRTUXB $(git merge-base head master) | grep '.js$') || true",
"jshint:diff": "jshint $(git diff --name-only --diff-filter=ACMRTUXB | grep '.js$') || true",
"jshint:prev": "jshint $(git diff head~1 --name-only --diff-filter=ACMRTUXB | grep '.js$') || true",
"coffeelint:diff": "coffeelint $(git diff --name-only --diff-filter=ACMRTUXB | grep '.coffee$') || true"
}
@erikdstock
erikdstock / github-show-outdated.txt
Last active September 12, 2019 05:37
Unhide outdated Github PR Comments bookmarklet
// Save as a bookmarklet
// unhides out of date comments on a Github PR, coloring the title bars in these code blocks.
javascript:void function(){
document.querySelectorAll(".show-outdated-button").forEach(function(button){
var banner = button.parentNode;
button.click();
banner.style.backgroundColor = '#e2d2ff';
banner.childNodes.forEach(function(child){});
});
}();

Links

Remove files from a repo's history

Another one

Helpful commands

find commit in remote heroku history

git fetch heroku && git log heroku/master --pretty=oneline | grep $(git log -1 --format="%H") || echo 'nope'

print heroku log since this commit (won't fail, just prints entire log)

What is going on with kernel_task, accountsd etc

sudo lsof | grep -i kernel
#  also works for accountsd
# =>
# KernelEve   118  root  txt  REG   1,4    662257664 20143772 /private/var/db/dyld/dyld_shared_cache_x86_64h

# 7th col '662257...' is file size (big). in this case it is dyld shared cache, related to xcode.
@erikdstock
erikdstock / ruby-closures.rb
Created September 26, 2017 20:38 — forked from pcantrell/ruby-closures.rb
Closures in Ruby
# CLOSURES IN RUBY Paul Cantrell http://innig.net
# Email: username "cantrell", domain name "pobox.com"
# I recommend executing this file, then reading it alongside its output.
#
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments,
# then trying to guess the output of the code!
# A closure is a block of code which meets three criteria:
@erikdstock
erikdstock / Validation.ts
Created May 27, 2018 22:05
Basic input validation [TypeScript]
// currently this assumes every input is a string
export interface InputStrings {
[everyProp: string]: string
}
type ValidationRule = (val: string) => boolean
type Errors<Inputs> = Partial<{ [P in keyof Inputs]: string }>
type Validator = (val: string) => string | void
type MakeValidator = (msg?: string) => Validator
type MakeValidatorWithArg = (arg: any, msg?: string) => Validator
@erikdstock
erikdstock / one-off-docker-command.sh
Created October 17, 2018 02:52
Docker shell commands
#!/usr/bin/env bash
# Start your built mycoolservice image with a bind mount on its source files in your ./myservice folder
DIR=$(dirname "$0") # relative
ROOT="$( cd "$DIR/.." && pwd )" # root, absolutized and normalized
Start the backend (docker)
cmd="docker run -p 8000:8000"\
" --mount src=$ROOT/myservice,target=/code,type=bind"\

Keybase proof

I hereby claim:

  • I am erikdstock on github.
  • I am erikdstock (https://keybase.io/erikdstock) on keybase.
  • I have a public key ASCKupOd3yVYrqY4tHkyUmwl51kckhpi_Awj7wLCIcmNSwo

To claim this, I am signing this object: