Skip to content

Instantly share code, notes, and snippets.

View pwxcoo's full-sized avatar
🐟

Xiance Wu pwxcoo

🐟
View GitHub Profile
@pwxcoo
pwxcoo / huffman.cpp
Created July 14, 2019 13:56
huffman encoding implemented by c++
#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
using namespace std;
// A Tree node
struct Node
{
char ch;
@pwxcoo
pwxcoo / fraction.cpp
Last active February 14, 2023 00:02
Fraction implement by C++
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stdexcept>
using namespace std;
class Fraction {
int numerator;
int denominator;
@pwxcoo
pwxcoo / NewPasswordUtil.java
Last active July 14, 2022 13:10
Generate a SALT in Java for Salted-Hash.
package com.pwxcoo.github.utils;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import java.util.Arrays;
import java.util.Base64;
import java.util.Random;
@pwxcoo
pwxcoo / javap.java
Last active June 14, 2021 03:36
javap 指令集
栈和局部变量操作
将常量压入栈的指令
aconst_nullnull对象引用压入栈
iconst_m1int类型常量-1压入栈
iconst_0int类型常量0压入栈
iconst_1int类型常量1压入栈
iconst_2int类型常量2压入栈
iconst_3int类型常量3压入栈
iconst_4int类型常量4压入栈
iconst_5int类型常量5压入栈
@pwxcoo
pwxcoo / crc.py
Last active January 29, 2020 09:46
CRC (Cyclic Redundancy Check) implemented with python
def check(frame, p):
n = len(p) - 1
fcs = frame[0: n]
for i in range(n, len(frame)):
fcs += frame[i]
fcs = bin(int(fcs, 2))[2:]
if (len(fcs) < len(p)):
continue
fcs = bin(int(fcs, 2) ^ int(p, 2))[2:]
while len(fcs) < n:
@pwxcoo
pwxcoo / profile.ps1
Last active August 26, 2019 14:11
my customized powershell profile
# http://joonro.github.io/blog/posts/powershell-customizations.html
Import-Module PSReadLine
# Oh-My-Posh https://github.com/pecigonzalo/Oh-My-Posh
Import-Module "Oh-My-Posh" -DisableNameChecking -NoClobber
Set-PSReadLineOption -HistoryNoDuplicates
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Set-PSReadLineOption -MaximumHistoryCount 4000
# history substring search
@pwxcoo
pwxcoo / fix-touchpad.sh
Created June 18, 2019 01:49
fix touchpad in ubuntu
# https://askubuntu.com/questions/970988/two-finger-scrolling-not-working-for-ubuntu-17-10
sudo modprobe -r psmouse
sudo modprobe psmouse
@pwxcoo
pwxcoo / cycle.cpp
Last active June 18, 2019 01:31
Find Cycle List Beginning Node
/**
* Time: O(n)
* Space: O(1)
* 1. find list if exists cycle.
* 2. 0 -> a(cycle s) -> b(cycle met) -> c(cycle s(e))
* slow = a + b + (b + c)n1, fast = a + b + (b + c)n2.
* slow * 2 = fast
* 2a + 2b + 2*n1*(b + c) = a + b + n2*(b + c) => a = (n2 - 2*n1) * (b + c) - b
* After meeting, so one start going from head and meanwhile slow start going, they will meet at cycle begin.
**/
@pwxcoo
pwxcoo / AtomicIntegerExample.java
Last active June 18, 2019 01:23
Five approaches to print "ABC" 10 times in sequence using 3 threads in Java
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class AtomicIntegerExample {
private AtomicInteger sycValue = new AtomicInteger(0);
private static final int MAX_SYC_VALUE = 3 * 10;
@pwxcoo
pwxcoo / repair.sh
Last active June 18, 2019 01:21
ubuntu 的 ibus 输入法不能按数字键取词
rm -rf ~/.cache/ibus/libpinyin
ibus restart