Skip to content

Instantly share code, notes, and snippets.

@tonitrnel
tonitrnel / to_base64.rs
Created January 20, 2024 11:43
Base64 Encode
const S_BASE_64: [char; 64] = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4',
'5', '6', '7', '8', '9', '+', '/',
];
fn to_base64(bytes: &[u8]) -> String {
let mut dst = String::new();
let mut padding = 0;
type PipeCurrying<T> = <F extends ((previousValue: T) => unknown) | undefined>(value?: F) => undefined extends F ? T : PipeCurrying<F extends (value: T) => infer R ? R : unknown>
/**
* Pipe function
* @example pipe(123)() // 123
* @example pipe(123)(v => v + 456)() // 579
* @example pipe({a: 3})(v => v.a)(v => v * 15)(v => v.toString(16))(v => '0x' + v)() // 0x2d
*/
function pipe<T>(initialValue: T): PipeCurrying<T> {
return ((value?: (previousValue: T) => unknown) => {
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@tonitrnel
tonitrnel / webstorm-regex-replace.md
Last active April 21, 2020 16:01
webstorm-regex-replace

WebStorm Regex replace

simple match stylus

MatchRegex: ^(?<tab>\s+)(?<property>[\w-]+):?\s+(?<value>.+)$ ReplaceValue: $1$2: $3;

stylus variable to css variable

MatchRegex: \$([\w-]+) ReplaceValue: var(--$1)

@tonitrnel
tonitrnel / clear-screen.ts
Created April 1, 2020 04:53
NodeJS clear PowerShell terminal screen
import readline from 'readline'
for (let i = 0; i < process.stdout.rows; i++) {
readline.cursorTo(process.stdout, 0, i)
readline.clearLine(process.stdout, 0)
}
readline.cursorTo(process.stdout, 0, 0)
process.stdout.write('\x1b[3J')