Skip to content

Instantly share code, notes, and snippets.

迷渡 justjavac

Block or report user

Report or block justjavac

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View unicode.js
// JavaScript 字符串编码使用 UTF-16
"💩".length === 2;
"💩" === "\u{1F4A9}"; // es6
"💩" === "\uD83D\uDCA9"; // es5
// 同一个编码可能使用不同的码位
"ò" === "ò"; // ❎
"ò" === "\xF2"; // ✅
"ò" === "o\u0300"; // ✅
"o\u0300".normalize("NFC") === "\xF2"; // ✅ es6 提供了 normalize 函数
@justjavac
justjavac / GetOptimizationStatus.md
Last active Aug 9, 2019
V8 %GetOptimizationStatus
View GetOptimizationStatus.md

%GetOptimizationStatus return a set of bitwise flags instead of a single value, to access the value, you need to take the binary representation of the returned value. Now, for example, if 65 is returned, the binary representation is the following:

(65).toString(2).padStart(12, '0');
// 000001000001

Each binary digit acts as a boolean with the following meaning:

@justjavac
justjavac / instructions.md
Last active Aug 23, 2019 — forked from Timer/instructions.md
使用 npm <= 5.2 创建新项目
View instructions.md

在 npm 5.1 或者更低版本中,不存在 npx 命令。因此,你必须全局安装 create-next-app

npm install -g create-next-app

然后再运行:

create-next-app
View gc-track.js
// 需要通过 node --allow-natives-syntax 参数运行
const { GCSignal, consumeSignals, trackGarbageCollection } = require("gc-signals");
function fn() {
// 创建两个局部变量
const a1 = new GCSignal(1);
const a2 = new GCSignal(2);
global.tmp = a2; // 将 a2 变量赋值给全局变量
const o = {};
trackGarbageCollection(o, 3); // 跟踪局部变量 o 的 GC 状态,标识为 3
@justjavac
justjavac / img2txt.js
Last active Feb 27, 2020
img2txt:基于canvas的图片转字符画工具
View img2txt.js
var cv = document.getElementById('cv');
var c = cv.getContext('2d');
var txtDiv = document.getElementById('txt');
var fileBtn = document.getElementById("up-button");
var img = new Image();
img.src = 'a.jpg';
img.onload = init; // 图片加载完开始转换
fileBtn.onchange = getImg;
// 根据灰度生成相应字符
You can’t perform that action at this time.