Skip to content

Instantly share code, notes, and snippets.

{
"name": "our-example-backend",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
@LearnWebCode
LearnWebCode / functions.php
Created January 31, 2025 19:44
WordPress functions to fetch external JSON (and store in transient + option backup) and also functions to setup programmatic URL patterns and use custom template files for said URLs
function get_cached_external_json($url) {
$transient_key = 'our_fetched_json_' . md5($url);
$option_key = 'our_fetched_json_backup_' . md5($url);
$cached_data = get_transient($transient_key);
if (false !== $cached_data) {
return $cached_data;
}
name: Publish Website
on:
push:
branches:
- main
jobs:
web-deploy:
@LearnWebCode
LearnWebCode / settings.json
Created December 10, 2024 21:08
My VS Code settings.json as of December 2024
{
"apc.sidebar.titlebar": {
"height": 8,
"fontSize": 0.000000000000000001
},
"apc.electron": {
"titleBarStyle": "hidden",
"frame": false
},
//"window.titleBarStyle": "native",
@LearnWebCode
LearnWebCode / script.js
Created October 1, 2024 19:00
Convert all .jpg and .jpeg files in the current directory to webp instead using the sharp package from NPM
const sharp = require("sharp")
const fs = require("fs").promises
async function start() {
// create the converted-images folder if it does not exist yet
fs.mkdir("./converted-images", { recursive: true })
// create array of all files in current directory
const files = await fs.readdir("./")
@LearnWebCode
LearnWebCode / db.js
Created August 28, 2024 18:11
MongoDB integration with Next.js 14
import { MongoClient } from "mongodb"
let client
let clientPromise
if (!process.env.CONNECTIONSTRING) {
throw new Error("Please add your MongoDB URI to the .env file")
}
const uri = process.env.CONNECTIONSTRING
@LearnWebCode
LearnWebCode / f.sh
Last active June 11, 2024 04:19
My fzf first draft
# You need to give this file permission to execute by doing the following...
# chmod +x f.sh
# Add an alias named f to your .zshrc file like this:
# alias f="/Users/brad/Documents/shell-scripts/f.sh"
code "$(find ~/Documents ~/Desktop ~/Sites ~/Local\ Sites -type d \( -name "node_modules" -o -name ".next" -o -name ".git" -o -name "vendor" -o -name "wp-includes" -o -name "wp-admin" \) -prune -o -type d | fzf)"
# todo someday
# currently it only searches for folders, but it would be nice if I could search for zshrc or specific files, but I'm not sure if that will include too many files and be slow...
@LearnWebCode
LearnWebCode / settings.json
Created March 4, 2024 02:16
My 2024 VS Code Settings As of March
{
"debug.javascript.codelens.npmScripts": "never",
"editor.fontFamily": "'Monaco', monospace",
"terminal.integrated.fontFamily": "'Monaco', monospace",
"editor.fontSize": 16,
"terminal.integrated.fontSize": 16,
"editor.minimap.enabled": false,
"editor.tabSize": 2,
"breadcrumbs.enabled": false,
"workbench.startupEditor": "none",
@LearnWebCode
LearnWebCode / next.config.js
Created February 23, 2024 21:59
For outputting static HTML files from Next.js that any server can easily host (I was integrating with an old WordPress site for the rest of the domain)
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
output: "export",
trailingSlash: true,
images: { unoptimized: true }
}
module.exports = nextConfig
{
"debug.javascript.codelens.npmScripts": "never",
"php.validate.executablePath": "/opt/homebrew/bin/php",
"editor.minimap.enabled": false,
"editor.fontSize": 14,
// "editor.fontSize": 22,
//"editor.fontFamily": "Menlo, Monaco, 'Courier New', monospace",
"terminal.integrated.fontSize": 16,
//"editor.hover.enabled": false,
"editor.tabSize": 2,