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
Base64 = Base64 || {
// @param n Number, 6 bits, e.g. 0b111111
// @return String, a char, e.g. "/"
encode6Bits: function(n) {
n = Math.min(Math.max(0, n), 63);
if (n >= 0 && n <= 25) return String.fromCharCode("A".charCodeAt(0) + n); // ["A", "Z"]
else if (n >= 26 && n <= 51) return String.fromCharCode("a".charCodeAt(0) + n - 26); // ["a", "z"]
else if (n >= 52 && n <= 61) return String.fromCharCode("0".charCodeAt(0) + n - 52); // ["0", "9"]
else if (n == 62) return "+";
else /* if (n == 63) */ return "/";
Base64 = {
// @param n Number, 6 bits, e.g. 0b111111
// @return String, a char, e.g. "/"
encode6Bits: function(n) {
n = Math.min(Math.max(0, n), 63);
if (n >= 0 && n <= 25) return String.fromCharCode("A".charCodeAt(0) + n); // ["A", "Z"]
else if (n >= 26 && n <= 51) return String.fromCharCode("a".charCodeAt(0) + n - 26); // ["a", "z"]
else if (n >= 52 && n <= 61) return String.fromCharCode("0".charCodeAt(0) + n - 52); // ["0", "9"]
else if (n == 62) return "+";
else /* if (n == 63) */ return "/";
@iwill
iwill / script-template.sh
Created December 26, 2020 07:56 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@iwill
iwill / ExCodable.swift
Last active August 17, 2021 01:27
Code Snippet: Adopte to ExCodable protocol
<#extension/struct/class#> <#Type#>: ExCodable {
static let <#keyMapping#>: [KeyMap<<#SelfType#>>] = [
KeyMap(\.<#property#>, to: <#"key"#>),
<#...#>
]
init(from decoder: Decoder) throws {
try decode<#Reference#>(from: decoder, with: Self.<#keyMapping#>)
}
func encode(to encoder: Encoder) throws {
try encode(to: encoder, with: Self.<#keyMapping#>)
@iwill
iwill / TypeErasure.swift
Last active November 17, 2021 08:33
Code Snippet: Type Erasure for Protocol with AssociatedType, Self and static methods
// Type-Erasure
// - seealso: [AnyIterator](https://github.com/apple/swift/blob/2fe4254cb712fa101a220f95b6ade8f99f43dc74/stdlib/public/core/ExistentialCollection.swift.gyb#L45)
// MARK: remove `Equatable` if not needed
public protocol Protocol: Equatable {
// MARK: `Protocol` requirements
associatedtype AssociatedType
func methodOfProtocol() -> Self.AssociatedType
}
@iwill
iwill / gdiff
Created March 16, 2021 04:43 — forked from gwarnes-mdsol/gdiff
Use FileMerge as git difftool on Mac OS X
#!/bin/bash
#
# A git difftool for Mac OS X that uses FileMerge from XCode
#
# source: https://gist.github.com/gwarnes-mdsol/b0aff96fbb7a4c92e570e7b03daa7e1b
#
# Setup:
#
# 1. Copy this file to a known path, e.g. $HOME/bin/gdiff
# 2. Make the file executable:
@iwill
iwill / remove-bottom-line-navbar.md
Created May 12, 2021 02:33 — forked from vinhnx/remove-bottom-line-navbar.md
remove 1px bottom line of the navigation bar

If you just want to use a solid navigation bar color and have set this up in your storyboard, use this code in your AppDelegate class to remove the 1 pixel border via the appearance proxy:

Objective-C

[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init]
                                  forBarPosition:UIBarPositionAny
                                      barMetrics:UIBarMetricsDefault];

[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
@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 / 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 / gist:1578b4bc2f0026cb6fc5b54b5f086f86
Created May 20, 2022 15:18 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue: