Skip to content

Instantly share code, notes, and snippets.

View wyw's full-sized avatar

WU Yuanwei wyw

  • 17:52 (UTC +08:00)
View GitHub Profile
@wyw
wyw / pimpl.cpp
Created June 14, 2017 11:08 — forked from cloudwu/pimpl.cpp
My version of pimpl
// My version of pimpl ([email protected])
// See http://en.cppreference.com/w/cpp/language/pimpl
#include <iostream>
// interface (widget.h)
class widget {
struct impl;
public:
static widget* create(int); // replacement of new
@wyw
wyw / tmux-cheatsheet.markdown
Created September 21, 2017 06:46 — forked from ryerh/tmux-cheatsheet.markdown
Tmux 快捷键 & 速查表

Tmux 快捷键 & 速查表

启动新会话:

tmux [new -s 会话名 -n 窗口名]

恢复会话:

tmux at [-t 会话名]
@wyw
wyw / mysql-docker.sh
Created November 17, 2017 11:26 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@wyw
wyw / proxmox-get-vm-ip.sh
Created November 22, 2017 03:48 — forked from pschmitt/proxmox-get-vm-ip.sh
Get the IP address of a VM hosted on Proxmox
#!/usr/bin/env bash
usage() {
echo "$(basename $0) VM"
}
get_vm_id() {
qm list | awk '/'"${1}"'/ { print $1 }'
}
@wyw
wyw / gist:4512dc44a23a1c1bd2f555b78d96412e
Created January 12, 2018 08:53 — forked from dmitshur/gist:6927554
How to `go get` private repos using SSH key auth instead of password auth.
$ ssh -A vm
$ git config --global url."[email protected]:".insteadOf "https://github.com/"
$ cat ~/.gitconfig
[url "[email protected]:"]
	insteadOf = https://github.com/
$ go get github.com/private/repo && echo Success!
Success!
@wyw
wyw / util.php
Created January 15, 2018 10:55 — forked from aeurielesn/util.php
Decode Unicode strings in PHP
<?php
#source: http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-char
function replace_unicode_escape_sequence($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}
function unicode_decode($str) {
return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $str);
}
@wyw
wyw / hmac_sha256.py
Created March 13, 2018 03:41 — forked from theY4Kman/hmac_sha256.py
Python SHA-256 HMAC
from Crypto import HMAC, SHA256
def hmac_sha256(key, msg):
hash_obj = HMAC.new(key=key, msg=msg, digestmod=SHA256)
return hash_obj.hexdigest()
@wyw
wyw / monitor.php
Created May 26, 2018 15:14 — forked from jesobreira/monitor.php
Server Monitor
<?php
/*
The aim is to create a functional server monitor based on the one
showed on Mark Zuckerberg's monitor on The Social Network movie.
Run so:
php monitor.php
Notes:
- The server LogFormat must be "Common Log Format" (%h %^[%d:%^] "%r" %s %b)
@wyw
wyw / container.go
Created June 1, 2018 02:53 — forked from christophberger/container.go
A container in less than 60 lines of Go
package main
import (
"fmt"
"os"
"os/exec"
"syscall"
)
func main() {
@wyw
wyw / apfs_cli_tools.txt
Created September 13, 2018 06:54 — forked from timsutton/apfs_cli_tools.txt
apfs tools in Sierra
➜ ~ sw_vers
ProductName: Mac OS X
ProductVersion: 10.12.1
BuildVersion: 16B2333a
➜ ~ ls -l /System/Library/Filesystems/apfs.fs/Contents/Resources
total 2088
-rwxr-xr-x 1 root wheel 349760 22 Sep 03:48 apfs.util
-rwxr-xr-x 1 root wheel 352880 22 Sep 03:48 apfs_invert