Skip to content

Instantly share code, notes, and snippets.

@max-lt
max-lt / infra.md
Last active May 22, 2024 08:20
Reflexions infra

Serveurs

Dimentionnement serveur: Actuel: Intel Xeon-D 1521 - 4c/8t - 2.4 GHz/2.7 GHz | 16 Go ECC 2133 MHz | 4×4 To HDD SATA + 1×500 Go SSD NVMe | 500Mbps in / 100Mbps out ~56e/mo

Necessaire:

  • ~50Go pour le moment (sync < 500Mo * 2 (cdn) = 1Go), de toute facon il faudra rediregier le resultat de la synchro
@max-lt
max-lt / random.md
Created February 12, 2024 12:03 — forked from joepie91/random.md
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

@max-lt
max-lt / analytics.service.ts
Last active December 15, 2023 08:45
Angular + Piano Analytics
import { Injectable } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { filter, map } from 'rxjs/operators';
import { logger } from '~/logger';
import { Config } from '~/config';
const log = logger.getLogger('AnalyticsService');
// Global variables used by piano analytics
@max-lt
max-lt / pagination.html
Created December 1, 2023 10:32
Angular pagination
<!-- Pagination -->
<ul class="pagination">
<li class="page-item">
<button class="page-link" (click)="goPrevious()" [disabled]="0 === current">Previous</button>
</li>
<li class="page-item" *ngFor="let n of nums;">
<button class="page-link" (click)="goPage(n)" [disabled]="n - 1 === current || n === '...'">{{ n }}</button>
</li>
<li class="page-item">
@max-lt
max-lt / tooltip.directive.ts
Last active December 30, 2023 12:39
Angular tooltip
import { Directive, ElementRef, HostListener, Input, OnInit, Renderer2 as Renderer } from '@angular/core';
@Directive({ selector: '[tooltip]' })
export class TooltipDirective implements OnInit {
private tooltip!: HTMLElement;
@Input('tooltip')
content!: string;
@Input()
@max-lt
max-lt / app.component.html
Last active November 25, 2023 15:00
Angular + Tailwind quickstart
<ng-template #logo>
<a href="#" class="flex items-center">
<img src="/favicon.ico" class="mr-3 h-8" alt="AppName Logo" />
<span class="self-center text-xl font-semibold whitespace-nowrap dark:text-white">AppName</span>
</a>
</ng-template>
<ng-template #lorem_ipsum>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
@max-lt
max-lt / github-signature.ts
Last active June 2, 2023 17:22
Signatures with browser crypto APIs
/// <reference lib="webworker" />
/// <reference lib="es2017" />
declare const env: {
GITHUB_SECRET: string;
};
if (!env.GITHUB_SECRET) {
throw new Error("Invalid or missing GITHUB_SECRET");
}
import { AbstractControl, ValidationErrors } from '@angular/forms';
const luhnArr = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9];
// https://portal.hardis-group.com/pages/viewpage.action?pageId=120357227
export function checkSIRET(control: AbstractControl): ValidationErrors {
if (!control.value) {
return null;
}
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"trailingComma": "none",
"endOfLine": "lf",
"arrowParens": "always",
"printWidth": 120
}