Skip to content

Instantly share code, notes, and snippets.

View jhancock532's full-sized avatar
😄
Hello world!

James Hancock jhancock532

😄
Hello world!
View GitHub Profile
@jhancock532
jhancock532 / example.ts
Created January 4, 2024 15:41
A custom GraphQL link for removing the __typename from the operation query object
// N.B. Consider disabling `addTypename` in InMemoryCache instead, if applicable
/*
const client = new ApolloClient({
...
cache: new InMemoryCache({
addTypename: false,
}),
...
});
*/
@jhancock532
jhancock532 / gist:05b59514651558e14dd71ab7dc80f74a
Created June 1, 2023 16:34
Storybook pseudo states addon code for preview.js to get nested classes working
let pseudoStyleRules: any = {
':hover': [],
':visited': [],
};
function removeMatchingSubstrings(str: string, patterns: string[]) {
const regex = new RegExp(patterns.join('|'), 'g');
return str.replace(regex, '');
}
@jhancock532
jhancock532 / alert.js
Created January 16, 2023 11:03
Alert
alert("Hello world!");
@jhancock532
jhancock532 / Glob to Import Convertor for Sass Updates
Created May 16, 2022 15:52
If you're importing scss files in your project using a glob, this snippet will rename and output the new imports. WIP draft
import glob
import os
scss_files = glob.glob('**/patterns/**/*.scss', recursive=True)
main_scss = ""
working_dir = os.getcwd()
for file in scss_files:
@jhancock532
jhancock532 / pa11yConfigGenerator.py
Created April 5, 2022 08:23
Generates a pa11y.config.js file for a Django pattern library site
import glob
import re
base_url = "http://localhost:8000/pattern-library/render-pattern/patterns"
pattern_libray_pages = glob.glob('**/patterns/pages/**/*.html', recursive=True)
config = """module.exports = {
defaults: {
standard: "WCAG2AAA",
@jhancock532
jhancock532 / sitemap-generator.py
Created March 17, 2022 16:27
Sitemap Generator for Django Pattern Library Pages
# Please adapt the file paths according to your project conventions.
import glob
import re
base_url = "http://localhost:8000/pattern-library/render-pattern/patterns"
# /render-pattern/ loads the pattern in full page view without the pattern library UI
pattern_libray_pages = glob.glob('**/patterns/pages/**/*.html', recursive=True)
@jhancock532
jhancock532 / emoji.js
Last active July 15, 2024 06:17
A lot of popular emojis in a JavaScript array.
let emojis = ['💘','💝','💖','💗','💓','💞','💕','💟','❣️','💔','❤️','🧡','💛','💚','💙','💜','🤎','🖤','🤍','❤️‍','🔥','❤️‍','🩹','💯','♨️','💢','💬','👁️‍🗨️','🗨️','🗯️','💭','💤','🌐','♠️','♥️','♦️','♣️','🃏','🀄️','🎴','🎭️','🔇','🔈️','🔉','🔊','🔔','🔕','🎼','🎵','🎶','💹','🏧','🚮','🚰','♿️','🚹️','🚺️','🚻','🚼️','🚾','🛂','🛃','🛄','🛅','⚠️','🚸','⛔️','🚫','🚳','🚭️','🚯','🚱','🚷','📵','🔞','☢️','☣️','⬆️','↗️','➡️','↘️','⬇️','↙️','⬅️','↖️','↕️','↔️','↩️','↪️','⤴️','⤵️','🔃','🔄','🔙','🔚','🔛','🔜','🔝','🛐','⚛️','🕉️','✡️','☸️','☯️','✝️','☦️','☪️','☮️','🕎','🔯','♈️','♉️','♊️','♋️','♌️','♍️','♎️','♏️','♐️','♑️','♒️','♓️','⛎','🔀','🔁','🔂','▶️','⏩️','⏭️','⏯️','◀️','⏪️','⏮️','🔼','⏫','🔽','⏬','⏸️','⏹️','⏺️','⏏️','🎦','🔅','🔆','📶','📳','📴','♀️','♂️','⚧','✖️','➕','➖','➗','♾️','‼️','⁉️','❓️','❔','❕','❗️','〰️','💱','💲','⚕️','♻️','⚜️','🔱','📛','🔰','⭕️','✅','☑️','✔️','❌','❎','➰','➿','〽️','✳️','✴️','❇️','©️','®️','™️','#️⃣','*️⃣','0️⃣','1️⃣','2️⃣','3️⃣','4️⃣','5️⃣','6️⃣','7️⃣','8️⃣','9️⃣','🔟','🔠','🔡','🔢','🔣','🔤','🅰️','🆎','🅱️','🆑','🆒','🆓','ℹ️','🆔','Ⓜ️','🆕','🆖','🅾️','🆗','🅿️','🆘','🆙','🆚','🈁'
@jhancock532
jhancock532 / pointInPolygon.js
Created December 28, 2020 12:01
JavaScript function to check if a point is in a polgyon
function pointInPolygon(point, vs) {
// Taken from https://github.com/substack/point-in-polygon
// Nice explainer at https://observablehq.com/@tmcw/understanding-point-in-polygon
// ray-casting algorithm based on
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
let x = point[0], y = point[1];
let inside = false;
for (let i = 0, j = vs.length - 1; i < vs.length; j = i++) {
@jhancock532
jhancock532 / QuaternionSlerpExample.js
Created November 27, 2020 23:04
How to animate a smooth camera angle transition in Three.js, without causing the camera to spin around itself several times.
let time = {t: 0};
const positionToLookAt = new THREE.Vector3(10, 10, 10);
const startQuaternion = camera.quaternion.clone(); //set initial angle
camera.lookAt(positionToLookAt);
const endQuaternion = camera.quaternion.clone(); //set destination angle
camera.quaternion.copy(startQuaternion);
new TWEEN.Tween(time)
.to({t: 1}, 1000) //duration in milliseconds
@jhancock532
jhancock532 / dadaArtistsOnDada.art.js
Last active November 11, 2020 20:39
How to get Dada artists on dada.art
var img = new Image;
img.crossOrigin = "Anonymous";
img.onload = function () {
ctx_final.drawImage(img, 0, 0, img.width * 0.64, img.height * 0.69);
}
img.src = 'https://res.cloudinary.com/dvxmjunfv/image/upload/v1605120751/Photos/Dada_artists__group_photograph__1920__Paris.jpg';