Skip to content

Instantly share code, notes, and snippets.

@yaowenqiang
yaowenqiang / sniff.txt
Created January 12, 2023 09:51 — forked from manifestinteractive/sniff.txt
A friendly formatter for curl requests to help with debugging.
\n
============= HOST: ==========\n
\n
local_ip: %{local_ip}\n
local_port: %{local_port}\n
remote_ip: %{remote_ip}\n
remote_port: %{remote_port}\n
\n
======= CONNECTION: ==========\n
\n
@yaowenqiang
yaowenqiang / Quirks of C.md
Created November 21, 2022 10:30 — forked from fay59/Quirks of C.md
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;
@yaowenqiang
yaowenqiang / tmux split-window subcommand.md
Created October 11, 2022 08:42 — forked from sdondley/tmux split-window subcommand.md
Super Guide to the split-window tmux Subcommand (and Beyond)

Super Guide to the split-window tmux Subcommand (and Beyond)

Guide overview

tmux, like other great software, is deceptive. On the one hand, it's fairly easy to get set up and start using right away. On the other hand, it's difficult to take advantage of tmux's adanced power features without spending some quality alone time with the manual. But the problem with manuals is that they aren't geared toward beginners. They are geared toward helping seasoned developers and computer enthusiasts quickly obtain the

@yaowenqiang
yaowenqiang / notes.md
Created July 15, 2022 08:08 — forked from ian-whitestone/notes.md
Best practices for presto sql

Presto Specific

  • Don’t SELECT *, Specify explicit column names (columnar store)
  • Avoid large JOINs (filter each table first)
    • In PRESTO tables are joined in the order they are listed!!
    • Join small tables earlier in the plan and leave larger fact tables to the end
    • Avoid cross joins or 1 to many joins as these can degrade performance
  • Order by and group by take time
    • only use order by in subqueries if it is really necessary
  • When using GROUP BY, order the columns by the highest cardinality (that is, most number of unique values) to the lowest.
@yaowenqiang
yaowenqiang / gist:5c3a47171224b852dc5cc0110d2d5bda
Created June 28, 2022 11:49 — forked from ipedrazas/gist:2c93f6e74737d1f8a791
List Docker Container Names and IPs
function drips(){
docker ps -q | xargs -n 1 docker inspect --format '{{ .NetworkSettings.IPAddress }} {{ .Name }}' | sed 's/ \// /'
}
@yaowenqiang
yaowenqiang / mysqld_exporter.service
Created May 23, 2022 12:03 — forked from lepiaf/mysqld_exporter.service
Prometheus - mysql_exporter systemd
# /etc/systemd/system/mysql_exporter.service
[Unit]
Description=Mysql Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=root
@yaowenqiang
yaowenqiang / install-tmux
Created May 17, 2022 11:08 — forked from cdkamat/install-tmux
Install tmux 2.3 on rhel/centos 6
# Install tmux on Centos release 6.5
# install deps
yum install gcc kernel-devel make ncurses-devel
# DOWNLOAD SOURCES FOR LIBEVENT AND MAKE AND INSTALL
curl -OL https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
tar -xf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable
./configure --prefix=/usr/local

You are doing JSON APIs wrong.

When you use JSON to call an API - not a REST API, but something like JSON-RPC - you will usually want to encode one of several possible messages.

Your request body looks like this:

{
 "type": "MessageWithA",