Skip to content

Instantly share code, notes, and snippets.

View kitihounel's full-sized avatar
🎯
Focusing

kitihounel

🎯
Focusing
View GitHub Profile
@kitihounel
kitihounel / json_minify.py
Last active March 23, 2023 18:52 — forked from KinoAR/json_minify.py
A JSON minify script written in Python.
#!/usr/bin/env python3
"""JSON minifier"""
from json import loads, dumps
from sys import argv
from pathlib import Path
def minify(filename):
content = ''
with open(filename, 'r', 1) as input:
import { ArgumentMetadata, BadRequestException, Injectable, PipeTransform } from '@nestjs/common';
import { isISO8601 } from 'class-validator'
@Injectable()
export class ParseDatePipe implements PipeTransform {
transform(value: any, metadata: ArgumentMetadata): Date {
if (typeof value !== 'string' || !isISO8601(value, { strict: true })) {
throw new BadRequestException()
}
import { BadRequestException, Injectable, PipeTransform } from '@nestjs/common'
@Injectable()
export class ParsePositiveIntPipe implements PipeTransform<any, number | undefined | null> {
transform(value) {
if (value === null || value === undefined) {
return value
}
const n = parseInt(value)
import { ArgumentMetadata, BadRequestException, Injectable, PipeTransform } from '@nestjs/common'
import { isUUID } from 'class-validator'
@Injectable()
export class ParseUuidListPipe implements PipeTransform {
transform(value: any, metadata: ArgumentMetadata): string[] {
if (typeof value !== 'string') {
throw new BadRequestException()
}
@kitihounel
kitihounel / genpw.js
Created July 15, 2024 20:04
Funny little NodeJS script to generate passwords
/**
* This is a small program used to generate passwords given an alphabet and a target length.
*
* A bit of math and programming.
* We have an alphabet of size A and we want a password of length P.
* We need to generate an integer bound by (A^P) and convert it to base A using the standard base
* conversion algorithm with our alphabet symbols as the digits.
*
* (A^P) is our upper bound because (A^P) has P+1 digits in base A and we need P digits (symbols).
* For example, in base 10, 10^2 = 100 has 3 digits. In base 2, 16 = 2^4 = 10000 has 5 symbols, etc.