Skip to content

Instantly share code, notes, and snippets.

View yowchun93's full-sized avatar
🇲🇾
Hello from Malaysia!

YC Yap yowchun93

🇲🇾
Hello from Malaysia!
View GitHub Profile
@yowchun93
yowchun93 / deaf_aunty.exs
Created February 15, 2021 03:43
Elixir
defmodule DeafAunty do
def run do
read_input(0)
end
# main loop
defp read_input(consecutive_byes) when consecutive_byes < 3 do
IO.read(:stdio, :line)
|> String.trim
|> talk_to_aunty(consecutive_byes)
@yowchun93
yowchun93 / coin_gecko.md
Created October 25, 2020 08:21
CoinGecko job application

1. Tell us about a newer web technology that you like

The one technology that piqued my interest in TypeScript. As a software engineer that has work mostly on dynamic typed languages such as Ruby and Javascript, learning TypeScript has been a really eye opening experience for me.

My general experience of using TypeScript and this is based on my personal experience , using a typed language does the following things better than a dynamically typed language:

  1. Types together with Automated tests, give developers the confidence to refactor code, because of the help you get from the compiler and IDE. This generally means that the code will have less technical debt.
  2. Modelling domain objects using Typescript' structural sub-typing. As opposed to the classic typing from c# and java, typescript's type system .

Now code are written coupled to interface, as opposed to class-typing done in Java.

@yowchun93
yowchun93 / custom_validator.rb
Last active August 13, 2020 12:38
Custom Validators
# Creating custom validator
# https://github.com/igorkasyanchuk/active_storage_validations/blob/master/lib/active_storage_validations/size_validator.rb
# inherited
class SizeValidator < ActiveModel::EachValidator
def check_validity!
raise ArgumentError, ‘bla bla’
end
@yowchun93
yowchun93 / checkout_service.rb
Last active August 11, 2020 08:45
Refactoring using OOP
# CheckoutService takes a cart, and checkouts each cart items
class CheckoutService
def initialize(cart, params)
@cart = cart
@params = params
end
def run
create_order
if order_approved? && cart.checked_out_at.nil?
@yowchun93
yowchun93 / race_condition.rb
Created July 28, 2020 03:41
Simulation race conditions using Threads
it 'does not allow multiple reservations on same spot' do
wait_for_all_threads = true
reservation_counter = ReservationCounterQuery.find_or_initialize_by_params(account, {
schedule_id: schedule.id,
date: Date.today.to_s
})
form1 = Reservation::SpotBooking::CreateForm.new(count: 1, reserved_spots: '1')
form2 = Reservation::SpotBooking::CreateForm.new(count: 1, reserved_spots: '1')
@yowchun93
yowchun93 / shopify_session.rb
Created April 23, 2020 01:50
ShopifySession
gem 'shopify_app'
ShopifyApp
def callback
if auth_hash
end
end
@yowchun93
yowchun93 / asyncAwait.ts
Last active April 22, 2020 00:14
Async Await in Typescript
function delay(milliseconds: number, count: number): Promise<number> {
return new Promise<number>(resolve => {
setTimeout(() => {
resolve(count);
}, milliseconds )
})
}
async function dramaticWelcome(): Promise<void> {
for (let i = 0; i < 5; i++) {
@yowchun93
yowchun93 / order_creation_strategy.rb
Last active April 16, 2020 06:17
Order creation strategy
## Might be unpopular , but i dont think we need this class because Ruby != Java LOL
## We should trust the object to implement create_order
class CourierAPI::OrderCreationStrategy::Base
attr_reader :order, :error_message
def create_order(parcel)
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
end
end
@yowchun93
yowchun93 / childRenderProps.jsx
Last active April 6, 2020 13:36
Children render props
export default function App() {
return (
<div className="App">
<Toggle
render={(on, toggle) => (
<div>
{on && <h1>Hello</h1>}
<button onClick={() => toggle()}>toggle</button>
</div>
)}
@yowchun93
yowchun93 / tsGenerics.ts
Last active April 6, 2020 02:39
Practising TS generics
// create a function which takes an array of any types, and return a value of that type
// create a function which takes 2 values of any type and return an array of the type
// create a function called 'makeFullName', which takes an object
// create a function called 'makeFullName', which takes an object with attribute { firstName, lastName }
// making it optional
interface UserName {