Skip to content

Instantly share code, notes, and snippets.

@bramses
bramses / upsertPost.js
Last active April 5, 2024 04:38
upserting a markdown file from obsidian into mdx for nextjs
const { read } = require("gray-matter");
const { writeFileSync } = require('fs')
const HOMEPAGE_PATH = process.env.HOMEPAGE_PATH;
/*
This code is taking the markdown file and converting it to a mdx file
The frontmatter data is being extracted from the markdown file then converted into an object.
Then we are checking if there\'s a slug in the frontmatter or not.
If there isn\'t one throw an error because that means we can\'t create a post without a slug
@bramses
bramses / README.md
Last active February 28, 2024 18:24
Uploading a file from iOS Shortcuts to Cloudflare Workers

Create a Shortcut with two steps:

  1. select photos
  2. get contents from url
  3. set method to post
  4. set request body to form
  5. use magic variable to set file as result of last step
@bramses
bramses / contact.js
Last active January 16, 2024 03:55
Create a Contact Form in NextJS/Vercel
// frontend - react
import { useState } from "react";
import Alert from "@reach/alert";
export default function Contact() {
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [message, setMessage] = useState("");
const [messageSent, setMessageSent] = useState(false);
On picture, look for volume number and link to correct part of video timestamp. If not in system, say not in system. All information sourced from Hunterpdiea (https://hunterxhunter.fandom.com/wiki/Hunterpedia)
On help, tell users what you do and prompt them to upload an image of HxH manga cover.
HxH Vol 1-5: https://youtu.be/FrZHYje8mPc?si=4JCdBJXWA1dKgu5c
6-13: https://youtu.be/FrZHYje8mPc?si=mVWEJT8blFPKJZpW&t=80
14-18: https://youtu.be/FrZHYje8mPc?si=R6sr8eLbn70LH8Ol&t=150
19-22: https://youtu.be/FrZHYje8mPc?si=i8XSTzULIPa9OSDs&t=220
23-30: https://youtu.be/FrZHYje8mPc?si=1Wv7jSTmMkQ7WGJD&t=300
31-32: https://youtu.be/FrZHYje8mPc?si=r5iMR-L7-OEoLv72&t=379
@bramses
bramses / _result.md
Last active January 8, 2024 09:45
Use GPT-4 to automatically diagnose errors

TLDR

I wrapped Python traceback and Exception so whenever an Exception is raised, an automatic diagnosis is done by GPT-4. See results below:

Prompt (Automatically Generated by error_wrap function)

This error message occurred because of 'test' at line 177 in file api.py, function main. The exception type is <class 'Exception'>. The function is:

@bramses
bramses / twitch_thanker_guidance.ipynb
Created May 23, 2023 22:20
Using Guidance to create a Twitch thank you bot
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bramses
bramses / obsidian-publish-swipe.js
Created January 5, 2023 04:10
swipe left to open menu; swipe right to close it
// swipe left on mobile to open menu
let touchstartX = 0;
let touchendX = 0;
function checkDirection() {
// check if greater than 100px
// if swipe right close menu
if (touchendX < touchstartX && touchstartX - touchendX > 100) {
document
.querySelector(".published-container")
@bramses
bramses / publish.js
Last active January 5, 2023 03:49
testing remark42 on obsidian publish
var remark_config = {
host: "https://demo.remark42.com",
site_id: "remark",
};
// https://stackoverflow.com/a/74271142/3952024
async function waitForElement(selector, timeout = null, location = document.body) {
return new Promise((resolve) => {
let element = document.querySelector(selector);
if (element) {
@bramses
bramses / vercel.json
Created January 2, 2023 19:09
:path not working
{
"rewrites": [
{
"source": "/zettelkasten/",
"destination": "https://publish.obsidian.md/serve?url=bramadams.dev/zettelkasten"
},
{
"source": "/zettelkasten/:path*",
"destination": "https://publish.obsidian.md/serve?url=bramadams.dev/zettelkasten/:path*"
}
@bramses
bramses / gitLastDay.js
Last active July 25, 2022 01:25
Note: this must be run in the repo that has the `.git` folder (https://www.bramadams.dev/projects/gitting-git-commits-for-your-work-journal)
import moment from "moment";
import { spawn } from "child_process";
import * as dotenv from "dotenv";
dotenv.config();
const OWNER = process.env.OWNER || process.argv[2];
const REPO = process.env.REPO || process.argv[3];
const AUTHOR = process.env.AUTHOR || process.argv[4];
const GH_URL = `https://github.com/${OWNER}/${REPO}/commit/`;