Skip to content

Instantly share code, notes, and snippets.

@arekbartnik
arekbartnik / README.MD
Created September 19, 2025 02:05 — forked from Mosharush/README.MD
React Hook - Server-Sent Events (SSE)

Server-Sent Events (SSE) are commonly used in real-time applications where the server needs to push updates to the client.

Here are a few use cases:

  1. Real-time notifications: SSE can be used to push notifications to the client in real-time. For example, in a social media application, the server can push notifications about new posts, likes, comments, etc.
  2. Live news updates: In a news application, the server can push live news updates to the client.
  3. Real-time analytics: In an analytics dashboard, the server can push real-time data updates to the client.
  4. Chat applications: In a chat application, the server can push new messages to the client in real-time.
  5. Online multiplayer games: In an online multiplayer game, the server can push game state updates to the client in real-time.
  6. Stock price updates: In a stock trading application, the server can push real-time stock price updates to the client.
export function rounded(number: number, decimals: number = 2): number {
return Math.round(number * Math.pow(10, decimals)) / Math.pow(10, decimals);
}
@arekbartnik
arekbartnik / create_pr.sh
Created September 14, 2024 13:31 — forked from slavingia/create_pr.sh
Create a (draft) pull request using GitHub CLI
#!/bin/bash
# Create a (draft) pull request using GitHub CLI.
# It assigns the PR to the current user, fills in the title from the first commit,
# and uses the PR template file for the description.
set -euo pipefail
# Colors for output
RED='\033[0;31m'
import { FileWithPath } from "react-dropzone-esm";
function hasFileWithName(set: Set<FileWithPath>, name: string) {
return [...set].some((file) => file.name === name);
}
export function combineUniqueFileSets<T extends FileWithPath>(set1: Set<T>, set2: Set<T>): Set<T> {
const combinedSet = new Set<T>();
// Add all elements from set1 to the combinedSet
@arekbartnik
arekbartnik / gist:75af8f2d57a2ecccf35aa762158adf7e
Last active September 25, 2023 14:03
Setup Multiple SSH Keys for Multiple GitHub Accounts
@arekbartnik
arekbartnik / useMagicalMutation.ts
Created June 27, 2023 13:34 — forked from kitze/useMagicalMutation.ts
magical mutation for blitz
import { useToast } from "@chakra-ui/react";
import { exists } from "app/core/utils/js-utils";
import { QueryFn, useMutation } from "blitz";
import { MutationOptions } from "react-query";
type ShowLoginOnFailFn = (s: any) => boolean;
type CustomOptions = {
errorMessage?: string;
showLoginOnFail?: boolean | ShowLoginOnFailFn;
@arekbartnik
arekbartnik / tailwind-plugin-patcher.py
Created January 24, 2023 19:02 — forked from liautaud/tailwind-plugin-patcher.py
Small Python script to patch the IntelliJ TailwindCSS plugin.
import re
from zipfile import ZipFile, Path
"""
TailwindCSS plugin patcher for IntelliJ IDEA
--------------------------------------------
1. Download the latest ZIP of the plugin compatible with your version of IntelliJ here:
https://plugins.jetbrains.com/plugin/15321-tailwind-css/versions
2. Fill `CLASS_ATTRIBUTES` to specify which XML attributes can contain Tailwind classes.
@arekbartnik
arekbartnik / InternalLink.tsx
Created July 19, 2022 07:42 — forked from tomhicks/InternalLink.tsx
Strongly-typed NextJS internal links
const formatPrice = (price: number | undefined) => {
if (!price) return ""
return (
price
.toLocaleString("en-US", { minimumFractionDigits: 2 })
.replace(/\D00(?=\D*$)/, "")
.replace(",", " ")
.replace(".", ",") + " zł"
)
}
@arekbartnik
arekbartnik / encrypt.js
Created April 14, 2021 12:02 — forked from shahinghasemi/encrypt.js
FullStack AES-GCM Encryption Decryption using NodeJS and Browser standard libraries (native crypto API)
//----------------------------------------------------------------
// ------------------- ServerSide(NODE.JS) -------------------
//----------------------------------------------------------------
function encrypt(message){
const KEY = crypto.randomBytes(32)
const IV = crypto.randomBytes(16)
const ALGORITHM = 'aes-256-gcm';
const cipher = crypto.createCipheriv(ALGORITHM, KEY, IV);
let encrypted = cipher.update(message, 'utf8', 'hex');