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 / double-linked-list.js
Created July 21, 2023 15:01
double-linked-list.js
View 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
View 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
View 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
View 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
View 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
View helm.md

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
View Kubelet.md

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
View using-minikube-cluster.md

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
View date-directive.js
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
@xwlee
xwlee / rest-directive.js
Created December 23, 2018 06:01
Apollo Server REST Directive
View rest-directive.js
const {
ApolloServer,
gql,
SchemaDirectiveVisitor
} = require('apollo-server');
const fetch = require('node-fetch');
const typeDefs = gql`
directive @rest(url: String) on FIELD_DEFINITION