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
/** | |
* 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. |
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 { 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() | |
} |
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 { 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) |
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 { 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() | |
} |
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 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: |