Skip to content

Instantly share code, notes, and snippets.

@bdss58
bdss58 / hashmap_h
Created April 14, 2015 15:12
hashmap header file
#ifndef HASHMAP_H
#define HASHMAP_H
/*
* Generic implementation of hash-based key-value mappings.
* See Documentation/technical/api-hashmap.txt.
*/
/* FNV-1 functions */
@bdss58
bdss58 / copy.js
Last active November 29, 2015 03:31
nodejs copy file
'use scrict';
var fs = require('fs');
var stat = fs.stat;
function copy(src, dest){
fs.readdir(src, function(err, paths) {
if (err) {
console.log(err);
throw err;
@bdss58
bdss58 / load_json_config.go
Created July 4, 2018 13:58
load json config file and read keys
var config = make(map[string]interface{})
func loadConfig(path string) (err error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
log.Fatal("config file path is not exist")
}
file, err := os.Open(path)
if err != nil {
log.Fatal("can not open: ", path)
@bdss58
bdss58 / LRUCache.go
Created July 4, 2018 14:00
LRUCache
package main
import (
"container/list"
"fmt"
"time"
"math/rand"
)
func init() {
rand.Seed(time.Now().UnixNano())
@bdss58
bdss58 / rsa_demo.sh
Created July 5, 2018 08:20
use rsa private key and public key to encrypt or decrypt
#!/bin/sh
# Create message to be encrypted
echo "Creating message file"
echo "---------------------"
echo "My secret message" > message.txt
echo "done\n"
# Create asymmetric keypair
echo "Creating asymmetric key pair"
echo "----------------------------"
@bdss58
bdss58 / tcpdump.sh
Last active September 19, 2018 10:18
tcpdump output to a file and view the out file
# tcpdump the localhost port to a pcap file
tcpdump -i lo 'port 3000' -w result.pcap
# view the pcap file using tcpdump
tcpdump -qns 0 -A -r result.pcap
# tcpdump the to dest host package to a pcap file
tcpdump -i eth1 -vv -n dst host 9.78.206.6 -w result.pcap
@bdss58
bdss58 / printbits.c
Created August 25, 2018 04:18
print each byte of integer in binary format
#include <stdio.h>
void pbits(char);
int main() {
int n = 1025;
char* p = (char*)&n;
for (int i = 0; i < sizeof(n); i++) {
printf("%d byte: ", i);
@bdss58
bdss58 / memory_layout.md
Created September 2, 2018 08:56 — forked from CMCDragonkai/memory_layout.md
Linux: Understanding the Memory Layout of Linux Executables

Understanding the Memory Layout of Linux Executables

Required tools for playing around with memory:

  • hexdump
  • objdump
  • readelf
  • xxd
  • gcore
@bdss58
bdss58 / ip2int.go
Created January 15, 2019 07:50
ip 字符串转整型 (golang)
func ip2int(ip string) uint32 {
IP := net.ParseIP(ip)
if len(IP) >= 16 {
return binary.BigEndian.Uint32(IP[12:16])
} else {
return 0
}
}
@bdss58
bdss58 / gbk2utf8.go
Created January 15, 2019 08:47
UTF82GBK
func GBKToUTF8(data []byte) []byte {
UTF8Reader := transform.NewReader(bytes.NewReader(data), simplifiedchinese.GBK.NewDecoder())
b, e := ioutil.ReadAll(UTF8Reader)
if e != nil {
log.Error("read GBKReader failed, error: %s, GBKReader: %v", e.Error(), UTF8Reader)
return nil
}
return b
}