Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Undefined behavior

Leedehai

:octocat:
Undefined behavior
View GitHub Profile
@Leedehai
Leedehai / gh_server.js
Last active March 24, 2022 00:33
Static server that mimics GitHub Pages.
View gh_server.js
// Static server that mimics GitHub Pages.
import chalk from 'chalk';
import express from 'express';
import * as fs from 'fs';
import http from 'http';
import path from 'path';
import {fileURLToPath} from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@Leedehai
Leedehai / dark_mode.md
Created August 23, 2020 22:15
Support dark mode with vanilla HTML, CSS, JavaScript.
View dark_mode.md

Supporting dark mode

Using vanilla HTML, CSS, JavaScript, on a static site.

Credit: Ryan Feigenbaum.

Developers love dark mode, especially during the night. Supporting dark mode on the page is not only beneficial, but also arguably imperative, given that human eyes don't handle sudden change in brightness well.

@Leedehai
Leedehai / rotating_log.py
Created August 18, 2020 04:15
Rotating log, Unix domain socket implementation
View rotating_log.py
#!/usr/bin/env python3
# Python 3.7+
import multiprocessing.dummy as mp # Threading wrapped using multiprocessing API.
import os
import queue
import socket
import socketserver
import sys
View color256.py
#!/usr/bin/env python
# Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349
print("xterm-256color color set\n")
colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
colored_palette = [
"%02x%02x%02x" % (r, g, b)
for r in colored
for g in colored
@Leedehai
Leedehai / progressbar.py
Last active June 4, 2020 23:09
Colored progress bar in Python (tested on Linux/macOS)
View progressbar.py
#!/usr/bin/env python3
import os, sys
from enum import Enum, unique
from typing import Optional
@unique
class ProgressBarColor(Enum):
BLUE = "\x1b[38;5;75m"
PINK = "\x1b[38;5;203m"
@Leedehai
Leedehai / Clang-with-libc++.md
Last active October 6, 2020 18:46
So, your Clang wants to compile with libc++.
View Clang-with-libc++.md

Clang with libc++

TL;DR: On macOS you are fine, if you didn't tweak its default compiler toolchain. If you did tweak it (e.g. use Clang downloaded from its official source or with a package manager), or if your OS is Linux, read below.

The C++ standard library has many well-maintained implementations, chief of them LLVM's libc++ and GNU's libstdc++. The standard library, including the headers and the binary itself, usually come with the downloaded compiler package: libc++ is with Clang and libstdc++ is with GCC.

@Leedehai
Leedehai / canvas.html
Last active April 17, 2020 21:40
So, you want to paint in HTML5 canvas.
View canvas.html
<!-- The boilerplate for HTML5 canvas painting. View in browser.
How to use: create canvas.js in the same directory and get the
canvas object by the element id "canvas". Draw on the canvas.
-->
<html translate="no">
<head>
<title>Canvas sketching</title>
<meta name="google" content="notranslate">
<style>
@Leedehai
Leedehai / why-gn-ninja.md
Last active April 27, 2020 03:26
Build system: Ninja and GN
View why-gn-ninja.md

Build system: Ninja and GN

Switching from Make to Ninja and GN across the board.

A build system is what coordinates the build process of various source files and libraries.

Make and CMake

Make is a tried and tested tool, but it does not scale well with large, collaborative projects that often require

@Leedehai
Leedehai / ncore.sh
Created December 20, 2019 02:15
Find number of CPU cores on Linux/macOS
View ncore.sh
#!/usr/bin/env sh
# Copyright: see README and LICENSE under the project root directory.
# Author: @Leedehai
#
# File: ncore.sh
# ---------------------------
# This is a handy script to get CPU core number on Linux and Darwin (macOS).
# Logical CPU cores