Skip to content

Instantly share code, notes, and snippets.

@max-lt
max-lt / router-data.service.ts
Last active November 22, 2022 21:55
router-data.service.ts
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Router, ActivatedRoute, Event, NavigationEnd } from '@angular/router';
import { filter, map, mergeMap, shareReplay } from 'rxjs/operators';
import { IRouteData } from '~/app/interfaces/route-data';
@Injectable({ providedIn: 'root' })
export class RouterDataService {
public readonly data$: Observable<IRouteData>;
import { Observable, merge, mergeMap, shareReplay } from 'rxjs';
interface ICacheElement<T> {
res$: Observable<T>;
exp: number;
}
const DEFAULT_KEY = Symbol('default_cache_key');
type CacheKey = string | number | symbol;
import { HttpClient } from '@angular/common/http';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
import { first, Observable } from 'rxjs';
export abstract class CRUDService<T, C, U extends { id: string }> implements Resolve<T> {
constructor(protected http: HttpClient, protected base: string) {
console.log(`Instantiating ${this.base.slice(0, -1)} service`);
}
public findAll(): Observable<T[]> {
@max-lt
max-lt / logger.ts
Last active November 17, 2022 12:08
enum LEVELS {
trace,
debug,
info,
warn,
error
}
type Levels = keyof typeof LEVELS;
addEventListener('scheduled', event => {
event.waitUntil(
handleSchedule(event.scheduledTime)
)
})
function sendMessage(chat_id, text, options = { }) {
return fetch(`https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`, {
method: "POST",
headers: { 'Content-Type': 'application/json' },
@max-lt
max-lt / telegram-bot.js
Created December 22, 2021 14:32
Basic telegram bot
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
})
function sendMessage(chat_id, text) {
return fetch(`https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`, {
@max-lt
max-lt / arch-setup.md
Last active February 22, 2021 19:46
Archlinux quick setup for scaleway

Full system update

pacman-static

Scaleway images may not be able to upgrade due to changes in the packages format, you will need to install pacman-static (resources here and here)

cd /tmp/
/**
* @type [[[number], [[string]]]]
*/
const tests = [
[[0, 1, 0], [['tea', 'aba', 'obj'], ['eat', 'aaa', 'job']]],
[[3], [['zzz'], ['aaa']]],
[[0], [['zzx'], ['xzz']]],
[[1, 1], [['zzx', 'xza'], ['xza', 'zzx']]],
[[0, 1], [['azx', 'xza'], ['xza', 'zzx']]],
[[-1, 0], [['azzz', 'xza'], ['xza', 'zax']]],
#Complete la ligne depuis l'historique plutot que d'ecraser la frappe en cours
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
PS1="$(if [[ ${EUID} == 0 ]];
then echo '\[\033[01;31m\]\u\[\033[01;0m\]@\h';
else echo '\[\033[01;33m\]\u\[\033[01;0m\]@\h'; fi)\[\033[01;36m\] \w/ \[\033[01;0m\]\\$ \[\033[01;0m\]"
PS2='> '
PS3='> '
PS4='+ '
@max-lt
max-lt / ca.md
Created October 15, 2019 09:56 — forked from soarez/ca.md
How to setup your own CA with OpenSSL

How to setup your own CA with OpenSSL

For educational reasons I've decided to create my own CA. Here is what I learned.

First things first

Lets get some context first.