Skip to content

Instantly share code, notes, and snippets.

@andrijdavid
andrijdavid / uint8arraytobase58.js
Created March 15, 2025 08:05
Converting Solana Private Key in JSON to Phantom Wallet Format
const privateKeyArray = [18, 245, 33, 87, 214, 128, 45, 87, 213, 98, 34, 64, 23, 12, 87, 213, 98, 34, 64, 23, 12, 87, 213, 98, 34, 64, 23, 12, 87, 213, 98, 34, 64, 23, 12, 87, 213, 98, 34, 64, 23, 12, 87, 213, 98, 34, 64, 23, 12, 87, 213, 98, 34, 64, 23, 12, 87, 213, 98, 34, 64, 23, 12, 87, 213, 98, 34, 64, 23];
const privateKeyUint8Array = new Uint8Array(privateKeyArray);
const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
function encodeBase58(uint8Array) {
let digits = [0];
for (let i = 0; i < uint8Array.length; i++) {
for (let j = 0; j < digits.length; j++) digits[j] <<= 8;
digits[0] += uint8Array[i];
@andrijdavid
andrijdavid / intercept.js
Created March 1, 2025 09:29
This script intercepts and redirects network requests destined to RPC endpoints to corresponding endpoints on Tenderly. It modifies requests made using the fetch API, XMLHttpRequest, and WebSockets.
// Define the URLs to be intercepted and their respective replacements
const URL_MAP = {
'https://base-mainnet.g.alchemy.com/v2/tgXc05yLe8pJDawEM3OZZdMYD8i29Qsi': 'https://virtual.base.rpc.tenderly.co/{CHANGE WITH YOUR KEY}',
'wss://base-mainnet.g.alchemy.com/v2/tgXc05yLe8pJDawEM3OZZdMYD8i29Qsi': 'wss://virtual.base.rpc.tenderly.co/{CHANGE WITH YOUR KEY}'
};
// Helper function to get the redirected URL
function getRedirectedUrl(url) {
for (const [original, replacement] of Object.entries(URL_MAP)) {
if (url.includes(original)) {
@andrijdavid
andrijdavid / app.py
Created April 10, 2023 10:27 — forked from init27/app.py
ArXiv Chat: Chat with the latest Arxiv papers
# Credit 🙏: I just used the example from langchain docs and it works quite well: https://python.langchain.com/en/latest/use_cases/question_answering.html
# Note 2: The Arxiv -> PDF logic is a bit messy, I'm sure it can be done better
# Note 3: Please install the following:
# To run:
# Save this in a `app.py`
# pip install arxiv PyPDF2 langchain chromadb
# The chat feature was shipped in H2O nightly this week, we will need to install from nightly link:
@andrijdavid
andrijdavid / setdevice.py
Created November 5, 2020 08:55
Set proper cuda device
import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" # see issue #152
os.environ["CUDA_VISIBLE_DEVICES"]="0"
@andrijdavid
andrijdavid / data.py
Last active February 19, 2019 07:00
MultiTask API for fast.ai
from fastai.basics import ItemBase, ItemList, Iterator, Collection, Callable, LabelList, Any, IntsOrStrs, listify, show_some, array, extract_kwargs
from fastai.vision import ImageDataBunch, ImageItemList
from fastai.data_block import PreProcessors, PreProcessor
class MultiLabelProcessor(PreProcessor):
def __init__(self, ds:Collection=None):
self.ref_ds = ds
self.procs_y = []
def process(self, ds:Collection=None):
@andrijdavid
andrijdavid / DK444-datablock-3channel-modified.ipynb
Created December 1, 2018 11:37
kaggle_hpa/DK444-datablock-3channel-modified.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@andrijdavid
andrijdavid / conv.py
Created October 28, 2018 20:01
Calculate the output of a convolution
from math import floor
def conv_output_shape(h_w, kernel_size=1, stride=1, pad=0, dilation=1):
if type(kernel_size) is not tuple:
kernel_size = (kernel_size, kernel_size)
if type(stride) is not tuple:
stride = (stride, stride)
if type(pad) is not tuple:
pad = (pad, pad)
if type(dilation) is not tuple:
41.63.128.0/19
196.43.214.0/24
196.46.158.148/30
196.46.158.192/30
196.49.13.0/24
196.192.32.0/20
196.223.41.0/24
197.148.128.0/18
197.149.0.0/18
197.158.64.0/18
name: "SENet"
# mean_value: 104, 117, 123
layer {
name: "data"
type: "Input"
top: "data"
input_param: {
shape: {
dim: 1
dim: 3
@andrijdavid
andrijdavid / SaveBestModel.py
Last active May 25, 2018 10:29
Save best model across multiple training in fast.ai
class SaveBestModel(LossRecorder):
""" Save weights of the best model based during training.
If metrics are provided, the first metric in the list is used to
find the best model.
If no metrics are provided, the loss is used.
Args:
model: the fastai model
lr: indicate to use test images; otherwise use validation images