Skip to content

Instantly share code, notes, and snippets.

View amanelis's full-sized avatar
🧙‍♀️

amanelis

🧙‍♀️
View GitHub Profile
@amanelis
amanelis / size.sql
Created November 22, 2023 03:08
Query a Postgres' tables size in bytes
SELECT l.metric, l.nr AS bytes
, CASE WHEN is_size THEN pg_size_pretty(nr) END AS bytes_pretty
, CASE WHEN is_size THEN nr / NULLIF(x.ct, 0) END AS bytes_per_row
FROM (
SELECT min(tableoid) AS tbl -- = 'public.tbl'::regclass::oid
, count(*) AS ct
, sum(length(t::text)) AS txt_len -- length in characters
FROM {YOUR TABLE} t -- provide table name *once*
) x
CROSS JOIN LATERAL (
@amanelis
amanelis / High_Performance_Redis.md
Created November 4, 2023 21:50 — forked from neomantra/High_Performance_Redis.md
Notes on running Redis with HPC techniques

High Performance Redis

In response to this brief blog entry, @antirez tweeted for some documentation on high-performance techniques for Redis. What I present here are general high-performance computing (HPC) techniques. The examples are oriented to Redis. but they work well for any program designed to be single- or worker-threaded and asynchronous (e.g. uses epoll).

The motivation for using these techniques is to maximize performance of our system and services. By isolating work, controlling memory, and other tuning, you can achieve significant reduction in latency and increase in throughput.

My perspective comes from the microcosm of my own bare-metal (vs VM), on-premises deployment. It might not be suitable for all scenarios, especially cloud deployments, as I have little experience with HPC there. After some discussion, maybe this can be adapted as [redis.io documentation](https://redis.io/do

@amanelis
amanelis / readdb.go
Created August 29, 2023 17:07 — forked from NAKsir-melody/readdb.go
Read ethereum level DB directly
package main
import (
"fmt"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
_ "github.com/ethereum/go-ethereum/common"
@amanelis
amanelis / work_queue.rs
Created February 7, 2023 06:22 — forked from NoraCodes/work_queue.rs
An example of a parallel work scheduling system using only the Rust standard library
// Here is an extremely simple version of work scheduling for multiple
// processors.
//
// The Problem:
// We have a lot of numbers that need to be math'ed. Doing this on one
// CPU core is slow. We have 4 CPU cores. We would thus like to use those
// cores to do math, because it will be a little less slow (ideally
// 4 times faster actually).
//
// The Solution:
@amanelis
amanelis / arbitrage.py
Created August 22, 2022 17:54 — forked from noxx3xxon/arbitrage.py
CFMM Routing Arbitrage Example
import numpy as np
import cvxpy as cp
import itertools
# Problem data
global_indices = list(range(4))
# 0 = TOKEN-0
# 1 = TOKEN-1
# 2 = TOKEN-2
@amanelis
amanelis / Multicall.sol
Created August 11, 2022 22:42 — forked from 0xAlcibiades/Multicall.sol
A Pre EIP-1559 MEV/Multicall in pure Yul integrated with ApeBank and with Native GasTokens
// SPDX-License-Identifier: MIT
object "Multicall" {
code {
// Deploy the contract
// Store gas token burn cost in zero slot
sstore(0, 0)
sstore(1, 0)
sstore(2, 0)
datacopy(0x0, dataoffset("MulticallRuntime"), datasize("MulticallRuntime"))
@amanelis
amanelis / ethereum_keys.sh
Created July 13, 2022 05:32 — forked from miguelmota/ethereum_keys.sh
Generate Ethereum Private key, Public key, and Address using Bash and OpenSSL
# Generate the private and public keys
openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout > key
# Extract the public key and remove the EC prefix 0x04
cat key | grep pub -A 5 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^04//' > pub
# Extract the private key and remove the leading zero byte
cat key | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//' > priv
# Generate the hash and take the address part
package main
import (
"context"
"fmt"
"io/ioutil"
"net/http"
neturl "net/url"
"time"
)
@amanelis
amanelis / geth.service
Created October 2, 2021 20:39
geth standard fast configuration
# /etc/systemd/system/geth.service
[Unit]
Description=Go Ethereum Client
After=network.target
Wants=network.target
[Service]
User=goeth`
Group=goeth
@amanelis
amanelis / fremont_covid_vaccine.rb
Created April 11, 2021 17:35
A quick ruby script for checking COVID-19 Vaccine in Fremont, California
require 'rubygems'
require 'nokogiri'
require 'open-uri'
puts "COVID Vaccine Finder / Fremont, California"
page = Nokogiri::HTML(open(URL))
mDiv = "body > div > div.shadow-sm.p-3.mb-4.rounded > div:nth-child(8) > div"
bDiv = "button"