Skip to content

Instantly share code, notes, and snippets.

@SolemnJoker
SolemnJoker / cpp.json
Last active May 22, 2021 16:45
[.vimspector.json] #vim #vimspector
{
"configurations": {
"Launch": {
"adapter": "vscode-cpptools",
"configuration": {
"request": "launch",
"program": "<path to binary>",
"args": [ ... ],
"cwd": "<working directory>",
"environment": [ ... ],
@SolemnJoker
SolemnJoker / go_ini_read.go
Created May 21, 2021 15:12
go read ini file
// Package config_reader provides ...
package config_reader
import (
"gopkg.in/ini.v1"
)
type AppConfig struct {
DbUser string
DbPasswd string
@SolemnJoker
SolemnJoker / go_aes_加密解密.go
Created May 12, 2021 03:59
[go aes加密解密] #go #aes
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
@SolemnJoker
SolemnJoker / initLog.md
Last active December 7, 2020 03:32
[go logrus] #go #log #logrus

创建log,启用hook,增加log按日期文件切分,自动删除旧日志,记录行号等功能

import(
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
log "github.com/sirupsen/logrus"
)
func initLog() {
	path := "./log/screen-monitor.log"
	vars.Logger = log.New()
	vars.Logger.Hooks.Add(log_hooks.NewContextHook())
@SolemnJoker
SolemnJoker / Map参数(字典参数).md
Last active December 7, 2020 04:59
[go gin] #go #gin
r.POST("/post", func(c *gin.Context) {
	ids := c.QueryMap("ids")
	names := c.PostFormMap("names")

	c.JSON(http.StatusOK, gin.H{
		"ids":   ids,
		"names": names,
	})
})
@SolemnJoker
SolemnJoker / FirstOrCreate
Last active May 7, 2021 06:29
[gorm库] go操作数据库 gorm框架代码片段#go #gorm
获取匹配的第一条记录, 否则根据给定的条件创建一个新的记录 (仅支持 struct 和 map 条件)
```
// 未找到
db.FirstOrCreate(&user, User{Name: "non_existing"})
//// INSERT INTO "users" (name) VALUES ("non_existing");
//// user -> User{Id: 112, Name: "non_existing"}
// 找到
db.Where(User{Name: "Jinzhu"}).FirstOrCreate(&user)
//// user -> User{Id: 111, Name: "Jinzhu"}
@SolemnJoker
SolemnJoker / utils.h
Created November 7, 2020 06:22
split a string
inline
std::vector<std::string> split(const std::string& str, char seperator) {
std::vector<std::string> results;
std::string::size_type start = 0;
std::string::size_type sep = str.find(seperator);
while (sep != std::string::npos) {
if (start < sep)
results.emplace_back(str.substr(start, sep - start));
@SolemnJoker
SolemnJoker / eigen_base.md
Last active November 7, 2020 13:51
[eigen库] #c++

一.变量操作

1.定义变量

Eigen::MatrixXd m1(row,col); /row*col double
Eigen::Matrix3d m2;//3*3 double
Eigen::Matrix3Xd m3(row);//row*3 double
Eigen::Matrix<double,row,col,Eigen::RowMajor> m4; //
Eigen::Matrix<double,row,Eigen::Dynamic,Eigen::RowMajor> m5(col); // row*col 
@SolemnJoker
SolemnJoker / read.cpp
Last active November 7, 2020 06:27
[rapidjson] #c++ #json
//#include "rapidjson/document.h"
rapidjson::Document doc;
doc.Parse(json_str.c_str());
rapidjson::Value array_val = doc["arr_val_name"].GetArray();
int int_val = doc["int_val_name"].GetInt();
string str_val = doc["str_val_name"].GetString();
@SolemnJoker
SolemnJoker / navi.md
Last active November 18, 2020 06:51
[个人配置文件] #config
plugins_dir="$ZSH_CUSTOM/plugins"
mkdir -p "$plugins_dir"
cd "$plugins_dir"
git clone https://github.com/denisidoro/navi

添加到oh-my-zsh plugin

plugins=(docker tmux fzf navi)
source "$(navi widget zsh )"