Skip to content

Instantly share code, notes, and snippets.

View iwill's full-sized avatar
Growing Well 🌱🌱

Míng iwill

Growing Well 🌱🌱
View GitHub Profile
@iwill
iwill / semverCompare.js
Last active October 2, 2024 09:14
JavaScript - Comparison of Semantic Versioning
/**
* Semantic Versioning Comparing
* #see https://semver.org/
* #see https://stackoverflow.com/a/65687141/456536
* #see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
*/
function semverCompare(a, b) {
if (a.startsWith(b + "-")) return -1
if (b.startsWith(a + "-")) return 1
return a.localeCompare(b, undefined, { numeric: true, sensitivity: "case", caseFirst: "upper" })
@iwill
iwill / RegExp.make.js
Last active March 19, 2024 13:40
Make RegExp in multiple lines, and indent with white spaces
// #see https://stackoverflow.com/a/12317105/456536
RegExp.make = (regExp, opts) => new RegExp(regExp.raw[0].replace(/( #.*|\s)/gm, ""), opts || "")
@iwill
iwill / git-cb.sh
Last active October 30, 2023 09:19
git checkout with grep patterns
#!/bin/bash
# alias in gitconfig:
# cb = "!sh ~/.git-cb.sh"
# usage:
# git cb ev lo # *ev*lo* - `develop` will be matched
# cb = "!checkoutbranch() { local branches=`git branch | grep -i $1 | tr -d '* '`; if [[ `echo \"$branches\" | wc -l | tr -d ' '` != 1 ]]; then echo \"Matched multiple branches:\"; git branch | grep --color -i $1; exit 1; fi; git checkout $branches; }; checkoutbranch"
branches=`git branch`
@iwill
iwill / $class-2.0.0.js
Last active September 21, 2023 08:16
$class-2.0.0
/*!
* Javascript library - $class 2.0.0
* https://gist.github.com/iwill/2303057
*/
export default function $class(source, SuperClass) {
// default values
SuperClass = SuperClass || Object;
source = source || {};
// constructor & super constructor

Brew Bundle Brewfile Tips

Copyright & License

Unless otherwise noted (either in this file or in a file's copyright section) the contents of this gist are Copyright ©️2020 by Christopher Allen, and are shared under spdx:Creative Commons Attribution Share Alike 4.0 International (CC-BY-SA-4.) open-source license.

Sponsor

If you more tips and advice like these, you can become a monthly patron on my GitHub Sponsor Page for as little as $5 a month; and your contributions will be multipled, as GitHub is matching the first $5,000! This gist is all about Homebrew, so if you like it you can support it by donating to them or becoming one of their Github Sponsors.

@iwill
iwill / get-opts.sh
Last active December 28, 2022 10:57
A Bash Script - Get Options without `getopt`, `getopts` or `gnu-getopt`.
#!/bin/bash
## basic
set -e -o pipefail
cmd="get-opts.sh"
RED='01;38;5;196'
@iwill
iwill / colortest.py
Created October 12, 2022 14:28 — forked from justinabrahms/colortest.py
Small utility to test terminal support for 256-color output.
#!/usr/bin/env python
# Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349
print "Color indexes should be drawn in bold text of the same color."
print
colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
colored_palette = [
"%02x/%02x/%02x" % (r, g, b)
for r in colored
@iwill
iwill / print256colours.sh
Created October 12, 2022 14:28 — forked from HaleTom/print256colours.sh
Print a 256-colour test pattern in the terminal
#!/bin/bash
# Tom Hale, 2016. MIT Licence.
# Print out 256 colours, with each number printed in its corresponding colour
# See http://askubuntu.com/questions/821157/print-a-256-color-test-pattern-in-the-terminal/821163#821163
set -eu # Fail on errors or undeclared variables
printable_colours=256
@iwill
iwill / color-legend.sh
Last active September 29, 2022 02:14
color-legend.sh
#!/bin/bash
# http://ss64.com/bash/echo.html
echo -n -e " "
for j in {40..47}; do
echo -n -e " bj-$j "
# Reset text attributes to normal without clear
tput sgr0
done
@iwill
iwill / isNumber.js
Last active September 6, 2022 07:53
isNumber(aNorNaN) === !isNaN(aNorNaN)
function isNumber(x, object, bigint, string) {
let type = typeof x;
if (object && type == "object") {
x = x instanceof Number ? x.valueOf() : NaN;
type = typeof x;
}
else if (bigint && type == "bigint") {
x = x >= Number.MIN_SAFE_INTEGER && x <= Number.MAX_SAFE_INTEGER ? Number(x) : NaN;
type = typeof x;
}