Skip to content

Instantly share code, notes, and snippets.

View baakeydow's full-sized avatar
🛠️
🦀 => 🚀

Baakey baakeydow

🛠️
🦀 => 🚀
View GitHub Profile
@baakeydow
baakeydow / ad-hoc_multithreading.rs
Created October 24, 2022 18:49
#rust ad hoc multithreading example
//! ad hoc multithreading example
use std::{
sync::{Arc, Mutex},
thread,
};
/// Task to be executed
#[derive(Default)]
pub struct TaskSpawner<T> {
id: u32,
//! src: https://github.com/mbrubeck/by_address/blob/master/src/lib.rs
//! Wrapper type for by-address hashing and comparison.
use std::ops::Deref;
#[derive(Copy, Clone, Debug, Default)]
/// Wrapper for pointer types that implements by-address comparison.
pub struct ByAddress<T>(pub T)
where
T: ?Sized + Deref;
@baakeydow
baakeydow / multiple_owners.rs
Created October 18, 2022 10:44
#rust multiple owners with Rc + RefCell
fn multiple_owners() {
use std::rc::Rc;
use std::cell::RefCell;
let value = Rc::new(RefCell::new(5));
let a = Rc::clone(&value);
let b = Rc::clone(&value);
*a.borrow_mut() += 1;
*b.borrow_mut() += 1;
assert_eq!(*value.borrow(), 7);
}
@baakeydow
baakeydow / standardDeviation.ts
Last active May 21, 2021 00:04
stddev with typescript
const average = (arr: number[]): number => arr.reduce((p, c) => p + c, 0) / arr.length;
const standardDeviation = (values: number[]) => {
const avg = average(values);
const squareDiffs = values.map((value) => {
let diff = value - avg;
let sqrDiff = diff * diff;
return sqrDiff;
});
@baakeydow
baakeydow / DockerEasyPublish.sh
Created May 18, 2021 13:13
Publish your docker image tag the easy way
#!/usr/bin/env bash
docker build -t app_x . && \
docker tag app_x:latest user_x/app_x:latest && \
docker push user_x/app_x:latest && \
echo 'new image successfully published to user_x as app_x!'
@baakeydow
baakeydow / paginateResults.ts
Created May 16, 2021 00:33
simple recursive function to paginate api results
import axios from 'axios';
const getAllResults = async (limit: number, offset: number, data: any[]): Promise<any[]> => {
const response = await axios.get('https://awesome.api.com/data/v1/get/money', {
timeout: 5 * 60 * 1000,
params: {
fields: "",
limit,
offset
},
@baakeydow
baakeydow / ntfsToOsx.sh
Created May 15, 2021 23:58
mount ntfs to osx
#!/bin/bash
brew install ntfs-3g
diskutil list // (it finds disk2s1)
sudo mkdir /Volumes/NTFS
sudo /usr/local/bin/ntfs-3g /dev/disk2s1 /Volumes/NTFS -olocal -oallow_other
@baakeydow
baakeydow / downloadFile.js
Created May 15, 2021 23:56
Simple #javascript function to download a file with #NodeJS
const download = (url, dest) => {
return new Promise((resolve, reject) => {
http.get(url, (res) => {
if (res.statusCode !== 200) {
const err = new Error('File couldn\'t be retrieved');
err.status = res.statusCode;
return reject(err);
}
const chunks = [];
res.setEncoding('binary');
@baakeydow
baakeydow / GoAccessCaddyLogsReport.sh
Last active July 12, 2021 03:15
Inspect Caddy logs with GoAccess
#!/usr/bin/env bash
sudo goaccess /var/log/caddy/logs/access.log \
--html-pref='{"theme":"darkBlue","perPage":50,"layout":"vertical","showTables":true,"visitors":{"plot":{"chartType":"area-spline"}}}' \
-o /full/path/to/new/report.html \
--with-mouse \
--hl-header \
--with-output-resolver \
--ignore-crawlers \
--all-static-files \
@baakeydow
baakeydow / mp4ToGif.ts
Last active May 15, 2021 23:30
Convert mp4 to gif
import express, { Request, Response, NextFunction } from 'express';
import temp from 'temp';
import Busboy from 'busboy';
import ffmpeg from 'fluent-ffmpeg';
import pathToFfmpeg from 'ffmpeg-static';
ffmpeg.setFfmpegPath(pathToFfmpeg);
const router = express.Router();
router.post('/mp4-to-gif', (req: Request, res: Response, next: NextFunction) => {