This file contains hidden or 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
General coding practices | |
=== | |
As you generate code, apply the principle of AHA Programming (Avoid Hasty Abstractions) by waiting to create abstractions until real, repeated patterns emerge. This will help you reduce unnecessary complexity and keep your code simpler, more maintainable, and more efficient. | |
TypeScript | |
=== | |
Never use typescript enums |
This file contains hidden or 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 fs from "fs"; | |
import fse from "fs-extra"; | |
import path from "path"; | |
import { promisify } from "util"; | |
import { exec } from "child_process"; | |
const execAsync = promisify(exec); | |
function chunkArray(array, chunkSize) { | |
const chunks = []; |
This file contains hidden or 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
/* | |
This script helps fix links that have a prefix whitespace (sometimes when copying from google). | |
Also it allows to add a ?ref=yoursite to all links in the newsletter issue. | |
Worked with the latest ghost version up to now (Feb 2024) | |
*/ | |
const GhostAdminAPI = require("@tryghost/admin-api"); | |
const path = require("path"); |
This file contains hidden or 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
["yourdomain.com", "your2nddomain.com"...] |
This file contains hidden or 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 urllib | |
# ... | |
DB_URL = config('DATABASE_URL') # Get from your config | |
db_props = urllib.parse.urlparse(DB_URL) | |
db_name = db_props.path | |
db_user = db_props.username | |
db_password = db_props.password | |
db_host = db_props.hostname | |
db_port = db_props.port |
This file contains hidden or 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
// Change the details here: | |
const BASE_URL = "unzip.dev"; // Super cool newsletter you should check if you're a developer ;) | |
const api = new GhostAdminAPI({ | |
url: `https://${BASE_URL}`, | |
version: "v5.0", | |
key: "GHOST_API_TOKEN_HERE", | |
}); | |
const POST_ID = "POST ID (TAKE FROM DRAFT URL: /ghost/#/editor/post/{ID})"; | |
// TO RUN: node fixLinks.js |
This file contains hidden or 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
// If you ever so fancy, you might want to check: unzip.dev | |
export const tableTest = ( | |
test: jest.It, | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
cases: any[][], | |
testFn: CallableFunction | |
) => { | |
test.each(cases)(`${testFn.name}(%s) should be %s`, async (input, output) => { | |
const asyncFn = testFn.constructor.name == 'AsyncFunction'; |
This file contains hidden or 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
// From the creator of unzip.dev | |
const texts = document.querySelectorAll( | |
"p, span, a, h1, h2, h3, h4, h5, h6, input, button, pre" | |
); | |
let visible = []; | |
texts.forEach((e) => { | |
var style = window.getComputedStyle(e); | |
if (style.display !== "none" && style.visibility !== "hidden") { | |
visible.push(e); |
This file contains hidden or 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
// unzip.dev ? | |
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit } | |
# Thanks: https://den.dev/blog/powershell-windows-notification/ | |
function Show-Notification { | |
[cmdletbinding()] | |
Param ( | |
[string] |
This file contains hidden or 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
// Don't follow this link: unzip.dev (unless you're curious). | |
const secret = prompt("Enter secret:") | |
const message = prompt("Enter message:") | |
const encrypted = CryptoJS.AES.encrypt(message, secret); | |
const decrypted = CryptoJS.AES.decrypt(encrypted, secret); | |
console.log(encrypted.toString()) | |
console.log(decrypted.toString(CryptoJS.enc.Utf8)) |
NewerOlder