Skip to content

Instantly share code, notes, and snippets.

View padolsey's full-sized avatar

James Padolsey padolsey

View GitHub Profile
import json
import re
import base64
import openai
from openai import OpenAI
from threading import Lock
with open('keys.json', 'r') as file:
api_keys = json.load(file)
// Creating a new MutationObserver to watch for changes in the attributes of an image element
new MutationObserver(changes => {
// Iterating through each change detected by the observer
changes.forEach(change => {
// Check if the change is related to the 'src' attribute of the image
if(change.attributeName.includes('src')){
console.log(change.target.src); // Logging the new source of the image
// Attempt to find an existing clone image by its ID
let i = document.querySelector('#img-clone-transparent');
import requests
import threading
import time
import csv
import os
import random
from collections import defaultdict
api_key = os.environ.get('OPENAI_API_KEY')
word_freq = defaultdict(int)
@padolsey
padolsey / mastodon_linker.js
Created November 19, 2022 22:06
Be careful.....
// ==UserScript==
// @name Mastodon Link To Own Instance
// @version 0.1
// @description Adds link to your own instance next to a mastadon
// @author You
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
/**
* I reckon computed member access in JS, i.e. ...[...],
* could be a tonne more powerful. This is an example of that.
* ===========================================================
* This is a filthy hack. Probably don't use it...
* ===========================================================
* It sets up a proxy that'll catch member access to arrays.
* Upon member-access, toString will be natively called and
* intercepted; the intercepted value will be used within our
* proxy to return a filtered version of the array.
Number.prototype.to = function*(n) {
let finish = n.valueOf();
let start = this.valueOf();
let finishLessThan = start >= finish;
for (
let i = start;
finishLessThan ? i >= finish: i <= finish;
i += finishLessThan ? -1 : +1
) yield i;
};

Keybase proof

I hereby claim:

  • I am padolsey on github.
  • I am padolsey (https://keybase.io/padolsey) on keybase.
  • I have a public key whose fingerprint is F256 45CF 1A20 5360 6A46 A9AD 599B 1D48 053D 0BD2

To claim this, I am signing this object:

'use strict'
const five = require('johnny-five');
const board = new five.Board();
board.on('ready', () => {
console.log('Ready');
let lcd = new five.LCD({
var uk = createFuzzyScorer('United Kingdom');
var us = createFuzzyScorer('United States');
console.log([
uk('United') > uk('uk'),
uk('nited') > uk('ingdom'),
uk('united kingdom') > uk('united kingdo'),
uk('united dom') < uk('united kin'),
uk('knited k') > uk('dom'),
uk('_united_') < uk('united'),
// context: https://twitter.com/codepo8/status/572863924887945216
function fuzzysearch(query, text) {
// Build a regex, then test text against it:
return RegExp(
query
// Escape any special regex characters:
.replace(/[.*+?^${}()|[\]\/\\]/g, '\\$&')
// Any escaped or non-escaped character can be followed by
// any number of other characters (.*):