Skip to content

Instantly share code, notes, and snippets.

View Jaballadares's full-sized avatar

John Balladares Jaballadares

View GitHub Profile
@rmtbb
rmtbb / ChatGPT Canvas HTML Renderer from Clipboard.url
Last active November 10, 2024 20:51
Bookmarklet that lets you render a full HTML page with any included css and javascript that is currently copied to your clipboard. Also works for SVG code. Useful with ChatGPT Canvas
javascript:(function(){try{navigator.clipboard.readText().then(function(t){if(t){var e=window.open("","_blank","width=800,height=600");e.document.open(),e.document.write(t),e.document.close()}else alert("Clipboard is empty. Please copy some text to the clipboard first.")}).catch(function(t){console.error("Failed to read clipboard contents: ",t),alert("An error occurred while trying to access the clipboard. Please ensure your browser allows clipboard access.")})}catch(t){console.error("An error occurred:",t),alert("An error occurred while trying to open the new window with the clipboard content.")}})();//bookmarklet_title: HTML Preview from Clipboard
@simonw
simonw / rag-demo.ts
Created June 20, 2024 17:17
Val.Town demo from this morning
import { basicAuth } from "https://esm.town/v/pomdtr/basicAuth?v=65";
import Anthropic from "npm:@anthropic-ai/[email protected]";
const anthropic = new Anthropic();
async function suggestKeywords(question) {
const message = await anthropic.messages.create({
max_tokens: 128,
model: "claude-3-5-sonnet-20240620",
tools: [{
@phechzzz
phechzzz / regexTutorial.md
Last active January 2, 2024 18:46
Regex Tutorial: Matching an Email

Regex: Matching an Email

Regular expressions are powerful search tools comprised of a sequence of defining characters. With regex, you can search, validate, replace, and extract strings of text based on these defining characters.

Summary

In this tutorial, we will break down a regex used to match an email using the following code snippet:
/^([a-zA-Z0-9._%+-]+)@([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,})$/
Going character by character, we will work through this snippet of code to understand how it is defining search parameters. Regular expressions can feel overwhelming at first, but by breaking the code down into different defining groups, we can easily understand how this expression is working.

@simonw
simonw / explain-selected.js
Last active October 26, 2024 04:30
JavaScript function to explain selected text on the page using GPT 3.5
(function() {
const OPENAI_API_KEY = 'sk-...';
let selectedText = window.getSelection().toString().trim();
if (selectedText.length > 0) {
let body = JSON.stringify({
model: 'gpt-3.5-turbo',
messages: [{role: 'system', content: 'explain this succinctly' },{ role: 'user', content: selectedText }]
});
fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
/*
Autosend Invites to anyone that shares X number of connections with you.
Way to use this script:
1. Save it as a bookmarklet
2. Go to 'People you may know'
3. Click on this bookmarklet.
4. Enter number of overlapping connections
5. Check your console
@NickDeckerDevs
NickDeckerDevs / hubspot-better-assocation-loop.js
Created December 7, 2022 18:04
looping through deal => contact assocations in hubspot, then associating them
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
const hubspotClient = new hubspot.Client({
accessToken: process.env.custom_code_private_app
});
try {
const request = require('request');
exports.main = async (event, callback) => {
/* BE SURE TO ADD THE CONTACT ID INTO THE 'PROPERTY TO INCLUDE IN CODE' SECTION OF THE CUSTOM CODED ACTION */
const contact_id = event.inputFields['hs_object_id'];
/* LOOK UP THE CONTACT VIA THE ID AND RETRIEVE THE PROPERTY 'hs_additional_emails' */
var options = {
"method": "GET",
"url": "https://api.hubapi.com/crm/v3/objects/contacts/" + contact_id + "?hapikey=" + process.env.HAPIKEY + "&properties=hs_additional_emails"
/** * @OnlyCurrentDoc */
function moveColumns() {
// get sheet
var sheet = SpreadsheetApp.getActiveSheet();
// select columns to be moved ('collegename' & 'shoesize')
var columnsToMove = sheet.getRange("E1:F1");
@evanreichard
evanreichard / archive-redirect.user.js
Last active September 15, 2023 07:40
Auto Archive Redirect
// ==UserScript==
// @name Auto Archive Redirect
// @namespace Evan Reichard
// @version 0.0.3
// @match *://*/*
// @grant GM.xmlhttpRequest
// @grant GM.openInTab
// @noframes
// @run-at document-start
// ==/UserScript==
@wcarss
wcarss / order-by.js
Last active May 13, 2021 15:50
a toy function to sort js arrays with sql-like syntax
// preamble: public domain; no warranty
//
// this is a toy -- it is slow, cannot handle unicode, keys w/
// spaces, nested keys, natural ordering, etc.
// orderBy('key1 [asc|1|desc|-1][, key2 [asc|1|desc|-1]][, etc]')
//
// write sql-like sort orders for arrays of objects, e.g.:
//