Skip to content

Instantly share code, notes, and snippets.

@roughconsensusandrunningcode
roughconsensusandrunningcode / PasswordGenerator.js
Last active October 27, 2023 08:21
JavaScript - Password generator based on crypto.getRandomValues()
class PasswordGenerator {
#chunksFromString(string, chunkSize) {
const numChunks = Math.floor(string.length / chunkSize);
const chunks = new Array(numChunks);
for (let i=0, o=0; i < numChunks; ++i, o+=chunkSize) {
chunks[i] = string.substr(o, chunkSize);
}
return chunks;
@roughconsensusandrunningcode
roughconsensusandrunningcode / TooManyRequestsObjectResult.cs
Last active May 15, 2023 14:03
C# - An ObjectResult that when executed will produce a Too Many Requests (429) response with an optional Retry-After header.
namespace Microsoft.AspNetCore.Mvc;
/// <summary>
/// An <see cref="ObjectResult"/> that when executed will produce
/// a <see cref="StatusCodes.Status429TooManyRequests"/> response
/// with an optional Retry-After header.
/// </summary>
[DefaultStatusCode(DefaultStatusCode)]
public class TooManyRequestsObjectResult : ObjectResult
{
@roughconsensusandrunningcode
roughconsensusandrunningcode / writeandhash.cs
Last active January 3, 2020 23:11
C# - Create a file and compute its hash at the same time
using System;
using System.IO;
using System.Security.Cryptography;
namespace HashDemo
{
class Program
{
public static void Main (string[] args)
{
@roughconsensusandrunningcode
roughconsensusandrunningcode / errors.csv
Last active May 15, 2023 14:32
Elenco delle stazioni ferroviarie italiane in formato CSV e GeoJSON
Name Id StatusCode
ACQUAMELA S09798 NoContent
AGOGNATE S00075 NoContent
AIELLI S08550 NoContent
ALBAIRATE VERMEZZO S01059 NoContent
ALBERGO S06067 NoContent
ALIFE S09020 NoContent
ALVIGNNO S09023 NoContent
ANCONA STADIO S07114 NoContent
ANDORA S04525 NoContent