Skip to content

Instantly share code, notes, and snippets.

View Aviksaikat's full-sized avatar
💭
I tell people secrets, it makes them like me

Saikat Karmakar Aviksaikat

💭
I tell people secrets, it makes them like me
View GitHub Profile
@Aviksaikat
Aviksaikat / square_root.rs
Created November 12, 2024 08:40
Find square root of U256 or any integers
use alloy::primitives::U256;
fn integer_sqrt(n: U256) -> U256 {
// https://en.wikipedia.org/wiki/Integer_square_root
if n < U256::from(2) {
return n;
}
let small_candidate = integer_sqrt(n >> 2) << 1;
@Aviksaikat
Aviksaikat / convert.rs
Created November 11, 2024 13:53
convert U256 to f64
use alloy::primitives::U256;
fn main() {
let reserve_ratio: f64 = pool.reserve0.to::<f64>() / pool.reserve1.to::<f64>();
}
@Aviksaikat
Aviksaikat / get_pending_tx.rs
Created October 18, 2024 15:30
Get pending transactions using Rust
use web3::transports::WebSocket;
use web3::Web3;
def main() {
let rpc_url: String = "http://localhost:8545" //"Your RPC URL"
// Initialize WebSocket transport
let ws = WebSocket::new(&rpc_url).await?;
let w3 = Web3::new(ws);
info!("Successfully connected to WebSocket RPC.");
@Aviksaikat
Aviksaikat / pyproject.toml
Last active July 6, 2024 07:38
Add custom files and folders to ship with your pip package
## Using hatch but should be similar for other tools
# https://hatch.pypa.io/latest/config/build/#pyprojecttoml_5
# Build configs
[tool.hatch.build.targets.sdist]
include = [
"src/**/*.py",
".configs/*"
]
@Aviksaikat
Aviksaikat / get_token_balances.py
Created May 16, 2024 07:47
get tokens associated with a token account (EOA account)
from solders.pubkey import Pubkey
from solana.rpc.api import Client
from solders.pubkey import Pubkey
from solders.keypair import Keypair
from solana.rpc.types import TokenAccountOpts
from rich.pretty import pprint
# You can use async client as well
http_client = Client("https://api.mainnet-beta.solana.com")
private_key = Keypair.from_bytes(bytes(key))
@Aviksaikat
Aviksaikat / get_decimals_sol.py
Last active July 17, 2024 07:33
Get decimals of a token from SOLANA chain from a given address
from spl.token._layouts import MINT_LAYOUT
from solana.rpc.api import Client, Pubkey
http_client = Client("https://api.mainnet-beta.solana.com")
# USDC token address
addr = Pubkey.from_string("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")
info = http_client.get_account_info(addr)
decimals = MINT_LAYOUT.parse(info.value.data).decimals
@Aviksaikat
Aviksaikat / pipx_upgrade.sh
Created April 9, 2024 15:59
one liner to upgrade all pipx packages
pipx list --short | cut -d ' ' -f1 | while read line; do pipx upgrade $line; done
@Aviksaikat
Aviksaikat / Filecoin-Station.desktop
Created March 5, 2024 19:06
desktop file for Filecoin Station AppImage
[Desktop Entry]
Name=Filecoin Station
Comment=Filecoin Station
Exec=/home/avik/tools/filecoin-station-linux-x86_64.AppImage
Icon=/home/avik/tools/icons-for-appImage/file-coin-station.jpg
Terminal=false
Type=Application
Categories=Development;
@Aviksaikat
Aviksaikat / ledger-live-desktop.desktop
Created March 5, 2024 19:05
Ledger Live Desktop App `.desktop` file for linux
[Desktop Entry]
Name=Ledger Live Desktop
Comment=Ledger Live Desktop App
Exec=/home/avik/tools/ledger-live-desktop-2.77.2-linux-x86_64.AppImage
Icon=/home/avik/tools/icons-for-appImage/ledger.webp
Type=Application
Terminal=false
Categories=Development;
@Aviksaikat
Aviksaikat / remove_old_snap.sh
Created January 20, 2024 14:27
remove old versions of snap packages
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
echo "Size before cleanup"
du -h /var/lib/snapd/snaps
set -eu
snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision;