Skip to content

Instantly share code, notes, and snippets.

@kyledcline
kyledcline / routing_number_validator.rb
Last active December 22, 2023 14:43
ABA Routing Number Validator for Rails
# frozen_string_literal: true
class RoutingNumberValidator < ActiveModel::EachValidator
WEIGHTS = ([3, 7, 1] * 3).freeze
DIVISOR = 10
def validate_each(record, attribute, value)
return if value.blank?
@kyledcline
kyledcline / postgres-best-practices.md
Last active October 26, 2023 06:10
Postgres Best Practices

PSQL CLI Client

Psql is a fully-fledged CLI client for Postgres, but most people are unaware of its many advanced features.

~/.psqlrc can be edited to persist any behavior or configuration settings you want between psql sessions. It behaves just like ~/.bashrc or ~/.vimrc, sourced at psql launch. See More out of psql for some interesting configurations.

If you have a long query to write and rewrite, you can use \e to edit your query in an editor.

Use \watch at the end of a query in order to automatically re-run the query every few seconds - great for monitoring while making changes elsewhere in your application architecture.

@kyledcline
kyledcline / keybase.md
Created August 26, 2016 17:02
Cryptographically verified identity

Keybase proof

I hereby claim:

  • I am kyledcline on github.
  • I am kyledcline (https://keybase.io/kyledcline) on keybase.
  • I have a public key whose fingerprint is 9B71 78FB 7745 B052 CB2B E30C 9E83 161C F775 A269

To claim this, I am signing this object:

@kyledcline
kyledcline / binary_search_tree.rb
Last active August 29, 2015 14:01
Simple binary search tree
class BinarySearchTree
Node = Struct.new(:key, :left, :right)
attr_reader :root
def initialize(root=nil, *keys)
@root = Node.new(root)
build_tree(*keys) unless keys.empty?
end