Skip to content

Instantly share code, notes, and snippets.

@max-lt
max-lt / blockchain.js
Last active May 16, 2018 09:22
Simple blockchain
function Blockchain() {
const blocks = this.blocks = []
const getBlockId = (i) => blocks[i] && blocks[i].id || '00000000'
function hash(str) {
const hash = Array(8).fill(0);
for (let i = 0; i < str.length; i++)
hash[i % 8] ^= str.charCodeAt(i)
return hash.map((e) => e % 10).join('')
# change all .js files to .ts
find . -name '*.js' -exec sh -c 'mv "$0" "${0%.js}.ts"' {} \;
#!/usr/bin/env bash
set -e
if [ -z "$1" ]
then
echo "Missing destination file parameter."
echo "Usage: $0 path/to/dest"
echo "Example: $0 /srv/registry/security/htpasswd"
exit 1;
@max-lt
max-lt / ps1.sh
Last active October 4, 2018 11:07
Long lines shortening in Bash PS1 customized prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
parse_path() {
if [ / = $PWD ]; then
echo "/";
return;
fi
import 'reflect-metadata';
interface Type<T> {
new(...args: any[]): T;
}
export const Injector = new class extends Map {
resolve<T>(target: Type<T>): T {
let tokens = Reflect.getMetadata('design:paramtypes', target) || [];
@max-lt
max-lt / cache.decorator.spec.ts
Created July 31, 2019 21:50
Cache decorator typescript
import { Cache } from './cache.decorator';
class Test {
seed;
constructor(seed?) {
this.seed = seed || Math.random();
}
@Cache()
@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.

#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='+ '
/**
* @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']]],
@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/