Skip to content

Instantly share code, notes, and snippets.

View byronbowerman's full-sized avatar

Byron Bowerman byronbowerman

View GitHub Profile
# Return JSON exceptions instead of rails' html exceptions
#
# example:
#
# When `params.require(:foo)` is called without a `:foo` parameter
#
# response body:
# {
# "exception": "ActionController::ParameterMissing",
# "message": "param is missing or the value is empty: foo"
@byronbowerman
byronbowerman / 1-given.rb
Created June 9, 2022 17:51
proxy methods to response
def delegate_to_response? name, public_only=false
response.respond_to?(name, public_only)
end
def respond_to_missing? name, public_only=false
delegate_to_response?(name, public_only) || super
end
require 'active_support/core_ext/string/inflections'
class Foo
def initialize *args
puts args.inspect
end
end
class Bar
end
@byronbowerman
byronbowerman / gist:fd9b613f48f4949fcb80543f61c8e889
Created February 5, 2021 04:30
Don't phone home to redmond
sudo nano /etc/apt/sources.list.d/vscode.list
sudo rm /etc/apt/trusted.gpg.d/microsoft.gpg
sudo touch /etc/apt/trusted.gpg.d/microsoft.gpg
sudo chattr +i /etc/apt/trusted.gpg.d/microsoft.gpg
sudo chattr +i /etc/apt/sources.list.d/vscode.list
@byronbowerman
byronbowerman / and_&_&&.rb
Created July 30, 2020 18:48
ruby and, &, && overriding
2.5.8 :001 > class String
2.5.8 :002?> def and(other)
2.5.8 :003?> "#{ self } AND #{ other }"
2.5.8 :004?> end
2.5.8 :005?> end
=> :and
2.5.8 :006 > "foo".and "bar"
=> "foo AND bar"
2.5.8 :007 > "foo" & "bar"
Traceback (most recent call last):
@byronbowerman
byronbowerman / gist:75ddb64d8228701a69920eae9a64aabc
Last active March 30, 2020 07:18
gitlab docker image expiration example
curl --request PUT \
--header 'Content-Type: application/json;charset=UTF-8' \
--header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
--data-binary '{"container_expiration_policy_attributes":{"cadence":"1day","enabled":false,"keep_n":10,"older_than":"90d","name_regex":":(?!v(\d+\.){2}\d+)"}' \
https://gitlab.example.com/api/v4/projects/2'
@byronbowerman
byronbowerman / feature_pattern.rb
Created August 14, 2019 16:10
Brainstorming about a pattern to use around checking feature flags
# Usage:
#
# class MyClass
# feature :my_feature
# end
#
# Defines the following instance method in MyClass:
#
# def my_feature *args
# if Feature.active?(:my_class_my_feature)
@byronbowerman
byronbowerman / keybase.md
Created February 7, 2019 16:27
Keybase Proof

Keybase proof

I hereby claim:

  • I am byronbowerman on github.
  • I am bm5k (https://keybase.io/bm5k) on keybase.
  • I have a public key ASDEciwhabrTBtffdF3QwZES9vwd6ccEkFNADrCJMk3LTwo

To claim this, I am signing this object:

@byronbowerman
byronbowerman / contrived_example.rb
Last active October 19, 2018 00:49
Example ruby class structure
require 'securerandom'
module MyNamespace
class ContrivedExample < ApplicationRecord
MINIMUM_DESIRED = 3
extend Forwardable
include MyNamespace::Shared