Skip to content

Instantly share code, notes, and snippets.

View Leedehai's full-sized avatar
:octocat:
Undefined behavior

Leedehai

:octocat:
Undefined behavior
View GitHub Profile
@Leedehai
Leedehai / ncore.sh
Created December 20, 2019 02:15
Find number of CPU cores on Linux/macOS
#!/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
@Leedehai
Leedehai / cross-repo-check.py
Last active July 11, 2020 17:02
Cross repository check.
#!/usr/bin/env python3
# https://gist.github.com/Leedehai/96ae9d03d3d34ec74d59f33087ba5e9f
import os, sys
import asyncio
import hashlib
import subprocess
from collections import OrderedDict
from pathlib import Path
from typing import List, Tuple, Union
@Leedehai
Leedehai / events.js
Last active November 23, 2019 07:16
Play: a custom event system like Chrome DevTools
/**
* Copyright (c) 2019 Leedehai. All rights reserved.
* Licensed under the MIT License. For details, refer to LICENSE.txt
* under the project root.
*
* File: events.js
* -----------------------------------------
* A custom event system so that event dispatching and listening is
* available to ordinary objects that are not instances of EventTarget's
* child classes.
@Leedehai
Leedehai / sans-comment-to-string-loader.js
Last active November 21, 2019 20:47
to-string-loader for Webpack, with comments removed.
/**
* Copyright (c) 2019 The contributors of https://github.com/gajus/to-string-loader
* License under the BSD-3-Clause License.
* Copyright (c) 2019 Leedehai. All rights reserved.
* Licensed under the MIT License. For details, refer to LICENSE.txt
* under the project root.
*
* File: code-to-string-loader.js
* -----------------------------------------
* A fork of to-string-loader (version 1.1.6) for Webpack:
@Leedehai
Leedehai / http-server.py
Last active November 21, 2019 16:46
Simple HTTP server, enhanced
#!/usr/bin/python
# Copyright holder unknown, from https://www.acmesystems.it/python_http
# Licensed under the CC-BY-SA 4.0 License.
# Copyright holder velis, from https://stackoverflow.com/a/17064025/8385554
# Licensed under the CC-BY-SA 4.0 License.
# Copyright (c) 2019 Leedehai. All rights reserved.
# Licensed under the MIT License. For details, refer to LICENSE.txt
# under the project root.
#
# File: http-server.py
@Leedehai
Leedehai / retry_exec.py
Last active November 10, 2019 05:06
Workaround if a command doesn't support concurrency well...
# Run function with delayed retry
#
# Motivation: BUG_WORKAROUND(ninja):
# It seems ninja has some issues with concurrency
# because it always tries to open deps log for write even for
# read-only operations like "ninja -t query"
#
# It's like how Pure ALOHA network deals with collision
### VERSION 1: using a wrapper function
@Leedehai
Leedehai / settings.json
Created November 8, 2019 05:21
GitLens settings in VS Code settings.json
{
"gitlens.advanced.abbreviatedShaLength": 5,
"gitlens.defaultDateStyle": "absolute",
"gitlens.defaultDateFormat": "YYYY-MM-D HH:mm:ss Z",
"gitlens.blame.highlight.locations": [
"gutter",
"overview",
"line"
],
"gitlens.codeLens.enabled": false,
@Leedehai
Leedehai / auto.py
Last active December 5, 2019 01:45
Project management
#!/usr/bin/env python
# Copyright: see README and LICENSE under the project root directory.
# Author: @Leedehai
#
# File: auto.py
# ---------------------------
# A master management script, like 'fx' of Google's Fuchsia.
# Feeling overwhelmed? Follow README.md's instructions on how
# to build and test the project. Make use of option '--help'.
#
@Leedehai
Leedehai / vim-ls.sh
Created June 1, 2019 08:04
vim <=> ls: to relieve a common command typo headache when working in terminal
# This contains two files.. the ls proxy and the vim proxy
# Problem I wanted to solve:
# when working in terminal, sometimes I mistake ls with vim, or vice versa, when I
# am inspecting a directory recursively. When this happens, I have to retype the
# command. Yes, '!$' helps me to re-use the previous argument, but I still wish the
# experience could be smoother.
# Solution:
# make ls and vim interchangeable by delegating ls and vim to proxy scripts, and set
# alias 'ls' and 'vim' to these scripts.
@Leedehai
Leedehai / print-line-elide.py
Created January 10, 2019 04:55
Python: print strings in the same line, overwriting the previous content
#!/usr/bin/env python
# Tested on Python2.7 and Python3.5
import os, sys
import time
lines = [
"abc",
"abcdefghi",
"a",