Skip to content

Instantly share code, notes, and snippets.

@liuwenzhuang
liuwenzhuang / binary-search-tree.ts
Created July 31, 2020 09:04
binary search tree in typescript
// tslint:disable: max-classes-per-file
class TreeNode {
public left: TreeNode = null;
public right: TreeNode = null;
constructor(public data) {
this.data = data;
this.left = null;
this.right = null;
}
}
@liuwenzhuang
liuwenzhuang / launch.json
Created June 5, 2020 07:11
launch and debug configuration for node, .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"protocol": "inspector",
"name": "Attach",
"port": 9229
}
@liuwenzhuang
liuwenzhuang / profiles.json
Created January 19, 2020 02:15
Add Git Bash to windows terminal. Windows Terminal添加Git Bash
{
"profiles": [
{
"guid": "{61c54bbd-c2c6-5271-96e7-109a87ff44be}",
"name": "Git Bash",
"commandline": "%ProgramFiles%\\Git\\bin\\bash.exe --login -i",
"icon": "%ProgramFiles%\\Git\\mingw64\\share\\git\\git-for-windows.ico",
"startingDirectory": "%USERPROFILE%",
"hidden": false
},
@liuwenzhuang
liuwenzhuang / .vimrc
Last active January 19, 2020 01:52
vim config file, place it to user directory
syntax on
set autoindent
set expandtab
set tabstop=2
set sw=2
set showcmd
set shortmess=at
set nowritebackup
@liuwenzhuang
liuwenzhuang / add_schemes_windows_terminal.ps1
Last active January 11, 2020 12:19
为wsl添加主题.(add schemes from iTerm2-Color-Schemes to wsl profiles). Code from https://andrewpla.dev/Adding-New-Color-Schemes-To-Windows-Terminal/
# Path to the profile when installed from the Windows Store.
$profilePath = "C:\Users\$Env:Username\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\profiles.json"
# remove comments
$profile = (Get-Content $ProfilePath) -replace '(?m)(?<=^([^"]|"[^"]*")*)//.*' -replace '(?ms)/\*.*?\*/' | Out-String | ConvertFrom-Json
$backupProfilePath = "$home\Documents\WindowsTerminalprofiles.json"
Write-Verbose "Backing up profile to $backupProfilePath"
$profile | ConvertTo-Json | Set-Content $backupProfilePath
@liuwenzhuang
liuwenzhuang / addSetGet2localStorage.js
Created March 6, 2019 09:08
Add set/get object capacity to localStorage 为localStorage增加读、写Object的能力
if (typeof Storage === 'undefined') {
window.localStorage = {};
localStorage.setItem = function (key, val) {
this[key] = val;
};
localStorage.getItem = function (key) {
return this[key];
};
window.localStorage.setObject = function (key, value) {
this[key] = value;
@liuwenzhuang
liuwenzhuang / beforeunload.js
Created October 19, 2018 06:08
离开页面前的监听事件
window.addEventListener("beforeunload", function (event) {
if (!checkSomething()) { // 假设已存在此方法
// 标准
event.preventDefault();
// Chrome需要
event.returnValue = '';
}
});
@liuwenzhuang
liuwenzhuang / objectEntries.js
Created July 19, 2018 05:54
使原生Object能够被遍历
/**
* 使object可遍历
* @param {Object} obj 需要处理的object
*/
function* objectEntries(obj) {
const propKeys = Reflect.ownKeys(obj);
for(const propKey of propKeys) {
yield [propKey, obj[propKey]];
}
}
@liuwenzhuang
liuwenzhuang / clock.svg
Created July 6, 2018 08:25
javascript控制SVG实现时钟效果
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@liuwenzhuang
liuwenzhuang / fetch_timeout.js
Last active June 14, 2018 06:20
利用Promise.race为fetch提供缺失的timeout的功能,Promise.race的作用是挑选出进行后续then操作的promise,其实每个promise都会被执行,不要在其中做具有side effects的操作
function timeoutPromise(timeout) {
return new Promise((resolve, reject) => {
setTimeout(resolve, timeout);
});
}
request(url, options, timeout) {
const defaultOptions = {
credentials: 'include',
};