Skip to content

Instantly share code, notes, and snippets.

@Anmol-Baranwal
Anmol-Baranwal / Bug_Report.yml
Created October 3, 2022 15:13
Basic Issue Templates in yml format
name: "🐛 Bug Report"
description: Create a new ticket for a bug.
title: "🐛 [BUG] - <title>"
labels: [
"bug"
]
body:
- type: textarea
id: description
attributes:
@felixhaeberle
felixhaeberle / timeAgo.ts
Last active May 10, 2024 13:43
TypeScript: Get time distance as human readable string
// takes either a unix time number, string or a Date object and returns time string
export const timeAgo = (time: number | string | Date) => {
switch (typeof time) {
case "number":
break;
case "string":
time = +new Date(time);
break;
case "object":
const DefaultRenderAnimationOutput = ({name, count}) => {
return (
<>
<span className="RenderAnimation-name">{name} </span>
<span className="RenderAnimation-count">{count}</span>
</>
);
};
function useRenderAnimation(
import { mkdirSync, readFileSync, writeFileSync } from 'fs';
import glob from 'glob';
import path from 'path';
const globAsync = (pattern: string): Promise<string[]> =>
new Promise<string[]>((res, rej) =>
glob(pattern, (err, matches) => (err ? rej(err) : res(matches))),
);
const paths = await globAsync('src/**/*.ts');
@joemaffei
joemaffei / form-data.ts
Last active June 21, 2024 16:16
Convert object to FormData
/**
* I started building this, then came across a more robust solution:
* {@link https://github.com/therealparmesh/object-to-formdata}
*/
import { isPlainObject } from "is-plain-object";
type Value = string | Blob | number | boolean | null | undefined | Date;
function convert<T extends Value>(value: T): string | Blob {
import pino from "pino";
const logger = pino({
serializers: {
req(req: any) {
return {
method: req.method,
headers: req.headers,
ip: req.ip,
url: req.url,
export {jsx, jsx as jsxs, jsx as Fragment}
type DOMElement = Element;
declare global {
namespace JSX {
type Element = DOMElement;
type ChildElement = string | number | boolean | symbol | bigint | null | undefined | { toString(): string } | (() => ChildElements) | Node;
type ChildElements = ChildElement | Iterable<ChildElement>;
interface HTMLAttributes<T> {
//const pinoInspector = require("pino-inspector");
const path = require("path");
const fastify = require("fastify")({
//logger: { prettyPrint: true, level: "debug", prettifier: pinoInspector },
ajv: {
plugins: [[require("ajv-keywords"), ["transform"]]],
},
});
fastify.register(require("@fastify/multipart"));
@arnoldc
arnoldc / foo.tsx
Last active December 3, 2023 01:10
[React] Hooks
// ------------ useState => dealing with multiple object in state
const [person ,setPerson] = useState(() => initialPerson);
setPerson((person) => ({
...person,
firstName: e.target.value
}));
@sangwin
sangwin / copyToClipboard.js
Created July 18, 2022 09:10
Copy a text to clipboard
const copyToClipboard = (text) => navigator.clipboard?.writeText && navigator.clipboard.writeText(text);
copyToClipboard("Hello World!");