Skip to content

Instantly share code, notes, and snippets.

View alebaffa's full-sized avatar
🗼
Focusing

Alessandro alebaffa

🗼
Focusing
View GitHub Profile
@alebaffa
alebaffa / git-squash.md
Last active November 30, 2023 21:28
Git squash alternatives

Git Squash alternatives:

  • git rebase -i HEAD~X - this allows you to merge interactively several commits
    • then fixup OR pick OR reword AND push --force
  • git reset --hard HEAD~X - this rollbacks the index back to X commits (check git status before doing this. Commit first)
    • commit again using just one commit
  • git reset --hard COMMIT_ID - this rollbacks the index back to the commit_id
@alebaffa
alebaffa / uniswap_v3_multicall_decode.py
Created November 1, 2023 02:31
Decode Uniswap V3 multicall (web3.py)
w3 = web3.Web3(HTTPProvider("PUT HERE YOUR PROVIDER"))
UNISWAP_V3_POSITIONS_NFT = "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
# example of Ethereum transaction calling multicall on Uniswap v3 (Etherscan)
tx = w3.eth.get_transaction(HexBytes("0xb835f4ab29be621eca1b2520a1e85d06b2e4fc03b84772e3fe05c220509e88b7"))
abi = await get_abi(Chain.ETHEREUM, UNISWAP_V3_POSITIONS_NFT)
contract = w3.eth.contract(HexBytes(UNISWAP_V3_POSITIONS_NFT), abi=abi)
fn, params = contract.decode_function_input(tx.input)
fn_and_params: dict[str, list[dict[str, str]]] = {}
for key, value in params.items():
for v in value:
@alebaffa
alebaffa / download-github-artifact
Created December 17, 2022 07:27 — forked from umohi/download-github-artifact
use curl to download release artifact from github private repository
# in order to download release artifacts from github, you have to first retreive the
# list of asset URLs using the github repo REST API. Use the asset URL to download
# the artifact as a octet-stream data stream. You will need to get an access token
# from "settings -> developer settings -> personal access tokens" on the github UI
#!/bin/bash -e
owner="MY_ORG_NAME"
repo="MY_REPO_NAME"
tag="ARTIFACT_TAG"
artifact="ARTIFACT_NAME"
@alebaffa
alebaffa / install_anaconda.md
Created August 26, 2022 14:59 — forked from kauffmanes/install_anaconda.md
Install Anaconda on Windows Subsystem for Linux (WSL)

Thanks everyone for commenting/contributing! I made this in college for a class and I no longer really use the technology. I encourage you all to help each other, but I probably won't be answering questions anymore.

This article is also on my blog: https://emilykauffman.com/blog/install-anaconda-on-wsl

Note: $ denotes the start of a command. Don't actually type this.

Steps to Install Anaconda on Windows Ubuntu Terminal

  1. Install WSL (Ubuntu for Windows - can be found in Windows Store). I recommend the latest version (I'm using 18.04) because there are some bugs they worked out during 14/16 (microsoft/WSL#785)
  2. Go to https://repo.continuum.io/archive to find the list of Anaconda releases
  3. Select the release you want. I have a 64-bit computer, so I chose the latest release ending in x86_64.sh. If I had a 32-bit computer, I'd select the x86.sh version. If you accidentally try to install the wrong one, you'll get a warning in the terminal. I chose `Anaconda3-5.2.0-Li
@alebaffa
alebaffa / rust_print.rs
Created August 24, 2022 08:00
Substrate force print
// To force print in console
sp_std::if_std! {
// This code is only being compiled and executed when the `std` feature is enabled.
println!("Hello native world");
}
// Run this command to see it in console during tests: cargo test -- --nocapture
@alebaffa
alebaffa / string-conversion.rs
Created August 1, 2022 01:37 — forked from jimmychu0807/string-conversion.rs
Conversion between String, str, Vec<u8>, Vec<char> in Rust
use std::str;
fn main() {
// -- FROM: vec of chars --
let src1: Vec<char> = vec!['j','{','"','i','m','m','y','"','}'];
// to String
let string1: String = src1.iter().collect::<String>();
// to str
let str1: &str = &src1.iter().collect::<String>();
// to vec of byte
@alebaffa
alebaffa / fabric-basic-chaincode.md
Last active October 3, 2021 09:28
Hyperledger Fabric basic lifecycle

List of steps of a basic chaincode lifecycle on Hyperledger Fabric

Pre-requisites

  • Install Docker Compose: sudo apt install -y docker-compose (Make sure that the docker-compose version is 1.14.0)
  • Install Golang version >= 1.15.x
  • Install build essential sudo apt install -y build-essential

Download Fabric and Fabric-samples

  • mkdir -p $HOME/go/src/github.com/hyperledger
  • cd $HOME/go/src/github.com/hyperledger
  • curl -sSL http://bit.ly/2ysbOFE | bash -s -- 2.2.2 1.4.9 (do not change these versions)

Bank in a Box Workshop for Capital Markets : Speaker Notes

Installing and Configuring a local Kubernetes cluster

brew install docker kubectl helm 

You can do this with docker for mac by enabling kubernetes
Make sure to set docker for mac's resources for this demo. Ideally 8GB CPU, and 12GB of Memory.

@alebaffa
alebaffa / text_analyzer.rb
Created March 24, 2014 14:56
Write a Ruby program that analyzes an MP3 file. Many MP3 files have a 128-byte data structure at the end called an ID3 tag. These 128 bytes are literally packed with information about the song: its name, the artist, which album it's from, and so on. You can parse this data structure by opening an MP3 file and doing a series of reads from a posit…
class TextAnalyzer
def initialize
@file = File.open("song.mp3")
end
def has_tag?
@file.seek(-128, IO::SEEK_END)
@file.read(3) == 'TAG'
end
@alebaffa
alebaffa / QueryExamples.kt
Last active June 22, 2021 00:13
Examples of queries with Corda
// 1. Use the PersistentState custom schema to filter by custom attribute
val customFilter = builder {
StateSchemaV1.PersistentState::productId.equal(productId)
}
// 2. Create a CustomQueryCriteria using the above filter
val customCriteria = QueryCriteria.VaultCustomQueryCriteria(customFilter)
// 3. Easy and quick filter. This returns a list
val state = serviceHub.vaultService.queryBy<YourState>().states.filter {