Skip to content

Instantly share code, notes, and snippets.

View padolsey's full-sized avatar

James Padolsey padolsey

View GitHub Profile
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
class TagStreamProcessor {
constructor(startTag, endTag, placeholder, processFn) {
this.startTag = startTag;
this.endTag = endTag;
this.placeholder = placeholder;
this.process = processFn;
this.buffer = '';
this.tagOpen = false;
}
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;
}