Skip to content

Instantly share code, notes, and snippets.

View alvinncx's full-sized avatar
👋
Happy to chat!

Alvin Ng alvinncx

👋
Happy to chat!
View GitHub Profile
@alvinncx
alvinncx / config.exs
Last active February 4, 2021 12:30
Getting Phoenix.PubSub & Phoenix.LiveView to work together
# Configures the endpoint
config :example, Example.Endpoint,
...
pubsub: [name: Example.PubSub, adapter: Phoenix.PubSub.PG2],
...
@alvinncx
alvinncx / regex.ex
Created April 6, 2019 07:54
Username and email regex
@mail_regex ~r/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/
@username_regex ~r/^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$/
@alvinncx
alvinncx / parser.ex
Last active April 20, 2019 06:37
Parsing DBS transactions
defmodule Parser do
@moduledoc """
Sample parser for data from DBS. It is annoying that there isn't a csv from DBS bank
Sample data:
18 Mar 2019 GRAB *16236905-9-139 S$23.00
18 Mar 2019 GRAB *2B3B63422351042EE S$10.00
18 Mar 2019 GRAB *1391705-9-138 S$15.00
19 Mar 2019 2C2P - ZARA.COM SG S$29.90 cr
@alvinncx
alvinncx / form.elm
Created September 7, 2019 07:23
Playing with Elm v0.19.0
import Browser
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
-- Main
main =
Browser.sandbox {init = init, update = update, view = view}
-- Model
@alvinncx
alvinncx / the_mythical_man_month.md
Last active August 26, 2020 07:00
The Mythical Man-month

If you happen to be reading the 20th anniversary edition of The Mythical Man-month, you can skip right to Chapter 18 for an outline of the entire book. Why this was added later is anyone's guess...

Chapter 2

  • Adding more people into a project that is overdue, makes it even later.
  • Throwing people at project without consideration of training, reallocation and communication is a disaster.
  • I used to apply the naive way of calculating time for a project. I was often wrong.
  • Eventually I found that using 4x the time of the initial estimates works well.
  • This is based on the assumption of degrees of freedom. If only developer is estimating, it is 2x original estimate. If requirements are incertain, then add additional 2x. This amounts to 4x.
  • Time for administration and ramp-up is often underestimated.
@alvinncx
alvinncx / notes.md
Last active August 24, 2020 10:35
My thoughts on Sandi Metz's presentation on better OOP Design

My thoughts on Sandi Metz's presentation on better OOP Design

Youtube Link

How to write better Object Oriented code. The central claim is that OO is not a problem, but many teams are not utilising the features of OO to design better code. Her other point is also that design becomes more important late stage as code bases becomes bigger.

Takeaway points

  • Premature design is bad. Does not really add value. However when design is required later, it is too late and most people don't know how to do it properly.
  • Code that is properly abstracted should be easier to change than complex routines. However, wrongly abstracted code can also make it as difficult at complex code.
@alvinncx
alvinncx / chapt_5.md
Last active September 29, 2020 06:03
Summary of Code Complete 2

Design in construction

  • Software’s Primary Technical Imperative is managing complexity. This is greatly aided by a design focus on simplicity.
  • Simplicity is achieved in two general ways: minimizing the amount of essential complexity that anyone’s brain has to deal with at any one time, and keeping accidental complexity from proliferating needlessly.
  • Design is heuristic. Dogmatic adherence to any single methodology hurts cre- ativity and hurts your programs.

Information Hiding

  • Foundation of OOP and structured design
  • Thinking in objects vs thinking in information hiding
    • Hiding abstracts complexity and delays lock in; thinking in OOP locks you into smaller set of decisions
  • e.g. Should something be declared as a new class
@alvinncx
alvinncx / models.rb
Last active October 10, 2020 08:10
Refactoring exercise #1
class Price
def price_code; end
def charge; end
def frequent_renter_points
1
end
class Childrens
def price_code; Movie::CHILDRENS; end
def charge(days_rented)
@alvinncx
alvinncx / chapter2.md
Last active August 17, 2021 16:13
Refactoring by Martin Fowler

Principles in Refactoring

Purpose of refactoring

  • Make the software easier to understand
  • Does not change observable behavior

Difficult to change

  • Programs that are hard to read are hard to modify.
  • Programs that have duplicated logic are hard to modify.
  • Programs that require additional behavior that requires you to change running code are hard to modify.
@alvinncx
alvinncx / day1.md
Last active November 20, 2020 01:34
Scrummaster course 17 Nov 2020

Sprint is a cycle lasts 4 weeks

  • Don't like the name, not sustainable
  • 2 weeks more common
  • No gap or delay between sprints

Stages

Plan

Sprint goal

  • Valuable, clear, realistic, won't change