This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! ad hoc multithreading example | |
use std::{ | |
sync::{Arc, Mutex}, | |
thread, | |
}; | |
/// Task to be executed | |
#[derive(Default)] | |
pub struct TaskSpawner<T> { | |
id: u32, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => { |