Skip to content

Instantly share code, notes, and snippets.

View tianchaijz's full-sized avatar
🏠
Working from home

tianchaijz tianchaijz

🏠
Working from home
View GitHub Profile
@tianchaijz
tianchaijz / HighTrafficServerSettings.md
Created April 6, 2022 05:05 — forked from fschiettecatte/HighTrafficServerSettings.md
High Traffic Server Settings on CentOS 8

High Traffic Server Settings on CentOS 8

I recently did some work to optimize the network configuration of a CentOS 8 based web server that receives a lot of traffic.

There is a lot of information on the web for this and it distills down to a minimum recommended configuration, and a recommended configuration.

The minimum recommended configuration should be sufficient for servers with less than 10Gb, and the recommended configuration should be sufficient for servers with 10Gb or more.

@tianchaijz
tianchaijz / CGO.md
Created February 16, 2022 03:21 — forked from dwbuiten/CGO.md

Problems & Solutions for Interaction Between C and Go

At Vimeo, on the transcoding team, we work a lot with Go, and a lot with C, for various tasks such as media ingest. This means we use CGO quite extensively, and consequently, have run into bits that are perhaps not very well documented, if at all. Below is my effort to document some of the problems we've run into, and how we fixed or worked around them.

Many of these are obviously wrong in retrospect, but hindsight is 20/20, and these problems do exist in many codebases currently.

Some are definitely ugly, and I much welcome better solutions! Tweet me at @daemon404 if you have any, or have your own CGO story/tips, please! I'd love to learn of them.

Table of Contents

package main
import (
"fmt"
"golang.org/x/net/http2/hpack"
)
func main() {
fmt.Println("nginx", "→", Encode("MYWS"))
fmt.Println("nginx", "→", Encode("nginx"))
@tianchaijz
tianchaijz / zcash-monitor.md
Created April 26, 2019 13:13 — forked from ageis/zcash-monitor.md
Prometheus exporter for monitoring statistics of Zcash daemon

zcash-monitor.py

This is a script written in Python intended to run alongside a Zcash node and export statistics for monitoring purposes. It assumes the existence of zcash-cli in the PATH and access to the RPC interface over localhost.

It tracks stuff like: block height, difficulty, number of peers, network solutions per second, errors, mempool size, size of recent blocks, number of transactions within blocks, chaintips, total bytes received and sent, transaction inputs and outputs, and the make-up of transactions in terms of JoinSplits, shielded, unshielded or mixed. These Zcash metrics are refreshed once every 2 minutes.

How it works

Prometheus is a monitoring system and time-series database.

@tianchaijz
tianchaijz / 000-tunneld-server.md
Last active November 7, 2018 05:39 — forked from ubergesundheit/000-tunneld-server.md
Ngrok alternative with mmatczuk/go-http-tunnel server
@tianchaijz
tianchaijz / js_spirit2.cpp
Created July 20, 2018 17:32 — forked from jefftrull/js_spirit2.cpp
Attempted solution to "Boost Spirit vs. Flex/Bison" comparison
// Attempt at making a Boost grammar that successfully parses Jason Shankel's predicate logic language
// #define BOOST_SPIRIT_DEBUG
#include <boost/spirit/include/qi.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/optional.hpp>
// start with the AST
@tianchaijz
tianchaijz / linalg.c
Created July 18, 2018 02:03 — forked from cloudwu/linalg.c
A linear algebra lua library
// C module for data stack manager
// See below for lua lib wrapper
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define MINCAP 128
local account = "blah@gmail.com" -- use your own gmail account
local password = "password" -- if you enable 2-phase authentication, you need to
-- generate and use a application-specific password here...
local sender_name = "Jon Snow"
local recipient = "recipient@foo.com"
local recipient_name = "Arya Stark"
local mail_title = "This is a test mail"
local mail_body = [[<html><body><p>Mail Body...</body></html>]]
@tianchaijz
tianchaijz / postgres-json-cheatsheet.md
Created March 20, 2018 08:36 — forked from rmtsrc/postgres-json-cheatsheet.md
Using JSON in Postgres by example

PostgreSQL JSON Cheatsheet

Using JSON in Postgres by example.

Quick setup via Docker

  1. Download and install: Docker Toolbox
  2. Open Docker Quickstart Terminal
  3. Start a new postgres container:
    docker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres