Skip to content

Instantly share code, notes, and snippets.

View xwlee's full-sized avatar
🎯
Focusing

Lee Xiang Wei xwlee

🎯
Focusing
View GitHub Profile
@xwlee
xwlee / map-morphism.ts
Last active May 22, 2024 07:22
map-morphism.ts
// List
type List<A> = Nil | Cons<A>;
interface Nil {
readonly _tag: "Nil";
}
interface Cons<A> {
readonly _tag: "Cons";
readonly head: A;
@xwlee
xwlee / double-linked-list.js
Created July 21, 2023 15:01
double-linked-list.js
class Node {
constructor(value) {
this.value = value
this.next = null
this.prev = null
}
}
class DoubleLinkedList {
constructor(value) {
@xwlee
xwlee / linked-list.js
Created July 21, 2023 15:00
linked-list.js
class Node {
constructor(value) {
this.value = value
this.next = null
}
}
class LinkedList {
constructor(value) {
const newNode = new Node(value)
@xwlee
xwlee / filterAsync.ts
Created June 7, 2023 04:48
filterAsync.ts
const filterAsync = <T>(arr: T[], fn: (x: T) => Promise<boolean>) =>
mapAsync(arr, fn).then((arr2) => arr.filter((_, i) => Boolean(arr2[i])));
(async () => {
console.log("START FILTER");
const filtered = await filterAsync([1, 2, 3, 4], async (n) => {
const x = await fakeFilter(n);
return x;
});
useResult(filtered);
@xwlee
xwlee / forEachAsync.ts
Created June 7, 2023 04:36
forEachAsync.ts
const forEachAsync = <T>(arr: T[], fn: (x: T) => any): Promise<any> =>
arr.reduce(
(promise: Promise<void>, value: T) => promise.then(() => fn(value)),
Promise.resolve()
);
(async () => {
console.log("START FOREACH VIA REDUCE");
await forEachAsync([1, 2, 3, 4], async (n) => {
const x = await fakeAPI(n * 1000, n);
@xwlee
xwlee / mapAsync.ts
Created June 7, 2023 04:35
mapAsync.ts
const mapAsync = <T, R>(arr: T[], fn: (x: T) => Promise<R>) =>
Promise.all(arr.map(fn));
(async () => {
console.log("START MAP");
const mapped = await mapAsync([1, 2, 3, 4], async (n) => {
const x = await fakeAPI(n * 1000, n);
return x * 10;
});
useResult(mapped);
@xwlee
xwlee / helm.md
Last active April 25, 2020 07:21
Helm 3

Install Helm

brew install helm

Initialize official Helm chart repository

helm repo add stable https://kubernetes-charts.storage.googleapis.com/
@xwlee
xwlee / Kubelet.md
Last active April 20, 2020 16:14
Kubelet

Kubelet

  • The kubelet is the agent that runs on each node, and is responsible for launching pods.
  • It doesn't directly run containers but instead controls a runtime, such as Docker or rkt.
  • The kubelet operates at the level of PodSpec, so it only knows how to launch pods.
  • The kubelet also runs a tool called cadvisor that collects metrics about resource usage on the node, and using each container that is running on the node, this information can then be used by Kubernetes when making scheduling decisions.
@xwlee
xwlee / using-minikube-cluster.md
Last active September 23, 2019 14:35
Using Minikube Cluster

Install minikube

brew install minikube

Create minikube cluster

minikube start
@xwlee
xwlee / date-directive.js
Created December 23, 2018 08:04
Apollo Server Date Directive
const { ApolloServer, gql, SchemaDirectiveVisitor } = require('apollo-server');
const { GraphQLScalarType, defaultFieldResolver, GraphQLString } = require('graphql');
const { Kind } = require('graphql/language');
const formatDate = require("dateformat");
const typeDefs = gql`
directive @date(
defaultFormat: String = "mmmm d, yyyy"
) on FIELD_DEFINITION