Skip to content

Instantly share code, notes, and snippets.

View nanmu42's full-sized avatar

Zhennan LI nanmu42

View GitHub Profile
@nanmu42
nanmu42 / pkcs7padding.go
Last active October 3, 2023 06:55
Golang PKCS7 Padding/Unpadding
// pkcs7strip remove pkcs7 padding
func pkcs7strip(data []byte, blockSize int) ([]byte, error) {
length := len(data)
if length == 0 {
return nil, errors.New("pkcs7: Data is empty")
}
if length%blockSize != 0 {
return nil, errors.New("pkcs7: Data is not block-aligned")
}
padLen := int(data[length-1])
@nanmu42
nanmu42 / randomstring.go
Created March 7, 2019 10:25
Superfast Golang Random String
// credits: https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
import (
"math/rand"
"time"
)
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const (
letterIdxBits = 6 // 6 bits to represent a letter index
@nanmu42
nanmu42 / random_string.js
Created March 7, 2019 07:52
Javascript Ramdom String With Specific Length
// change 10 to the length desired
[...Array(10)].map(i=>(~~(Math.random()*36)).toString(36)).join('')
@nanmu42
nanmu42 / update_tmux.sh
Last active May 7, 2024 09:24
Update tmux to latest version
#!/usr/bin/env bash
set -e
# dependecies
apt update
apt install -y git automake build-essential pkg-config libevent-dev libncurses5-dev byacc
# where our temp file locates
rm -rf /tmp/tmux
@nanmu42
nanmu42 / airdroper.sol
Created August 2, 2018 04:36
Airdropper for any ERC20 contract
pragma solidity ^0.4.24;
interface Token {
function transfer(address _to, uint256 _value) external returns (bool);
}
contract onlyOwner {
address public owner;
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
@nanmu42
nanmu42 / GetMyIP.go
Created June 6, 2018 10:22
Get My IP - Golang
package main
import (
"errors"
"fmt"
"net"
)
func main() {
{
"123":"application/vnd.lotus-1-2-3",
"ez":"application/andrew-inset",
"aw":"application/applixware",
"atom":"application/atom+xml",
"atomcat":"application/atomcat+xml",
"atomsvc":"application/atomsvc+xml",
"ccxml":"application/ccxml+xml",
"cdmia":"application/cdmi-capability",
"cdmic":"application/cdmi-container",