May 16Time Complexity of Creating a Heap (or Priority Queue)There are two ways to create a heap of n elements: heapify an existing array of n elements: O(n) of time complexity; create an empty heap instance, and then enqueue n elements one by one: O(nlogn)of time complexity. Heapify For example, python’s heapify() from heapq module: heapq - Heap queue algorithm - Python 3.10.4 documentation Source code: Lib/heapq.py This module provides an implementation of the heap queue algorithm, also known as the…docs.python.orgHeap2 min readHeap2 min read
Jan 31Work with Python DictionaryThe dictionary is a data type that people use day to day in Python. This post covers the basic knowledge a Python developer need to know when working with a dictionary. What is a dictionary for How to create a dictionary How to use a dictionary What is a dictionary for? For storing key–value pairs…Python5 min readPython5 min read
Jan 24Syntax Comparison: TypeScript vs SwiftThis post compares basic syntax between languages of JavaScript/TypeScript and Swift, while making notes about Swift from the perspective of a JavaScript/TypeScript developer. The order of the topics in this post is based on A Swift Tour. …Typescript7 min readTypescript7 min read
Jan 24The 4 Most Common Geometries in KMLKeyhole Markup Language (KML) is an XML notation for expressing geographic annotation and visualization within two-dimensional maps and three-dimensional Earth browsers. In this post, we are going to first quickly introduce KML file structure and <Placemark> element, then focus on the 4 most common geometries that can be used in…Kml6 min readKml6 min read
Dec 30, 20212021读完的9本书我在2020年读完了12本书,而今年2021年只读完的9本。另有若干本尚未读完,哪年读完算哪年。 Dirty Chinese读书推荐7 min read读书推荐7 min read2021读完的9本书我在2020年读完了12本书,而今年2021年只读完的9本。另有若干本尚未读完,哪年读完算哪年。Dirty Chinese----
Mar 8, 2020The return type of a function conditionally returning a Promise or a non-Promise valueImagine the following workflow: You have an object, possibly hydrated already. Before use it, you need to make sure it is actually hydrated, otherwise you need to first asynchronously hydrate it. Luckily, you can easily determine if you need to hydrate it or not, because it is typed as interface…Java Script2 min readJava Script2 min read
Aug 28, 2019How to properly break/wrap a long string in a grid?What do you mean by a long string? By “long string” I mean strings like start________________________________end where there is no space, word break opportunity, hyphens, whatsoever. Why should I care about this kind of imaginary long strings? Because sometimes you need to properly display a URL an ID (e.g. wojuedingyongpinyindayijuhuajiazhuangshiyigeid) a pseudo string for translation … What options do I have?CSS1 min readCSS1 min read
Apr 30, 2019Manipulating inline styles using JavaScriptThe first thing we do, let’s get elements Let’s say we have this DOM: <html> <body> <div id="some-id" class="some-class-name">target element</div> </body> </html> and we want to get the div element from it. Here are several DOM methods to do that: getElementById() const elem = document.getElementById('some-id'); getElementsByClassName() const elem = document.getElementsByClassName('some-class-name')[0];Java Script2 min readJava Script2 min read
Apr 28, 2019How to get two characters’ ASCII decimal value difference and how +/- are not inverse in JavaScriptIn Java, 'b' - 'a' // 1, the diff between two ASCII decimal values, 98 and 97 'b' + 'a' // 195, the sum of two ASCII decimal values, 98 and 97 Note that 'b' and 'a' in Java are chars, not strings. In JavaScript, where there is no char…Java Script1 min readJava Script1 min read