This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo sysctl -w vm.max_map_count=262144 | |
sudo apt install apt-transport-https ca-certificates curl software-properties-common | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu `lsb_release -cs` stable" | |
sudo apt update -y | |
sudo apt install docker-ce -y | |
# Docker-compose | |
mkdir -p ~/.docker/cli-plugins/ | |
curl -SL https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function formatFixedPoint(val: bigint, decimals = 18): string { | |
const l = val / 10n ** BigInt(decimals); | |
const r = val % 10n ** BigInt(decimals); | |
if (r === 0n) { | |
return l.toString(); | |
} | |
return `${l}.${r.toString().padStart(decimals, "0").replace(/0*$/, "")}`; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
CallHandler, | |
ExecutionContext, | |
Injectable, | |
NestInterceptor, | |
} from "@nestjs/common"; | |
import { Observable, map } from "rxjs"; | |
export class PickOptions { | |
type?: any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Global, Module } from "@nestjs/common"; | |
import { ConfigService } from "@nestjs/config"; | |
@Global() | |
@Module({ | |
providers: [ | |
{ | |
provide: LockService, | |
inject: [ConfigService], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
etcd-1: | |
image: gcr.io/etcd-development/etcd:v3.3.9 | |
restart: always | |
ports: | |
- 2379 | |
- 2380 | |
volumes: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BroadcastChannel, createLeaderElection } from 'broadcast-channel' | |
import React from 'react' | |
const channels = {} | |
export function useBroadcastLeader(id = 'default') { | |
const [isBroadcastLeader, setIsBroadcastLeader] = React.useState(false) | |
React.useEffect(() => { | |
if (!channels[id]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Get, Inject, Injectable, Module, Scope } from "@nestjs/common"; | |
import { | |
ContextId, ContextIdFactory, ContextIdResolver, ContextIdResolverFn, ContextIdStrategy, | |
HostComponentInfo, ModuleRef, NestFactory, REQUEST | |
} from "@nestjs/core"; | |
import { NestExpressApplication } from "@nestjs/platform-express"; | |
// Context strategy | |
const tenants = new Map<string, ContextId>(); | |
export class TenantContextIdStrategy implements ContextIdStrategy { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh -L 3000:localhost:3000 your-non-root-user@yourserver-ip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.toPersianDigit = function (a) { | |
return this.replace(/\d+/g, function (digit) { | |
var enDigitArr = [], peDigitArr = []; | |
for (var i = 0; i < digit.length; i++) { | |
enDigitArr.push(digit.charCodeAt(i)); | |
} | |
for (var j = 0; j < enDigitArr.length; j++) { | |
peDigitArr.push(String.fromCharCode(enDigitArr[j] + ((!!a && a == true) ? 1584 : 1728))); | |
} | |
return peDigitArr.join(''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const parallel = (...fs) => sequential( | |
() => fs.map(f => f()), | |
Promise.all.bind(Promise)); | |
export const sequential = (f, ...fs) => val => Promise.resolve() | |
.then(() => f(val)) | |
.then(fs.length ? sequential(...fs) : id => id); |
NewerOlder