Skip to content

Instantly share code, notes, and snippets.

View zhanglintc's full-sized avatar
🐦
Working from home

Lane zhanglintc

🐦
Working from home
View GitHub Profile
@echo off
SET var=C:\Folder1\Folder2\File.txt
echo before: %var%
call :getFolder "%var%" var
echo after: %var%
exit /b
:getFolder
set "%2=%~dp1"
function heavyTask() {
i=0
// do a heavy job
for (let j = 0; j < 1e8; j++) {
i++;
}
}
setTimeout(function(){console.log(1)}, 10)
heavyTask();
@zhanglintc
zhanglintc / suppress-warning.py
Created April 23, 2022 14:50
Suppress all warnings
import warnings
warnings.warn = lambda *a, **kw: (a, kw)
@zhanglintc
zhanglintc / pom.xml
Created April 30, 2021 04:32
echo in POM
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>ant-validate</id>
<phase>validate</phase>
@zhanglintc
zhanglintc / ssh-nc-proxy.sh
Last active January 19, 2021 14:17
ssh nc proxy
# bastion is the jump server
# target is the target server
# %h stands for host given to ssh, here is target
# %p stands for port given to ssh, here is 22(the default port)
ssh -go ProxyCommand='ssh user@bastion nc %h %p' user@target
@zhanglintc
zhanglintc / Traversal.java
Last active September 29, 2020 02:25
preorderTraversal, inorderTraversal, postorderTraversal
// 二叉树前中后序遍历统一写法:
// https://leetcode-cn.com/problems/binary-tree-postorder-traversal/solution/bang-ni-dui-er-cha-shu-bu-zai-mi-mang-che-di-chi-t/
class Solution {
// 前序遍历
public List<Integer> preorderTraversal(TreeNode root) {
if (root == null) return new LinkedList<>();
List<Integer> res = new LinkedList<>();
Stack<TreeNode> st = new Stack<>();
st.push(root);
while (!st.isEmpty()) {
@zhanglintc
zhanglintc / load_balance.py
Created September 5, 2020 13:13
load balance method
def make_balance_list(servers):
whole_weight = sum(srv[1] for srv in servers)
balance = []
weight_so_far = 0
for server in servers:
weight = server[1]
weight_so_far += weight
balance.append(weight_so_far / whole_weight)
return balance
@zhanglintc
zhanglintc / bubble_sort.py
Created August 26, 2020 12:35
bubble sort
def bubble(a):
for i in range(len(a)):
for j in range(len(a) - i - 1):
if a[j] > a[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]
class BigHeap {
// 大根堆, 大顶堆, 最大堆
int capacity = 0; // 容量
int size = 0; // 当前大小
int[] hp; // 数组模拟堆, 本实现使用数组下标 0 位置
public BigHeap(int k) {
capacity = k;
hp = new int[capacity];
}
private void qsort(int[] a, int bl, int br) {
if (bl >= br) return;
int m = a[bl], l = bl, r = br;
while (l < r) {
while (l < r && a[r] >= m) r--;
if (l < r) a[l++] = a[r];
while (l < r && a[l] <= m) l++;
if (l < r) a[r--] = a[l];
}
a[l] = m;