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');
@padolsey
padolsey / recruiter_call.md
Last active February 21, 2024 11:50
This happened.

"Do you know JavaScript?"

"Uhh, yes."


"Do you know Object-orientated JavaScript?"

"Yes."

@padolsey
padolsey / makeInterpolator.js
Last active February 21, 2024 11:50
Dead simple straight-up performant interpolation
/**
* Outputs a new function with interpolated object property values.
* Use like so:
* var fn = makeInterpolator('some/url/{param1}/{param2}');
* fn({ param1: 123, param2: 456 }); // => 'some/url/123/456'
*/
var makeInterpolator = (function() {
var rc = {
'\n': '\\n', '\"': '\\\"',
'\u2028': '\\u2028', '\u2029': '\\u2029'
@padolsey
padolsey / jquery.genSelector.js
Created October 15, 2013 22:56
Cheap jQuery Selector Generation
jQuery.fn.genSelector = function() {
// Generate a selector for the given elements
// Note: Selector is not guarenteed to be unique
return this.map(function() {
var out = [], p = this;
switch (true) {
case this.id: return '#' + this.id;
case this === document.body: return 'body';
case this === document.documentElement: return 'html';
}
'use strict';
var CLIENT_ID = 'CLIENT ID';
var API_KEY = 'YOUR SECRET API KEY (Test or Live)';
var TOKEN_URI = 'https://connect.stripe.com/oauth/token';
var AUTHORIZE_URI = 'https://connect.stripe.com/oauth/authorize';
var qs = require('querystring');
var request = require('request');
@padolsey
padolsey / jQStyleThrower.js
Last active February 21, 2024 11:50
jQuery style watcher/thrower
jQuery.throwOnStyle = (function($) {
var watchers = [];
$.style = (function(_style) {
return function(elem, name, value) {
for (var i = 0, l = watchers.length; i < l; ++i) {
var w = watchers[i];
if (
(w.styleMatcher.test ?
@padolsey
padolsey / gist:7990476
Created December 16, 2013 17:08
Get notified when you're attempting jQuery method calls on an empty collection
for (var i in $.fn) (function(method, name) {
// ignore traversal/selection methods
if (typeof method != 'function' || [
'constructor', 'init', 'find', 'add', 'next', 'nextUnil', 'prevUntil',
'parents', 'closest', 'eq', 'filter', 'has', 'first', 'siblings',
'last', 'map', 'not', 'slice', 'addBack', 'andSelf', 'contents', 'prev',
'end', 'not', 'children', 'nextAll', 'prevAll', 'parent', 'parentsUntil'
].indexOf(name) > -1) {
return;
}
var vic = require('./vic').vic;
var singular = require('./singularValidators');
var DateRange = require('./DateRange');
var Date = require('./Date');
var NativeDate = Date.NativeDate;
// Regexes adaped/used in the regexBuilder (r)
// Flag hard-set to 'i';
var YEAR = /(\d{2,4})/;
function git_likely_authority() {
# Outputs a ranked list of likely author(itie)s regarding tracked files matching *${1}*
# (Makes it easier to discover who likely knows most about the matched files)
# (Note: Not always indicative if large refactors/renamings have occurred)
# E.g. `git_likely_authority some_pattern_that_matches_a_path`
git ls-files "*${1}*" |
grep -v -E 'node_modules|vendor' | # edit to avoid certain files/dirs
xargs -n1 git blame --line-porcelain |
sed -n 's/^author //p' |
sort -f |