Skip to content

Instantly share code, notes, and snippets.

View navono's full-sized avatar
:octocat:
I may be slow to respond.

Darkness navono

:octocat:
I may be slow to respond.
View GitHub Profile
@navono
navono / protoc.cmd
Last active June 20, 2019 07:27
使用 batch 编译 proto 文件
@ECHO OFF
REM 声明采用UTF-8编码
chcp 65001
echo "请先安装 Golang 和 protoc,然后安装 protoc 插件"
REM plugin binary path
set PROTOC_GEN_TS_PATH=%cd%\\bin\\node_modules\\.bin\\protoc-gen-ts.cmd
set PROTOC_GEN_GRPC_PATH=%cd%\\bin\\grpc_cpp_plugin.exe
set PROTOC_GEN_LINT_PATH=%cd%\\bin\\protoc-gen-lint.exe
@navono
navono / protobufjs
Created June 21, 2019 05:06
Load proto(with third party proto files) with protobufjs
const root = new protobuf.Root();
root.resolvePath = function(origin, target) {
if (origin.length === 0) {
return target;
}
if (target.startsWith('are')) {
const protoPath = path.resolve(__dirname, '../', target)
console.log('path: ', protoPath);
function Uint8ArrayToString(fileData){
var dataString = "";
for (var i = 0; i < fileData.length; i++) {
dataString += String.fromCharCode(fileData[i]);
}
return dataString
}
@navono
navono / main.go
Created May 18, 2020 11:08 — forked from Zenithar/main.go
More secure password storage using HMAC-SHA256 and scrypt
// Inspired by https://blog.filippo.io/salt-and-pepper/
package main
import (
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"crypto/subtle"
"encoding/base64"
"encoding/json"
@navono
navono / main.go
Created May 18, 2020 11:08 — forked from Zenithar/main.go
More secure password storage using HMAC-SHA256 and scrypt
// Inspired by https://blog.filippo.io/salt-and-pepper/
package main
import (
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"crypto/subtle"
"encoding/base64"
"encoding/json"
@navono
navono / git2go-merge-local-branch.go
Created June 1, 2020 01:49 — forked from danielfbm/git2go-merge-local-branch.go
how to merge two local branches using git2go
package main
import (
"errors"
"log"
"github.com/libgit2/git2go"
)
func mergeBranches(repo *git.Repository, sourceBranchName string, destinationBranchName string) error {
// Assuming that these two branches are local already
sourceBranch, err := repo.LookupBranch(sourceBranchName, git.BranchLocal)
@navono
navono / pull.go
Created June 1, 2020 08:47 — forked from sithembiso/pull.go
git pull using git2go
func (repo *Repo) Pull() error {
branch, err := repo.Branch()
if err != nil {
return err
}
// Get the name
name, err := branch.Name()
if err != nil {
return err
@navono
navono / zap_jq.md
Last active August 3, 2020 12:06
filter zap json logger with jq

suppose we have a log file named 'log.json' and record some error level info, we want to split the stack trace from the file with some filter(like time) to formatted json, so we can do this :

cat log.json | jq '. | select(.level=="error") | select(.time | contains("xxxxx"))' | jq '.stacktrace | fromjson'
@navono
navono / utf8-string
Created September 28, 2020 08:35
UTF8 - string in C++
std::string ofDewarServer::string_To_UTF8(const std::string & str)
{
int nwLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
wchar_t * pwBuf = new wchar_t[nwLen + 1];//一定要加1,不然会出现尾巴
ZeroMemory(pwBuf, nwLen * 2 + 2);
::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen);
int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL);
@navono
navono / env_bat
Created September 28, 2020 08:38
setup env with bat
@echo off
setlocal EnableDelayedExpansion
setlocal EnableExtensions
set dir=%~dp0
set ligGit2Path=%dir%third_party\libgit2
set pkgConfigPath=%dir%third_party\pkg-config
set zlibPath=%dir%third_party\zlib
set KEY_NAME="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"