Skip to content

Instantly share code, notes, and snippets.

View 0ex-d's full-sized avatar
💭
Engr. management

Precious 0ex-d

💭
Engr. management
  • Irgendwo, Irgendwohin (100% remote)
View GitHub Profile
@0ex-d
0ex-d / WS-optcode
Created November 20, 2023 13:28
My personal optcodes for WS handshakes
Text:
ping
pong
Binary:
01110000 01101001 01101110 01100111
01110000 01101111 01101110 01100111
Hex (ASCII):
@0ex-d
0ex-d / CLI_install.txt
Last active June 25, 2023 00:00
AWS setup on machine (Dowload latest AWS SDK for CLI https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) Most of the fiels are stored in ~/aws/
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
@0ex-d
0ex-d / create_bucket.js
Last active June 24, 2023 23:59
This is used for Cloudflare R2 which has a very similar Cloud infra stetup with AWS S3
const { S3Client, CreateBucketCommand } = require("@aws-sdk/client-s3");
// Replace the following placeholders with your own values
const bucketName = "your-bucket-name";
const region = "your-preferred-region";
// Set up the S3 client
const s3Client = new S3Client({ region });
// Create the S3 bucket
@0ex-d
0ex-d / rust_mutable_with_immut_bounds.rs
Created April 23, 2023 18:40
Poking the Rust 🦀 Borrow Checker.
// ❌ snippet_a
// This wouldn't work in Rust compiler because we're trying to change immutable data in memory
// https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#variables-and-mutability
// Look at the fix in *snippet_b*
let mut_data:Vec<(),()> = Vec::new();
for datum in set_of_data {
mut_data.push(datum);
}
// ✅ snippet_b
@0ex-d
0ex-d / invert_binary_tree_once.rs
Created April 8, 2023 20:00
I inverted a Binary Tree "once" so you don't have to anymore ;(
fn main() -> Result<(), std::process::ExitCode> {
invert_binary_tree_once(Some(🌳));
Ok(std::process::ExitCode::SUCCESS)
}
#[must_use = "You darn bloke! use a type that implements a *Copy* trait."]
struct BnTree;
fn invert_binary_tree_once(&mut b_tree: Option<BnTree>) -> Option<BnTree> {
@0ex-d
0ex-d / ctx-sandbox-a-nodejs.js
Created November 27, 2022 15:06
Create a context for executing code in a sanbox using Node.js runtime Package: https://nodejs.org/docs/latest-v18.x/api/vm.html
// https://nodejs.org/docs/latest-v18.x/api/vm.html
const vm = require("vm");
// create an object in heap
const sandboxCtx = {};
// Contextify the sandbox.
vm.createContext(sandboxCtx);
let code = 'var human = 2; let fish = "a big fish :)"';
@0ex-d
0ex-d / short-circuit-clang-style.rs
Created October 10, 2022 21:27
🥹 My top Longest Short-Circuit Evaluation in Javascript and Rust.
// use good 'ol c-language one-liner (rust doesn't have terniary operator 🙂)
let x = if true { if false { true } else { false } } else { if true { false } else { true } };
// could also be
let x = if true { !false } else { !true };
// even further
let x = if true { true } else { false };
@0ex-d
0ex-d / clone_repo.sh
Created October 9, 2022 23:47
bitbucket repo manager shell
#!/bin/bash
# import multiple remote git repositories to local CODE dir
# settings
remoteHost=bitbucket.org
remoteUser=mrbaguvix
remoteDir="~/scm/remote_dir/"
branchName="branch_name"
remoteRepos=$(ssh -l $remoteUser $remoteHost "ls $remoteDir")
@0ex-d
0ex-d / get_bitcoin_address.rs
Created September 28, 2022 21:55
A plugin for validating some selected cryptocurrency wallet address using regular expressions (regex). Note: TDD approach used
#[macro_use]
extern crate lazy_static;
use regex::{Captures, Regex};
// starts with "1" or "3" or "bc1"
// doesn’t contain ambiguous characters
// consists of uppercase or lowercase alphabetic and numeric characters
// except the uppercase letter "O", uppercase letter "I", lowercase letter "l", and the number "0"
// check that the string is 26-35 characters long
@0ex-d
0ex-d / count_data_frequency.rs
Created September 15, 2022 23:36
Get a list of data and count the number of repeating groups and display the most frequent
use std::collections::{BTreeMap, HashMap};
fn main() {
let frequency = [19, 19, 20, 32, 35, 19, 32];
// use hashmap to store k/v pairs
let mut seek_hash: HashMap<i32, u8> = HashMap::new();
let mut seek_hash_sorted: BTreeMap<i32, u8> = BTreeMap::new();
let mut highest_freq_val = 0;
let mut highest_freq_key = 0;