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
function getSafe(fn) { | |
try { | |
return fn(); | |
} catch (e) { | |
return undefined; | |
} | |
} | |
function allTrue(conditions: boolean[]): boolean { | |
return conditions.every(Boolean); |
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
const read = async (filePath: string) => { | |
return new Promise((resolve, reject) => { | |
fs.readFile(filePath, 'utf8', (err: any, data: string) => { | |
if (err) reject(err) | |
resolve(data) | |
}) | |
}) | |
} | |
const write = (filePath: string, fileName: string, fileExtension: string, content: 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
async function encryptData(data, key) { | |
const encodedData = new TextEncoder().encode(data); | |
const iv = crypto.getRandomValues(new Uint8Array(12)); // Initialization vector | |
const encryptedData = await crypto.subtle.encrypt( | |
{ | |
name: "AES-GCM", | |
iv: iv | |
}, | |
key, | |
encodedData |
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
function getEnvVariable(key: string): string { | |
if (key === undefined) { | |
throw Error(`"${key}" is undefined`); | |
} | |
const value = process.env[key]; | |
if (!value) { | |
throw Error( | |
`Environment variable "${key}" does not exist on process.env` |
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
Show hidden characters
{ | |
"Component": { | |
"prefix": "mkComponent", | |
"body": [ | |
"import React, { type ReactNode } from 'react';", | |
"", | |
"interface ${TM_FILENAME_BASE/(.*)\\..+$/$1/}Props {", | |
" children: ReactNode;", | |
"}", | |
"", |
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
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. | |
# Initialization code that may require console input (password prompts, [y/n] | |
# confirmations, etc.) must go above this block; everything else may go below. | |
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then | |
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" | |
fi | |
# If you come from bash you might have to change your $PATH. | |
# export PATH=$HOME/bin:/usr/local/bin:$PATH |
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
<span> | |
{new Intl.NumberFormat("en-US", { | |
style: "currency", | |
currency: "USD", | |
signDisplay: "never", | |
}).format(option.price - selectedOption.price)} | |
</span> |
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 { Slot, type AsChildProps } from "./slot.tsx" | |
type ButtonProps = AsChildProps< | |
React.ButtonHTMLAttributes<HTMLButtonElement> | |
> & { | |
style?: React.CSSProperties | |
className?: string | |
} | |
function Button({ asChild, ...props }: ButtonProps) { |
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
function getUniqueId(prefix: string, length: number = 8): string { | |
let result = `${prefix}-`; | |
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
const charactersLength = characters.length; | |
let counter = 0; | |
while (counter < length) { | |
result = `${result}${characters.charAt(Math.floor(Math.random() * charactersLength))}`; |
NewerOlder