Skip to content

Instantly share code, notes, and snippets.

@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()
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 / 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
#!/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;
# change all .js files to .ts
find . -name '*.js' -exec sh -c 'mv "$0" "${0%.js}.ts"' {} \;
@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('')
@max-lt
max-lt / bash.bashrc
Created April 7, 2018 14:07
Bash completion for aliases
# autocompletion for d and dokcer (docker)
source /usr/share/bash-completion/completions/docker
complete -F _docker d dokcer
@max-lt
max-lt / md-renderer.conf
Last active December 25, 2024 23:37
Nginx config to render markdown files (client side)
location /__special {
internal;
allow all;
root /usr/share/nginx/html/__special;
}
location = /__md_file {
internal;
allow all;
@max-lt
max-lt / package-version.sh
Created December 17, 2017 13:57
Get package.json version shell script
#!/bin/sh
VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[", ]//g')
echo "Version is >${VERSION}<"
@max-lt
max-lt / index.js
Created November 10, 2017 21:04
minimal chat
const net = require('net');
const isServer = process.argv[2] == 'server';
const port = process.argv[3]; // server port
const display = (data) => console.log('> ' + data.toString().trim());
let send = null;
if (isServer) {