Skip to content

Instantly share code, notes, and snippets.

View shangzongyu's full-sized avatar
💭
I may be slow to respond.

TomShine shangzongyu

💭
I may be slow to respond.
View GitHub Profile
@shangzongyu
shangzongyu / JNI-Example-Mac.md
Last active November 7, 2018 05:31 — forked from DmitrySoshnikov/JNI-Example-Mac.md
JNI Example For Mac

JNI (Java Native Interface) allows implementing methods in C/C++, and use them in Java.

0. Prepare

I use hombrew install java, java version is java 10.

$ java --version
java 10.0.2 2018-07-17
@shangzongyu
shangzongyu / aes_encryption.py
Created September 18, 2018 02:58 — forked from stupidbodo/aes_encryption.py
AES Encryption Example in Python
from base64 import urlsafe_b64encode, urlsafe_b64decode
from Crypto.Cipher import AES
from Crypto import Random
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s: s[:-ord(s[len(s) - 1:])]
base64pad = lambda s: s + '=' * (4 - len(s) % 4)
@shangzongyu
shangzongyu / main.go
Created September 10, 2018 02:13 — forked from mickelsonm/main.go
Golang AES Encryption/Decryption example. See running example: http://play.golang.org/p/5G-IUlYqQV
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"errors"
"io"
"log"
@shangzongyu
shangzongyu / signal.go
Created August 28, 2018 10:40 — forked from reiki4040/signal.go
signal handling example for golang
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
@shangzongyu
shangzongyu / macaddr.go
Created August 6, 2018 11:08
a simple example of how to grab a mac address in Golang.
// getMacAddr gets the MAC hardware
// address of the host machine
func getMacAddr() (addr string) {
interfaces, err := net.Interfaces()
if err == nil {
for _, i := range interfaces {
if i.Flags&net.FlagUp != 0 && bytes.Compare(i.HardwareAddr, nil) != 0 {
// Don't use random as we have a real address
addr = i.HardwareAddr.String()
break
@shangzongyu
shangzongyu / ovs-cheat.md
Last active May 28, 2024 06:03 — forked from djoreilly/ovs-cheat.md
OVS Cheatsheet

DB

ovs-vsctl list interface
ovs-vsctl --columns=ofport,name list Interface
ovs-vsctl --columns=ofport,name --format=table list Interface
ovs-vsctl --format=table --columns=name,mac_in_use find Interface name=br-dpdk1
ovs-vsctl get interface vhub656c3cb-23 name

ovs-vsctl set port vlan1729 tag=1729
ovs-vsctl get port vlan1729 tag
@shangzongyu
shangzongyu / spacemacs-cheatsheet.md
Created December 18, 2017 10:44 — forked from davoclavo/spacemacs-cheatsheet.md
Spacemacs cheatsheet

emacs --daemon to run in the background. emacsclient.emacs24 <filename/dirname> to open in terminal

NOTE: "M-m and SPC can be used interchangeably".

  • Undo - C-/
  • Redo - C-?
  • Change case: 1. Camel Case : M-c 2. Upper Case : M-u
  1. Lower Case : M-l
@shangzongyu
shangzongyu / oauth.go
Created January 17, 2017 12:45 — forked from guotie/oauth.go
package main
import (
"dxmall/models/user"
"dxmall/utils"
"fmt"
"net/http"
"strings"
@shangzongyu
shangzongyu / user.go
Created January 17, 2017 12:45 — forked from guotie/user.go
package user
import (
"fmt"
"regexp"
"strconv"
"time"
"dxmall/utils"
@shangzongyu
shangzongyu / time.py
Created November 2, 2015 03:39 — forked from DeronW/time.py
python 拿当前的时间戳 秒数和毫秒数,time的经度跟系统相关,windows小数点后3位,linux后面6位
import time
from datetime import datetime, date
# 今天
datetime.datetime.today().date().isoformat()
# 通过日期对象生成时间戳
int(time.mktime(datetime.now().timetuple()))
# 通过时间戳生成日期对象,timestamp 的时间戳以秒为单位