Skip to content

Instantly share code, notes, and snippets.

View bramses's full-sized avatar
🤨

Bram Adams bramses

🤨
View GitHub Profile
@bramses
bramses / sms.js
Created August 9, 2021 23:05
Receiving a Message on NodeJS with Twilio
router.post('/sms', async (req, res) => {
const twiml = new MessagingResponse();
await workflow(`${req.body.Body}`)
res.writeHead(200, {'Content-Type': 'text/xml'});
res.end('Message Received');
});
@bramses
bramses / stenography-autopilot.js
Created October 13, 2021 20:31
running stenography automagically on a full file
[
{
code: 'if (str.length > 1) {\n' +
' return str[0] + str[str.length - 1];\n' +
' }',
start: 238,
end: 316,
charLength: 78,
type: 'conditional',
startLine: 8,
@bramses
bramses / firebase-next.js
Created December 17, 2021 08:33
Putting the RUD in CRUD (NextJS + Firebase)
import db from '../../../utils/db';
export default async function handler (req, res) {
const { id } = req.query;
try {
if (req.method === 'PUT') {
await db.collection('my_collection').doc(id).update({
...req.body,
updated: new Date().toISOString(),
@bramses
bramses / create-embeddings.ts
Last active December 28, 2021 22:08
Embedding an Obsidian Document
/**
This code is taking the input text and sending it to OpenAI's API.
The response from the API is then parsed into a JSON object, which contains an array of embeddings for each sentence in the input.
*/
createEmbeddings = async (input: string[]): Promise<EmbeddingsResponse|null> => {
try {
input = input.map(inp => inp.replace(/\n/g, ' '))
const body = { input };
const response = await axios.post(this.endpoint, JSON.stringify(body),
@bramses
bramses / TweetHref.js
Last active March 11, 2022 18:16
A React Component to Tweet
/**
Usage:
<TweetHref slug="{url}">This will be the Tweet</TweetHref>
*/
import styled from 'styled-components';
// create a styled component called StyledA
// that is styled like an anchor tag
// with the font family of Work Sans
@bramses
bramses / KingdomHearts.js
Created March 14, 2022 21:29
Example of DOM targeting in NextJS with styled components
/* eslint-disable react-hooks/exhaustive-deps */
import anime from 'animejs';
import { useEffect } from 'react';
import styles from './KingdomHearts.module.css'
export default function KingdomHearts () {
let startBGMusic
let openUrl
let play
@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 / open from shell
Created March 17, 2022 22:40
opening a file from shell
open -n -b "com.microsoft.VSCode" --args "$*"
@bramses
bramses / swr-frontend-example.js
Created March 19, 2022 22:14
using swr in a React component
import useSWR from "swr";
const fetcher = (...args) =>
fetch(...args)
.then((res) => res.json())
export default function Page() {
const { data, error } = useSWR("/api/endpoint", fetcher);
if (!data)
@bramses
bramses / swr-backend-example.js
Created March 19, 2022 22:15
SWR backend example forn next js
export default async function handler(req, res) {
try {
const res = await longDataFetch();
return res.status(200).json(res);
} catch (err) {
return res.status(500).json({ error: err.message });
}
}