Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am nateklaiber on github.
  • I am nateklaiber (https://keybase.io/nateklaiber) on keybase.
  • I have a public key whose fingerprint is 6930 A573 358D 135A 2269 F9CC 7B5D D6D8 F811 B831

To claim this, I am signing this object:

View invisible_proxy.rb
class FlatArray
instance_methods.each do |m|
undef_method(m) unless m =~ /(^__|^nil\?|^send$|^object_id$)/
end
def initialize(array)
@target = array
end
def respond_to?(symbol, include_priv=false)
@nateklaiber
nateklaiber / design.md
Last active Oct 28, 2020
API Client Design
View design.md
View convert-seconds-into-hh-mm-ss-in-ruby.rb
t = 236 # seconds
Time.at(t).utc.strftime("%H:%M:%S")
=> "00:03:56"
# Reference
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time
View corpusify.sh
cat *.json |\
jq 'map(select(.from.name=="Nate Klaiber"))' |\
jq '.[].message' |\
grep -v 'jq' |\
sed -e 's/\([[:punct:]]\)//g' |\
grep -v '^$' |\
tr '\n' ' ' |\
tr ' ' '\n' |\
tr '[:upper:]' '[:lower:]' |\
sort |\
@nateklaiber
nateklaiber / .env.sample
Last active Aug 29, 2015
Dover Utilities Electric Usage Information
View .env.sample
API_HOST='http://utilities.theklaibers.com'
CACHE_HOST='localhost:11211'
@nateklaiber
nateklaiber / envelope_expansion_example.md
Last active Aug 29, 2015
Envelope Expansion Example
View envelope_expansion_example.md

I'll use Stripe as an example. The client is responsible for:

  • Configuration
  • Routing
  • Connection Handling
  • Request Handling
    • Raw requests with JSON
    • Object model requests that wrap the raw request (allow us to say Stripe::Request::Charge.get(id: 'sdfsdf'))
  • Object Creation. This includes top level and associations.
View relation_expansion.md

Given an object has an owner association (relation), when expanded by default it will be exposed as:

{
  "name": "service-production",
  "owner": {
    "id": "5d8201b0...",
    "name": "Alice",
    "email": "alice@heroku.com"
  },
@nateklaiber
nateklaiber / name_format.rb
Created Apr 17, 2012
Person Name Forms Evolution
View name_format.rb
class NameFormat
attr_reader :first_name, :last_name, :middle_name
def initialize(person)
@person = person
@first_name = person.first_name
@last_name = person.last_name
@middle_name = person.middle_name