Skip to content

Instantly share code, notes, and snippets.

View nateklaiber's full-sized avatar

Nate Klaiber nateklaiber

View GitHub Profile
@nateklaiber
nateklaiber / name_format.rb
Created April 17, 2012 18:37
Person Name Forms Evolution
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
@nateklaiber
nateklaiber / relation_expansion.md
Created May 27, 2014 15:15
API Relation Expansion

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 / envelope_expansion_example.md
Last active August 29, 2015 14:01
Envelope Expansion Example

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.
@nateklaiber
nateklaiber / .env.sample
Last active August 29, 2015 14:13
Dover Utilities Electric Usage Information
API_HOST='http://utilities.theklaibers.com'
CACHE_HOST='localhost:11211'
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 |\
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
@nateklaiber
nateklaiber / design.md
Last active April 24, 2024 18:11
API Client Design
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)

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:

@nateklaiber
nateklaiber / _overview.md
Last active March 8, 2024 15:53
Pizza Service SDK Architecture

SDK Architecture

Rough Draft

This is still in rough draft form. I will continue to make edits as I receive them. I will collate the list of feedback here and make notes of the changelog as revisions are made.

What does it solve?

String Interpolation

No string interpolation for building your routes to your resources.