Skip to content

Instantly share code, notes, and snippets.

@zhangw
zhangw / gist:0c4bd6ec53b493b0b5d60af752eb4b1a
Created May 11, 2024 14:01 — forked from chrisdone/gist:02e165a0004be33734ac2334f215380e
Build and run minimal Linux / Busybox systems in Qemu

Common

export OPT=/opt
export BUILDS=/some/where/mini_linux
mkdir -p $BUILDS

Linux kernel

Libuv and libev, two I/O libraries with similar names, recently had the privilege to use both libraries to write something. Now let's talk about my own subjective expression of common and different points.

The topic of high-performance network programming has been discussed. Asynchronous, asynchronous, or asynchronous. Whether it is epoll or kqueue, it is always indispensable to the asynchronous topic.

Libuv is asynchronous, and libev is synchronous multiplexing IO multiplexing.

Libev is a simple encapsulation of system I/O reuse. Basically, it solves the problem of different APIs between epoll and kqueuq. Ensure that programs written using livev's API can run on most *nix platforms. However, the disadvantages of libev are also obvious. Because it basically just encapsulates the Event Library, it is inconvenient to use. For example, accept(3) requires manual setnonblocking after connection. EAGAIN, EWOULDBLOCK, and EINTER need to be detected when reading from a socket. This is a

@zhangw
zhangw / daemonset-scaledown.md
Created June 20, 2023 12:09 — forked from ragul28/daemonset-scaledown.md
k8s Trick to Scale down daemonset to zero
  • Scaling k8s daemonset down to zero
kubectl -n kube-system patch daemonset myDaemonset -p '{"spec": {"template": {"spec": {"nodeSelector": {"non-existing": "true"}}}}}'
  • Scaling up k8s daemonset
kubectl -n kube-system patch daemonset myDaemonset --type json -p='[{"op": "remove", "path": "/spec/template/spec/nodeSelector/non-existing"}]'
@zhangw
zhangw / README.md
Created June 14, 2023 08:10 — forked from ayosec/README.md
GDB commands to trace calls to malloc/free

Attach to a running process with

  gdb -x trace-dyn-mem -p $PID

After every malloc the returned value (the allocated address) will be read from the RAX (64 bits) register.

After every free the last item in the backtrace (the free itself) will be shown. With the libc6-dbg package installed you can see the address passed as the first argument of free.

@zhangw
zhangw / rust-cross-compile-openssl
Last active February 18, 2023 05:16 — forked from marirs/rust-cross-compile-openssl
Rust OpenSSL Cross Compile for Linux on Mac M1
# Install the toolchain
```bash
brew tap SergioBenitez/osxct
brew install x86_64-unknown-linux-gnu
```
# this should get installed in:
# /opt/homebrew/Cellar/x86_64-unknown-linux-gnu/
# Installing the macOS OpenSSL - if not already installed
@zhangw
zhangw / README.md
Created October 11, 2022 04:32 — forked from darrenpmeyer/README.md
Automatically start a single instance of ssh-agent for all terminal sessions to share (bash)

Installation

  1. mkdir -p ~/.config && touch ~/.config/ssh-agent.pid
  2. Paste the contents of ssh-agent-manage.sh into your .bashrc or .bash_profile or similar
  3. killall -9 ssh-agent
  4. Start a new terminal session (note: old sessions will not see ssh-agent, only new ones)

Details

This snippet, when included in .bashrc, will ensure that your session has a working ssh-agent with all your ssh keys loaded into it. It does this without creating separate ssh-agent processes by:

@zhangw
zhangw / Generate_new_table.sql
Created August 26, 2022 09:39 — forked from lacerogers20/Generate_new_table.sql
This will use "create table" and generate a new table with clustering and partitioning
CREATE TABLE
`testing.insert` (date DATE OPTIONS( description='date' ),
unique_visits INT64 OPTIONS( description='counts' ))
PARTITION BY
date
CLUSTER BY
unique_visits OPTIONS ( description="A table with a date partition",
labels=[("testing",
"data_is_great")],
expiration_timestamp=TIMESTAMP "2023-01-01 00:00:00 UTC"
SELECT
date,
COUNT(DISTINCT(visitid)) as unique_visits
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`
WHERE _table_suffix = '20170801' # use date_sub to programmatically select your table
GROUP BY date
ORDER BY date
@zhangw
zhangw / proper_case_function.sql
Created August 26, 2022 09:38 — forked from lacerogers20/proper_case_function.sql
Example of building a simple UDF compared to the standard SQL function
CREATE TEMP FUNCTION
PROPER(str STRING) AS ((
SELECT
STRING_AGG(CONCAT(UPPER(SUBSTR(w,1,1)), LOWER(SUBSTR(w,2))), ' '
ORDER BY
pos)
FROM
UNNEST(SPLIT(str, ' ')) w
WITH
DECLARE
SQLRUN STRING DEFAULT '';
CREATE TEMP FUNCTION
ga4_firebase( key1 STRING,
params ARRAY <STRUCT <key STRING,
value STRUCT <string_value STRING,
int_value INT64,
float_value FLOAT64,
double_value FLOAT64 >>>) AS ( (
SELECT