Skip to content

Instantly share code, notes, and snippets.

@syrusakbary
syrusakbary / benchmark.md
Created March 16, 2024 20:16
Pystone benchmark comparison (Native vs CPython interpreter vs Nuitka)

Native

When executing Python natively:

$ python pystone.py
Pystone(1.1) time for 50000 passes = 0.129016
This machine benchmarks at 387549 pystones/second
@okld
okld / components_callbacks.py
Last active March 8, 2024 22:00
Patch to use callbacks with Streamlit custom components.
"""Patch to use callbacks with Streamlit custom components.
Usage
-----
>>> import streamlit.components.v1 as components
>>> from components_callbacks import register_callback
>>>
>>> print("Script begins...")
>>>
@renuka-fernando
renuka-fernando / force-delete-namespace.sh
Last active January 15, 2023 13:16
Kubernetes - Force delete a Namespace with Invalid Finalizers
# namespace to be deleted in k8s
NAMESPACE=foo
# Terminal 1
kubectl proxy
# Terminal 2
kubectl get ns $NAMESPACE -o json | \
jq '.spec.finalizers=[]' | \
curl -X PUT "http://localhost:8001/api/v1/namespaces/${NAMESPACE}/finalize" -H "Content-Type: application/json" --data @-
@wschwab
wschwab / eventFilterWithPagination.js
Created August 24, 2020 14:57
an attempt at implementing some kind of pagination to an Ethereum event filter
const eventFilterv5WithPagination = (contractAddress, erc20abi, _provider, numberOfResponses) => {
// creating the interface of the ABI
const iface = new ethers.utils.Interface(erc20abi.abi);
// intialize array for the logs
let logs = [];
// get latest block number
const latest = await provider.getBlockNumber();
// intialize a counter for which block we're scraping starting at the most recent block
let blockNumberIndex = latest;
@wschwab
wschwab / eventFilter.js
Last active September 13, 2024 06:17
a handmade Ethereum event filter that you should never really use
const eventFilter = (contractAddress, contractAbi, eventName, _provider) => {
const provider = _provider
// this will return an array with an object for each event
const events = contractAbi.abi.filter(obj => obj.type ? obj.type === "event" : false);
// getting the Transfer event and pulling it out of its array
const event = events.filter(event => event.name === eventName)[0];
// getting the types for the event signature
const types = event.inputs.map(input => input.type)
// knowing which types are indexed will be useful later
let indexedInputs = [];
@p3jitnath
p3jitnath / install-docker.sh
Last active June 22, 2024 11:56
Docker and Nvidia Docker installation in Ubuntu 20.04 LTS
# WARNING : This gist in the current form is a collection of command examples. Please exercise caution where mentioned.
# Docker
sudo apt-get update
sudo apt-get remove docker docker-engine docker.io
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
docker --version
@jetersen
jetersen / add-cert.py
Created March 8, 2020 09:00
Python: add custom root ca to certifi store
import requests
import certifi
import sys
try:
requests.get('https://any-website-protected-by-your-custom-root-ca')
print('Certificate already added to the certifi store')
sys.exit(0)
except requests.exceptions.SSLError as err:
print('SSL Error. Adding custom certs to Certifi store...')
@vicsimental
vicsimental / PHP_OCI.md
Last active August 30, 2023 12:12
How to install OCI8 on Debian 10 Buster / Ubuntu 18.04 LTS / Ubuntu 16.04 and PHP 7.3
import json
import subprocess
import sys
import os
import zipfile
def upload_editable_requirement_from_current_venv(sc):
for requirement_dir in get_editable_requirements():
add_lib_to_spark_context(requirement_dir, sc)
import json
import subprocess
import sys
from pex.fetcher import PyPIFetcher
from pex.pex_builder import PEXBuilder
from pex.resolvable import Resolvable
from pex.resolver import resolve_multi, Unsatisfiable, Untranslateable
from pex.resolver_options import ResolverOptionsBuilder