Skip to content

Instantly share code, notes, and snippets.

View zjkuang's full-sized avatar

Zhengqian (John) Kuang zjkuang

View GitHub Profile
@zjkuang
zjkuang / one-one.js
Created July 6, 2024 00:47
One; one one; two one; one two, one one; ...
// [1]
// [1,1]
// [2,1]
// [1,2,1,1]
// [1,1,1,2,2,1]
// [3,1,2,2,1,1]
// [1,3,1,1,2,2,2,1]
// [1,1,1,3,2,1,3,2,1,1]
// [3,1,1,3,1,2,1,1,1,3,1,2,2,1]
// [1,3,2,1,1,3,1,1,1,2,3,1,1,3,1,1,2,2,1,1]
@zjkuang
zjkuang / smallest-positive-number.js
Last active March 23, 2023 15:34
Get the smallest positive number in JavaScript
// Consider the "smallest" positive number in JavaScript, (where there are 322 zeros before "1" after the point,)
const a = 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001;
// I call it "smallest" because if we add one more zero before the "1", JavaScript takes it as zero:
const a0 = 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001;
console.log(`a0 == 0: ${a0 == 0}`); // true
// Now let's check a number b9,
// a = 0.0...01 // 0.(322 zeros)1
// b9 = 0.0...009
@zjkuang
zjkuang / README.md
Created November 17, 2022 16:07
locate-yourself

In Termial, run

npx <url-of-this-gist>

Each time you make any change, remember to update the version in package.json

Sophie's Maths

In Terminal, npx <url-of-this-gist>

IMPORTANT: If you have made any changes in the script, to make the changes visible, make sure you update the version number in package.json

@zjkuang
zjkuang / SQL
Created October 6, 2021 12:30
SQL
Visual Representation of SQL Joins
https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins
@zjkuang
zjkuang / anyToString.ts
Created September 8, 2021 18:44
TypeScript: Convert any to string
function anyToString(a: any): string {
if (Array.isArray(a)) {
let s = '[';
const arr = a as Array<any>;
const numberOfElements = arr.length;
arr.map((e, index) => {
let eString = anyToString(e);
s = s + eString;
if (index + 1 < numberOfElements) {
s = s + ',';
// TypeScript Playground - https://www.typescriptlang.org/play
////////////////////////////////////////////////////////////////////////////////
// Start multiple promises simultaneously and execute them in parallel
const p1 = new Promise((resolve) => {
setTimeout(() => {
const result = Date();
console.log(`r1: ${result}`);
@zjkuang
zjkuang / CombineCheatSheet
Created May 17, 2020 22:40
Combine Cheat Sheet By Zhengqian (John) Kuang
//
// CombineCheatSheet.swift
//
//
// Created by Zhengqian Kuang on 2020-05-17.
//
import Foundation
import Combine
@zjkuang
zjkuang / keybase.md
Last active August 26, 2019 15:23
Keybase gist

zjkuang Zhengqian (John) Kuang iOS Developer Regina, SK, Canada

Keybase proof

I hereby claim: