Skip to content

Instantly share code, notes, and snippets.

@bobohb
bobohb / dx11-screen-capture.cpp
Created May 9, 2023 11:19 — forked from t-mat/dx11-screen-capture.cpp
[WIN32] DX11 DXGI Screen capture sample
// WIN32/C++17: DX11 DXGI Screen capture sample
//
// References:
// - https://github.com/microsoftarchive/msdn-code-gallery-microsoft/tree/master/Official%20Windows%20Platform%20Sample/DXGI%20desktop%20duplication%20sample
// - https://github.com/microsoft/DirectXTex/blob/master/ScreenGrab/ScreenGrab11.cpp
// - https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/desktop-dup-api
//
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <atlbase.h>
@bobohb
bobohb / cachedecorator.py
Created August 19, 2022 01:49 — forked from mminer/cachedecorator.py
An example of a Python decorator to simplify caching a function's result.
"""An example of a cache decorator."""
import json
from functools import wraps
from redis import StrictRedis
redis = StrictRedis()
def cached(func):
@bobohb
bobohb / Readme.md
Created May 19, 2022 01:52 — forked from paskal/Readme.md
How to set up the Percona Monitoring and Management (PMM) v2 with docker-compose

Set up PMM Server v2

Let's start by creating entry for server in docker-compose.yaml:

version: '2'
# version 2 of docker-compose is not "old" version, it's the actual version,
# see below for explanation:
# https://stackoverflow.com/a/53636006/961092
services:
- General
[ ] The code works
[ ] The code is easy to understand
[ ] Follows coding conventions
[ ] Names are simple and if possible short
[ ] Names are spelt correctly
[ ] Names contain units where applicable
[ ] Enums are used instead of int constants where applicable
[ ] There are no usages of 'magic numbers'
[ ] All variables are in the smallest scope possible
# 生成 socks5 协议的连接命令16进制数据,用于 haproxy的 tcp-check send-binary
# 参考:
# - <https://zh.wikipedia.org/wiki/SOCKS#SOCKS5>, "SOCKS5请求格式" 部分
# - <http://cbonte.github.io/haproxy-dconv/configuration-1.7.html#4.2-tcp-check%20send-binary>
socks5_connect_binary = lambda domain, port: "05010003"+"%02x" % len(domain)+"".join(["%02x" % ord(x) for x in domain])+"%04x" % int(port)
@bobohb
bobohb / gist:05a58a2faa36d4e86280cbcc107dea8f
Created June 20, 2018 06:03 — forked from mikhailov/gist:9639593
Nginx S3 Proxy with caching
events {
worker_connections 1024;
}
http {
default_type text/html;
access_log /dev/stdout;
sendfile on;
keepalive_timeout 65;
@bobohb
bobohb / ConvertNewSteamID.markdown
Created August 25, 2017 12:42 — forked from bcahue/ConvertNewSteamID.markdown
Converting New SteamID Formats in Python

Seeing how SteamIDs have changed recently, I thought I'd write a Gist to help others (including myself!) decypher how to convert these from one format to the other in Python. First, let's go over basics to convert a 64bit CommunityID into a SteamID:

steamid64ident = 76561197960265728

def commid_to_steamid(commid):
  steamid = []
  steamid.append('STEAM_0:')
  steamidacct = int(commid) - steamid64ident
  
@bobohb
bobohb / myapp.conf
Created July 4, 2017 08:30 — forked from prydie/myapp.conf
Supervisor and uWSGI
[program:myapp]
autostart = true
user = myapp
command = /srv/myapp/env/bin/uwsgi --ini /srv/myapp/run/uwsgi.ini
directory=/srv/myapp
priority = 1
redirect_stderr = true
stdout_logfile = /srv/myapp/log/wsgi.log
stopsignal = QUIT
@bobohb
bobohb / chk_haproxy.sh
Created September 23, 2015 10:06 — forked from kenshinx/chk_haproxy.sh
Keepalived + Haproxy VIP: 123.125.22.90 Master: 123.125.22.97 Backup: 123.125.22.98 Server1: 123.125.22.99 Server2: 123.125.22.100
# author: weizhifeng
status=$(ps aux|grep haproxy | grep -v grep | grep -v bash | wc -l)
if [ "${status}" = "0" ]; then
/etc/init.d/haproxy start
status2=$(ps aux|grep haproxy | grep -v grep | grep -v bash |wc -l)
if [ "${status2}" = "0" ]; then
/etc/init.d/keepalived stop