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 / 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 / solution.rb
Created December 8, 2021 15:10
Advent Of Code 2021 - Day 8 Solution (Part 2)
# By far the most tedious puzzle to get the 2nd ⭐️
# Display class -> this is where most of the logic happens. Use different combinations of digit segments to determine
# the correct mapping
class Digit
attr_accessor :segments, :length
def initialize(raw)
@raw = raw
@segments = raw.split('')
@alvinncx
alvinncx / solution.rb
Created December 14, 2021 10:03
Advent Of Code 2021 - Day 10 Solution (Part 2)
# Pretty simple challenge. The key is to loop through the string to keep finding instances of legal chucks and remove them.
# Chucks are made of itself so you can just keep removing the simplest chunks
class Line
attr_reader :temp
def initialize(raw)
@raw = raw
@temp = raw
parse