Skip to content

Instantly share code, notes, and snippets.

@hitzhangjie
hitzhangjie / disassembler.go
Created September 6, 2020 19:27 — forked from grantseltzer/disassembler.go
Full disassembler
package main
import (
"debug/elf"
"fmt"
"log"
"os"
"github.com/bnagy/gapstone"
)
@hitzhangjie
hitzhangjie / reverse2.go
Created August 23, 2020 02:11
reverse anything you could
func reverse(s interface{}) {
n := reflect.ValueOf(s).Len()
swap := reflect.Swapper(s)
for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
swap(i, j)
}
}
func reverse(slice interface{}) interface{} {
// Completely inefficient but syntactically "convenient"
s := reflect.ValueOf(slice)
switch s.Kind() {
case reflect.String:
// Support proper rune stuff, but terribly
ret := ""
for _, v := range slice.(string) {
ret = string(v) + ret
}
@hitzhangjie
hitzhangjie / database_connect.go
Last active April 9, 2020 13:19
database connect
//连接数据库示例(通过*sql.DB执行数据库操作,其内部维护了数据库连接池)
func OpenDatabase(ipport, database, user, pwd string) (*sql.DB, error) {
connStr := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4", user, pwd, ipport, database)
return sql.Open("mysql", connStr)
}
@hitzhangjie
hitzhangjie / create_calendar_event.applescript
Last active February 9, 2019 00:51
Create event in Calendar
set theQuery to "{query}"
-- 今天的开始、结束,用于筛选今天的事件列表
set todayStart to (current date)
set time of todayStart to 0
copy todayStart to todayEnd
set time of todayEnd to 86400
todayEnd
-- 待添加事件的开始、结束时间,我喜欢按照时间顺序追加的添加方式
copy todayStart to todoStart
set hours of todoStart to 8
@hitzhangjie
hitzhangjie / remap_win_desktop_switcher.ahk
Created June 27, 2017 01:21 — forked from yiboyang/remap_win_desktop_switcher.ahk
Remap Windows10's virtual desktop switcher key combo to Unity's "Ctrl + Alt + Left/Right"
;
; AutoHotkey Version: 1.1
; Language: English
; Platform: Win9x/NT
; Author: Yibo Yang
;
; Script Function:
; Remap Windows10's virtual desktop switcher keyboard shortcut from the default "Ctrl + Win + Left/Right" to Unity's "Ctrl + Alt + Left/Right"
; Put into the startup folder so that it will run every time your computer starts (http://superuser.com/questions/948616/windows-10-change-shortcut-keys-to-switch-between-desktops)
@hitzhangjie
hitzhangjie / osx-brew-gnu-coreutils-man.sh
Created August 23, 2016 11:03 — forked from quickshiftin/osx-brew-gnu-coreutils-man.sh
Running GNU coreutils via Homebrew on your Mac? Here's a one-liner to get the manpages working!
# Short of learning how to actually configure OSX, here's a hacky way to use
# GNU manpages for programs that are GNU ones, and fallback to OSX manpages otherwise
alias man='_() { echo $1; man -M $(brew --prefix)/opt/coreutils/libexec/gnuman $1 1>/dev/null 2>&1; if [ "$?" -eq 0 ]; then man -M $(brew --prefix)/opt/coreutils/libexec/gnuman $1; else man $1; fi }; _'