Skip to content

Instantly share code, notes, and snippets.

View airled's full-sized avatar

Uladzimir airled

  • Minsk, Belarus
View GitHub Profile
@airled
airled / curry.js
Last active March 2, 2023 15:08
Simple currying example in JS
class Curry {
constructor(fn) {
return this.curry(fn, fn.length, [])
}
curry(fn, argRestCounter, args) {
if (argRestCounter === 0) return fn(…args);
return arg => this.curry(fn, argRestCounter — 1, […args, arg]);
}
}
@airled
airled / subs.rb
Created February 5, 2024 05:55
Check substring in string
def subs(str1, str2)
return nil if str2.size > str1.size
str1.each_char.with_index do |char, index|
next if char != str2[0]
match = true
str2[1..].each_char.with_index do |_, str2_slice_index|
str2_index = str2_slice_index + 1
next if str2[str2_index] == str1[index + str2_index]
@airled
airled / contract_call.js
Created April 11, 2024 12:55
ETH contract call
const { ethers } = require("ethers");
const rpcUrl = ''
const contractAddress = ''
const abi = []
async function main() {
const provider = new ethers.JsonRpcProvider(rpcUrl);
const signer = new ethers.Wallet("", provider)
const contract = new ethers.Contract(contractAddress, abi, signer);
@airled
airled / affinity.sh
Last active June 20, 2024 06:28
Show list of process affinities ommiting threads
# Show list of process affinities omitting threads
for pid in $(ps --ppid 2 -p 2 --deselect -o pid=); do taskset -pc $pid 2>/dev/null; done
@airled
airled / qsort.rs
Last active November 15, 2025 11:45
Simple quicksort in rust
fn qs<T: std::cmp::Ord>(a: &mut [T]) {
if a.len() <= 1 { return; }
let last_index = a.len() - 1; // pivot index
let mut partition_index = 0;
for i in 0..last_index {
if a[i] >= a[last_index] { continue; }
a.swap(i, partition_index);
partition_index += 1;
@airled
airled / extractor.sol
Created August 14, 2024 13:54
Extract a signer address from signature of a personal signed message
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
using MessageHashUtils for bytes;
using ECDSA for bytes32;
contract AddressExtractor {
@airled
airled / u32_to_bytes.rs
Created November 4, 2025 07:24
Convert u32 to the vec of bytes big-endian
fn int_to_bytes(num: u32) -> Vec<u8> {
let mut bytes: Vec<u8> =
(0..4).map(|offset| ((num >> offset * 8) & 0xFF) as u8).collect();
bytes.reverse();
bytes
}
fn main() {
let res = int_to_bytes(1234u32);
println!("{:?}", res);
@airled
airled / xray_client.json
Last active November 11, 2025 04:38
Minimal xray client config
{
"inbounds": [
{
"port": 1080,
"protocol": "socks",
"settings": {
"udp": true
}
}
],
@airled
airled / xray_server.json
Created November 11, 2025 04:37
Minimal xray server config
{
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "{xray uuid}",
"flow": "xtls-rprx-vision"
@airled
airled / u128_to_string.rs
Created November 16, 2025 06:44
Represent u128 to the string
const ALPHABET: [char; 16] =
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
// Do not use in production:
// - does not check base 0
// - u128 instead of generic
// - no negative support
fn to_s(num: u128, base: u128) -> String {
let mut buffer: String = String::new();
let mut div = num;