Skip to content

Instantly share code, notes, and snippets.

View vimiix's full-sized avatar
🧱
Coding

Vimiix Yao vimiix

🧱
Coding
View GitHub Profile
@vimiix
vimiix / libpq-demo.cc
Created August 4, 2023 10:34 — forked from ictlyh/libpq-demo.cc
libpq examples.
/*
* Demo of libpq.
* Build: g++ libpq-demo.cc -o libpq-demo -lpq
* Run: ./libpq-demo
*/
#include <arpa/inet.h>
#include <iostream>
#include <libpq-fe.h>
#include <sstream>
@vimiix
vimiix / deploy_mogdb.sh
Last active August 7, 2023 09:57
Auto deploy a MogDB instance by PTK
#!/bin/bash
# Author: vimiix
# Email : i@vimiix.com
set -euo pipefail
# Parameters
CLUSTER_NAME="mogdb"
HOST_NAME="127.0.0.1" # ip of target host
@vimiix
vimiix / go_version_manage_function.sh
Last active June 28, 2023 15:06
Shell functions for managing golang multiple versions
####### GOLANG VERSION MANAGE FUNCTIONS ######
# ref: https://go.dev/doc/manage-install
function goinstall() {
echo "Downloading go$1 ..."
go install golang.org/dl/go$1@latest && go$1 download
}
function gouse() {
gopath=$(go env GOPATH)
if test -x ${gopath}/bin/go$1; then
@vimiix
vimiix / how-to-install-python3.7-on-centos.md
Created August 31, 2022 01:26
How to install python3.7 on CentOS

Step 1 – Requirements

安装编译解释器所需的依赖

yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel xz-devel 

Step 2 – Download Python 3.7

@vimiix
vimiix / parallel_ping.py
Last active October 19, 2021 03:35
批量发送ping包测试网络连通性
import asyncio
async def _async_ping(ip):
"""发送ping包
探测策略:发送3次包,每次间隔0.5s, 超时时间为2s
判断依据:指令执行的退出状态码是否正常为0
Args:
ip (string): IP
@vimiix
vimiix / Makefile
Created November 30, 2020 08:26 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@vimiix
vimiix / magic_decorator.py
Created December 18, 2019 10:42
使装饰器同时支持带参数和不带参数
def ban_attr(ban):
if callable(ban):
def _wrapper():
raise AttributeError("Cannot write from Greywood to Dale")
return _wrapper
else:
assert isinstance(ban, bool), TypeError("ban_attr: want bool, got %s" % type(ban))
def _wrapper(f):
@wraps(f)
def __wrapper(*args, **kwargs):
@vimiix
vimiix / LRUCache.py
Created December 10, 2019 08:43
LRU算法实现
class LRUCache(object):
def __init__(self, capacity):
self.capacity = capacity
self.queue = []
self.cache = {}
def to_dict(self):
return {"capacity": self.capacity, "queue": self.queue, "cache": self.cache}
@classmethod
package main
/*
golang 实现 google 的rtb 价格加密方案
https://developers.google.com/authorized-buyers/rtb/response-guide/decrypt-price#encryption-scheme
*/
import (
"crypto/hmac"
"crypto/md5"
@vimiix
vimiix / simple_python_datasource.py
Created July 10, 2019 08:54 — forked from linar-jether/simple_python_datasource.py
Grafana python datasource - using pandas for timeseries and table data. inspired by and compatible with the simple json datasource
from flask import Flask, request, jsonify, json, abort
from flask_cors import CORS, cross_origin
import pandas as pd
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'