Skip to content

Instantly share code, notes, and snippets.

View ali-master's full-sized avatar
🎯
Focusing on Something new!

Ali Torki ali-master

🎯
Focusing on Something new!
View GitHub Profile
@getify
getify / 1-CalendarItem.js
Last active March 21, 2024 09:11
an illustration (non-trivial example) of many newer JS class features
// abstract class, not intended to be instantiated directly
class CalendarItem {
static #UNSET = Symbol("unset")
static #isUnset(v) {
return v === this.#UNSET;
}
static {
for (let [idx,msg] of [
"ID is already set.",
"ID is unset.",
@getify
getify / 1.md
Last active March 2, 2023 21:24
In defense of using blocks to create localized scope for variables... (part 1 of 2)
@kpirliyev
kpirliyev / postgresql_13_replication.md
Last active March 1, 2024 11:07
PostgreSQL 13 Master-Slave Streaming Replication

PostgreSQL 13 Master-Standby Streaming Replication

PostgreSQL has various types of replication available and it could be a little bit confusing to figure out what has to be done to just configure a simple master-standby replicated database setup. Digging my way through documentation I decided to write my own little guide on how to setup simple replication in PostgreSQL 13.

How it works

Streaming replication works by streaming the contents of WAL (Write-Ahead Logging) file from one server to another. Each transaction is first written into the WAL file, so essentially every change on the primary server will be replicated on the standby server. Standby server could be used for read-only operations, but can't be written to. Ofcourse, transferring data over the network takes time and there is a small lag before data written to one server becomes available on the other. To guarrantee data consistency on both servers at the time of read operation we can enable synchronous replication mode. This way, datab

@ErfanMirzapour
ErfanMirzapour / TailwindCSS-CheatSheet.md
Last active January 23, 2024 16:13
Mapping CSS properties to equivalent tailwind classes
@sindresorhus
sindresorhus / esm-package.md
Last active April 26, 2024 03:53
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
function preprocessImage(canvas) {
const ctx = canvas.getContext('2d');
const image = ctx.getImageData(0,0,canvas.width, canvas.height);
blurARGB(image.data, canvas, 1);
dilate(image.data, canvas);
invertColors(image.data);
thresholdFilter(image.data, 0.4);
return image;
}
@mstorus
mstorus / cryptoSign.js
Created February 27, 2021 07:03
use browser subtle crypto to sign some text with hmac-sha1
async function cryptoSign(message) {
const key = await window.crypto.subtle.generateKey(
{
name: "HMAC",
hash: { name: "SHA-512" },
},
true,
["sign", "verify"]
);
const encodedText = new TextEncoder().encode(message);
@MBrassey
MBrassey / Match_Addresses.md
Last active April 11, 2024 12:44
Match Crypto Wallet Addresses (REGEX)

Match Crypto Wallet Addresses using Regular Expressions

The following regular expressions are crafted to match some commonly used cryptocurrency wallet address types. This document details the Regex components and pattern tests to match Ethereum, Bitcoin, Dash and Monero addresses.

🌀 Click the images below to view the tested patterns.

Ethereum (ETH)

/^0x[a-fA-F0-9]{40}$/g

@jengel3
jengel3 / authentication-1.controller.ts
Last active April 23, 2024 19:26
NestJS - Implementing Access & Refresh Token Authentication
// app/modules/authentication/authentication.controller.ts
import { Body, Controller, Post } from '@nestjs/common'
import { RegisterRequest } from './requests'
import { User } from '../../modules/user'
import { UsersService } from '../users/users.service'
@eunsukimme
eunsukimme / Dockerfile.app
Last active March 7, 2024 09:29
Configuration Files for Logging System wigh Docker-elk, Filebeat and Node.js
FROM node:12
WORKDIR /app
COPY ./package*.json ./
RUN npm install
ENV PORT=4000
COPY . .
CMD ["npm","run","start"]