Skip to content

Instantly share code, notes, and snippets.

View bozdoz's full-sized avatar
☠️
I may be dead

bozdoz bozdoz

☠️
I may be dead
View GitHub Profile
@bozdoz
bozdoz / main.rs
Created December 30, 2024 17:34
aoc 24 1/2
#![allow(unused)]
use std::collections::{ HashMap, HashSet };
#[derive(Debug)]
enum Op {
AND,
XOR,
OR
}
@bozdoz
bozdoz / main.rs
Created December 30, 2024 15:36
aoc 23
#![allow(unused)]
use std::collections::{ HashMap, HashSet };
fn main() {
let networks = "kh-tc
qp-kh
de-cg
ka-co
yn-aq
@bozdoz
bozdoz / README.md
Last active December 26, 2024 07:09
Simple Example of how Deno could be calling NPM scripts

Important

Run with deno run --allow-run=deno main.ts (this allows us to run deno instead of node in scripts, but prevents any other nefarious scripts)

With NPM

npm run start

> [email protected] start
> node evil.js
@bozdoz
bozdoz / main.rs
Created December 11, 2024 20:52
AOC 2024 Day 11
fn main() {
let s = "125 17";
let mut data: Vec<_> = s.split(" ").map(|x| { x.parse::<usize>().unwrap() }).collect();
let mut len = data.len();
// println!("{:?}", data);
for _ in (0..).take(75) {
// println!("len: {len}");
@bozdoz
bozdoz / main.rs
Last active December 4, 2024 17:08
AOC 2024 Day 4 in rust
#![allow(unused)]
fn main() {
let example = "
MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
XMASAMXAMM
XXAMMXXAMA
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bozdoz
bozdoz / getPassword.js
Created June 4, 2024 00:18
Get a password from stdin
const readline = require("node:readline");
const { Writable } = require("node:stream");
const getPassword = (user) =>
new Promise((resolve) => {
const mutableStdout = new Writable({
write: function (chunk, encoding, callback) {
if (!this.muted) process.stdout.write(chunk, encoding);
callback();
},
@bozdoz
bozdoz / draft.js
Last active February 28, 2024 02:48
Node.js Encryption/Decryption Example
const crypto = require("node:crypto");
const { Buffer } = require("node:buffer");
const ALGO = "aes-256-cbc";
// random SECRET stored in memory
const SECRET = crypto.randomBytes(64);
function getKey(salt) {
// In 2023, OWASP recommended to use 600,000 iterations for PBKDF2-HMAC-SHA256 and 210,000 for PBKDF2-HMAC-SHA512.[6]
return crypto.pbkdf2Sync(SECRET, salt, 210_000, 32, "sha512");
@bozdoz
bozdoz / day-01.rs
Created November 28, 2023 05:14
2019 Advent of Code
// to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2.
use std::fs;
use std::io::Error;
fn main() -> Result<(), Error> {
let contents = fs::read_to_string("./src/input.txt");
let data = match contents {
Ok(c) => c,
@bozdoz
bozdoz / useWhyDidYouUpdate.ts
Last active July 5, 2023 20:15
useWhyDidYouUpdate
import { useRef, useEffect } from 'react';
type IProps = Record<string, unknown>;
const useWhyDidYouUpdate = (componentName: any, props: any) => {
const oldPropsRef = useRef<IProps>({});
useEffect(() => {
if (oldPropsRef.current) {
// iterate through all the key of the old and new props