Skip to content

Instantly share code, notes, and snippets.

View esemeniuc's full-sized avatar

Eric Semeniuc esemeniuc

View GitHub Profile
@esemeniuc
esemeniuc / gist:dca6bdbf4c758774d9d771b4540117eb
Last active January 6, 2024 04:18
Websocket example for Solana RPC
Subscribe to any acount changes to Pyth SOL/USDC account (H6AR...QJEG):
This requires websocat - `brew install websocat`
```bash
echo '{"id":1,"jsonrpc":"2.0","method":"accountSubscribe","params":["H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG",{"encoding": "jsonParsed"}]}' | websocat --no-close "wss://internal.ny.mainnet.rpc.jito.wtf/?access-token=XYZ"
```
Output
```
{"jsonrpc":"2.0","method":"accountNotification","params":{"result":{"context":{"slot":240142003},"value":{"lamports":23942400,"data":["1MOyoQIAAAADAAAA8AwAAAEAAAD4////GgAAABcAAAC0RlAOAAAAALNGUA4AAAAAGAudTAIAAAB/ZvSRAAAAAJ08zJMAAAAAFUKKAAAAAAAc++qFAAAAAJ08zJMAAAAAUNSYZQAAAAADAAAAAAAAAIqwPP8YRKuXXc3RaDAgwFmfxTkrby4S1d1hW8wsLm0IAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACzRlAOAAAAAHT4GUsCAAAA6daTAAAAAABP1JhlAAAAAHT4GUsCAAAA6C6NAAAAAAABAAAAAAAAALRGUA4AAAAAB/LLOf2wKdxReE0o7xeRHZfBppyFcjobYlWzQlNDrXUNzhRLAgAAAKBnWgMAAAAAAQAAAAAAAACeRlAOAAAAAA3OFEsCAAAAoGdaAwAAAAABAAAAAAAAAJ5GUA4AAAAAnz6le9QJugDEDZKuVxNBwn48L37frOHCSlGxoVwxsregsyJLAgAAAAJjkgMAAAAAAQAAA
@esemeniuc
esemeniuc / redis.lua
Created August 15, 2023 05:01
Redis Chunking (avoid unpack() stack issues)
local keys = redis.call('KEYS', ARGV[1]);
if next(keys) == nil then return keys end;
local chunk_size = 4096; -- must be under 8k, see https://github.com/nhibernate/NHibernate-Caches/issues/62
local n = #keys;
local out = {};
for i=1,n,chunk_size do
local unpack_start = i;
local unpack_end = math.min(n, i + chunk_size - 1);
local vals = redis.call('MGET', unpack(keys, unpack_start, unpack_end));
@esemeniuc
esemeniuc / ErrorBoundary.tsx
Last active June 29, 2023 14:40
ErrorBoundary for React 16 using Typescript
import React, {ErrorInfo} from 'react';
export default class ErrorBoundary extends React.Component<{}, { hasError: boolean }> {
constructor(props: {}) {
super(props);
this.state = {hasError: false};
}
static getDerivedStateFromError(error: Error) { // Update state so the next render will show the fallback UI.
return {hasError: true};
@esemeniuc
esemeniuc / rotate_cert_redis.md
Last active June 26, 2023 13:07
Rotate certificate in redis without restarting

Generate expiring certs

#!/bin/bash

# Generate some test certificates which are used by the regression test suite:
#
#   tests/tls/ca.{crt,key}          Self signed CA certificate.
#   tests/tls/redis.{crt,key}       A certificate with no key usage/policy restrictions.
#   tests/tls/client.{crt,key}      A certificate restricted for SSL client usage.
#   tests/tls/server.{crt,key}      A certificate restricted for SSL server usage.
@esemeniuc
esemeniuc / redis.rs
Created June 19, 2023 16:11
Redis Pub/Sub Async Reconnect Example
use std::thread::sleep;
use std::time::{Duration, Instant};
use redis::{AsyncCommands, ConnectionLike, RedisResult};
use tokio::time::timeout;
use futures::StreamExt;
use futures_util::Stream;
/* Cargo.toml
@esemeniuc
esemeniuc / demo.sh
Created June 3, 2023 04:05
CSV Import to Sqlite
cat file.csv | sqlite3 demo.db ".import --csv '|cat -' mytable"; sqlite3 demo.db
@esemeniuc
esemeniuc / benchmark_lock.rs
Last active May 30, 2023 19:26
Read contention Benchmark for Tokio async vs arc_swap vs RwLock vs parking_lot
/* results on 24 threads, Linux, Ryzen 5900X, 64GB RAM, rust 1.66 release mode
mutex st: 3.504602ms
mutex mt 24 threads: 966.566131ms
rwlock st: 4.115984ms
rwlock mt 24 threads: 1.639819526s
parking_lot st: 4.255349ms
parking_lot mt 24 threads: 1.336455132s
try channel st: 18.446771ms
try channel mt 24 threads: 3.152402156s
new channel st: 45.410769ms
@esemeniuc
esemeniuc / Readme.md
Last active March 28, 2023 03:48
Grafana FluxQL demo
import "array"
 
array.from(rows: [
  {_time: 2021-01-01T00:00:00Z, _value: "foo"},
  {_time: 2020-01-02T00:00:00Z, _value: "bar"}
])

@esemeniuc
esemeniuc / example.rs
Created March 24, 2023 05:12
Rustls SSLKEYLOGFILE extraction
use rustls;
let roots = rustls::RootCertStore::empty();
let mut tls = rustls::ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(roots)
.with_no_client_auth();
tls.key_log = Arc::new(rustls::KeyLogFile::new());
let client = Arc::new(
@esemeniuc
esemeniuc / duplicate_packets.nft
Created March 17, 2023 01:54
Duplicate packets
#!/usr/sbin/nft -f
# see https://unix.stackexchange.com/questions/740061/how-do-you-duplicate-all-udp-traffic-on-a-port-range-using-nftables/
# sends all duplicated packets to 10.0.0.1
# run this before applying this file
# sudo ip addr add 10.0.0.1/24 dev lo
# clean up with
# sudo ip addr delete 10.0.0.1/24 dev lo