Skip to content

Instantly share code, notes, and snippets.

@learyjk
learyjk / wf-sso.js
Last active December 19, 2024 23:51
app.get(
'/dashboard/sso',
middleware.checkForUserObject,
// @ts-expect-error - TS7006 - Parameter 'req' implicitly has an 'any' type. | TS7006 - Parameter 'res' implicitly has an 'any' type. | TS7006 - Parameter 'next' implicitly has an 'any' type.
// eslint-disable-next-line unused-imports/no-unused-vars
function dashboardGetSso(req, res, next) {
const payload = {
iat: Math.ceil(new Date().getTime() / 1000),
jti: uuid.v4(),
first_name: req.user.firstName,
@learyjk
learyjk / user.js
Last active October 31, 2024 01:13
TalkJS USers
Talk.ready.then(function() {
const me = new Talk.User({
id: member.id,
name: member.customFields["free-user"],
email: member.auth.email,
photoUrl: member.profileImage,
welcomeMessage: null,
role: "brand",
});
<script src="https://cdn.jsdelivr.net/npm/p5@1.6.0/lib/p5.js"></script>
<script>
const dotSize = 3
const spacing = dotSize * 8
const areaOfEffect = 64
let dots = []
function setup() {
let cnv = createCanvas(windowWidth, windowHeight);
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns"></script>
<script>
// chart-1
const ctx = document.getElementById("chart-1").getContext("2d");
const sunriseDates = document.querySelectorAll("[sunrise-date]");
const sunriseValues = document.querySelectorAll("[sunrise-value]");
const fvsDates = document.querySelectorAll("[fvs-date]");
const fvsValues = document.querySelectorAll("[fvs-value]");
const lgtDates = document.querySelectorAll("[lgt-date]");
// This endpoint lives on my cloudflare worker
// It is called each time the user launches the DE.
// Note that we already have the user's access token from initial app install.
// The access token is stored in KV SITEID_SITE_INFO.
app.post('/resolve', async (c) => {
// Get the siteId and idToken from the request body
const body = await c.req.json();
const { siteId, idToken } = body;
// Check KV for access token and credits
@learyjk
learyjk / staging-vs-prod.js
Created March 16, 2024 00:41
Staging vs. Production Code
const currentDomain = window.location.hostname;
let scriptElement = document.createElement('script');
scriptElement.type = 'text/javascript';
if (currentDomain === 'staging.webflow.io') {
// staging
scriptElement.src = 'http://127.0.0.1/index.js';
} else if (currentDomain === 'www.example.com') {
// production
@learyjk
learyjk / matterJsBodyWithImage.js
Created January 4, 2024 16:25
How to add images to a Body in matter.js
let circle = Bodies.circle(i, 10, 30, {
friction: 0.3,
frictionAir: 0.00001,
restitution: 0.8,
render: {
sprite: {
texture: "your-image-link-here.jpg",
},
},
plugin: {
@learyjk
learyjk / webflowTimezones.js
Last active October 3, 2023 16:06
Converts times on the Webflow Conf website to users' timezone.
function isValidTimeFormat(timeStr) {
const twelveHourFormat = /^(\d{1,2}:\d{2} [AP]M)$/i;
const twentyFourHourFormat = /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/;
if (twelveHourFormat.test(timeStr)) {
return { valid: true, is24HourFormat: false };
} else if (twentyFourHourFormat.test(timeStr)) {
return { valid: true, is24HourFormat: true };
} else {
return { valid: false, is24HourFormat: false };
function initialize() {
var markers = [];
var input = /** @type {HTMLInputElement} */
(document.getElementById('Address'));
var options = {
componentRestrictions: {
country: 'gb'
}
}
var autocomplete = new google.maps.places.Autocomplete(input,options);
// Define your attribute names here.
const ATTR_NAME = "wb-data";
const ATTR_ITEM_VALUE = "tab-item";
const ATTR_CONTENT_VALUE = "tab-content";
gsap.registerPlugin(ScrollTrigger);
function init() {
const tabItems = document.querySelectorAll(
`[${ATTR_NAME}="${ATTR_ITEM_VALUE}"]`