Skip to content

Instantly share code, notes, and snippets.

View wongjiahau's full-sized avatar

WJH wongjiahau

  • Malaysia
View GitHub Profile
@wongjiahau
wongjiahau / react-native-practical-4-answer (async storage)
Last active September 20, 2018 09:57
React Native Async Storage Example
import React, { Component } from "react";
import {
AsyncStorage,
View,
TextInput,
Picker,
Text,
Button
} from "react-native";
replace with : (String , String , String) -> String
x replace y with z =
'a List :> nil
'a List :> 'a head ; 'a
x = 1 head ; 1 ; 2 ; 3 ; 4
@wongjiahau
wongjiahau / exercise.js
Last active December 5, 2018 04:06
Filter Map Reduce Exercise
let xs = [1,2,3,4,5,6,7,8,9,10]
// Q1. Take only the number that is more than 5
// Q2. Multiply each number by 5
// Q3. Add all numbers together
let people = [
@wongjiahau
wongjiahau / hi.ts
Created December 11, 2018 07:00
aeon admin portal endpoint
import { Endpoint } from "../../src/lib/DiloServer";
/**
* Common response code
* 401 - Request body error
* 500 - Internal server error
*/
const LIST_OF_PERMISSIONS = {
"1100": true, // User management
@wongjiahau
wongjiahau / shape.txt
Created February 13, 2019 07:39
Data of shapes
NULL
Circle 5
Rectangle 3 4
Circle 3
Rectangle 8 1
Square 5
NULL
Rectangle 6 0
NULL
Square 8
@wongjiahau
wongjiahau / main.hs
Created February 14, 2019 10:36
Simple Type Inference System in Haskell
import qualified Data.Map.Strict as Map
import Data.List
-- This implementation is based on https://medium.com/@dhruvrajvanshi/type-inference-for-beginners-part-1-3e0a5be98a4b
data Expression
= EInt
Int -- value
| EVar
String -- name
@wongjiahau
wongjiahau / Main.hs
Created February 15, 2019 05:17
TeachingHaskell-Exercise 1-Answer
data Shape
= Circle Float
| Square Float
| Rectangle Float Float
| Null
deriving (Show)
main :: IO ()
main = do
-- Read contents from shape.txt
interface Shape {}
class Circle extends Shape {
constructor(public radius: number) {}
}
class Rectangle extends Shape {
construtor(public height: number, public width: number) {}
}
class Triangle extends Shape {
constructor(public height: number, public base: number) {}
}
const newShape2: Shape = {
label: 'circle',
width: 30 // You'll get a compiler error saying `width` does not exists when label is `circle`
}
const getArea = (shape: Shape) => {
if (shape.radius) {
return Math.PI * Math.pow(shape.radius, 2)
}
else if (shape.height && shape.width) {
return shape.height * shape.width
}
else if (shape.base && shape.height) {
return 0.5 * shape.base * shape.height
}