Skip to content

Instantly share code, notes, and snippets.

View andrewhao's full-sized avatar

Andrew Hao andrewhao

View GitHub Profile

Keybase proof

I hereby claim:

  • I am andrewhao on github.
  • I am andrewhao (https://keybase.io/andrewhao) on keybase.
  • I have a public key whose fingerprint is ABAD 072E 4722 22E2 9E81 F71C 9865 AEB1 52A6 945A

To claim this, I am signing this object:

@andrewhao
andrewhao / elixir_buildpack.config
Last active June 29, 2016 22:47
Rails and Phoenix Session Sharing
# elixir_buildpack.config
config_vars_to_export=(SECRET_KEY_BASE SESSION_ENCRYPTED_COOKIE_SALT SESSION_ENCRYPTED_SIGNED_COOKIE_SALT DOMAIN)
@andrewhao
andrewhao / pass_1.rb
Last active October 18, 2016 16:16
The Joy of Naming - Domain Driven Design
class Checkout
  def initialize(booking_amount, discount)
    @booking_amount = booking_amount
    @discount = discount
  end
 
  def total
    @booking_amount.total - @discount.calculate_amount_for(booking_amount: booking_amount)
  end
end
@andrewhao
andrewhao / -
Created September 8, 2016 18:17
<?xml version="1.0" encoding="utf-8" ?>
<!ELEMENT tsung (information?, clients, servers, monitoring?, load, options?, sessions)>
<!ELEMENT information (name|description|username|organisation)*>
<!ELEMENT name (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT username (#PCDATA)>
<!ELEMENT organisation (#PCDATA)>
@andrewhao
andrewhao / add_view_paths.rb
Last active January 25, 2023 18:31
Domain-oriented Rails file structures
module Ridesharing
class DriverController
append_view_path(‘app/domains’)
end
end
@andrewhao
andrewhao / asynchronous_operation.rb
Last active December 19, 2016 17:48
Evented Rails
module Ridesharing
  class RidesController < ApplicationController
    def post
      # Hail a time-traveling Delorean: 
      HailDelorean.hail(current_user.id)
      render text: 'Hailing a cab, please wait for a response...'
    end
  end
end
@andrewhao
andrewhao / session_1.md
Last active May 12, 2017 20:58
Carbon Five Elm Study Sessions

Session 1

Welcome to the :c5: Elm study sessions! In this 45-minute session Zoe and Andrew are going to try to lead you through the basics of the Elm language.

You will leave this session with a decent understanding of the core language.

What is Elm?

Elm is a strongly-typed language developed by Evan Czaplicki (apparently, a high school classmate of Sue Anna's). It was a MIT senior thesis project of his (see his paper) in 2012.

@andrewhao
andrewhao / OriginalTodo.elm
Created June 20, 2017 18:22
Elm Study Sessions - Part 3
-- Todo.elm
import Html exposing (Html, Attribute, button, div, ul, li, h1, text, input)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick, onInput)
main =
Html.beginnerProgram { model = model, view = view, update = update }
-- MODEL
@andrewhao
andrewhao / domain-messaging-new-way.rb
Last active May 27, 2018 06:29
Evented Rails - Decoupling complex domains in Rails with Domain Events
# -----------------------------
# Passenger (Experience) Domain
# -----------------------------
module Passenger
# app/domains/passenger/find_driver_match.rb
class FindDriverMatch
include Wisper::Publisher
def call(passenger, ride_requirements)
# Publishes the event (a fact), but lets someone else do the rest of the hard work.
@andrewhao
andrewhao / ValidatedForm.Model.elm
Last active October 12, 2017 23:32
Introduction to Elm
type alias Model =
{ name : String
, phone : String
}
model : Model
model =
{ name = ""
, phone = ""