Skip to content

Instantly share code, notes, and snippets.

Working from home

Alvin Ng alvinncx

Working from home
View GitHub Profile
alvinncx / myModule.ts
Last active Jul 22, 2021
Mocking Typescript named export modules
View myModule.ts
export const function1 = () => {
return 'awesome'
export const function2 = () => {
return 'not so awesome'
alvinncx /
Last active Nov 20, 2020
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



Sprint goal

  • Valuable, clear, realistic, won't change
alvinncx /
Last active Nov 26, 2020
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 / models.rb
Last active Oct 10, 2020
Refactoring exercise #1
View models.rb
class Price
def price_code; end
def charge; end
def frequent_renter_points
class Childrens
def price_code; Movie::CHILDRENS; end
def charge(days_rented)
alvinncx /
Last active Sep 29, 2020
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 /
Last active Aug 24, 2020
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 /
Last active Aug 26, 2020
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 / form.elm
Created Sep 7, 2019
Playing with Elm v0.19.0
View form.elm
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 / parser.ex
Last active Apr 20, 2019
Parsing DBS transactions
View parser.ex
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 / regex.ex
Created Apr 6, 2019
Username and email regex
View regex.ex
@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._]+(?<![_.])$/