Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env node
// @ts-check
/**
* Duplicate detector for TS/JS React projects.
*
* Heuristics:
* - Extracts functions, React components (PascalCase returning JSX), and const/config objects.
* - Normalizes tokens (identifiers/strings/numbers -> placeholders), hashes for exact clones.
* - Computes near-duplicate and semantic similarity via token Jaccard.
*
@visualjeff
visualjeff / README.md
Last active November 21, 2025 03:58
tokenManager

This gives you:

•	getToken() that:
•	returns cached token if still valid
•	otherwise calls your REST endpoint with the existing token
•	Protection against the "thundering herd" of multiple callers triggering multiple renewals at once
•	invalidate() method for logout or when you need to clear the token
•	Support for seeding an initial token (e.g., from localStorage)
•	No external deps, MIT-licensed, TypeScript-native
const productApiResponses = await Promise.all(
itemNumbers.map(async (itemNumber: string) => {
try {
const productAPIResponse = await productService(
itemNumber,
productConfig,
locale
);
if (!productAPIResponse) return null;
Pre-req's:
Python 3
A project that is git initialized
Windozs setup:
pip install pre-commit
MAC OS setup for pre-commit:
@visualjeff
visualjeff / gist:412f89aecce959fd71513dbc809be3e4
Created January 27, 2021 04:20
Script for processing megaMenu. Save to root of forge project as index.js. Run as "node index.js"
// Note you may need to update the path to our sample data.
let data = require('./src/stories/menus/megaMenu/megamenu.json');
const sortByName = (a, b) => {
return a.name > b.name ? 1 : b.name > a.name ? -1 : 0;
};
// This function should be memoized for performance reasons.
const sortParent = (data) => {
let sortedData = [...data];
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
import Component from '@glimmer/component';
export default class BlogPost extends Component {
}
@visualjeff
visualjeff / gist:ba6ebac7c80572046f02b879edd24789
Last active July 11, 2019 22:43
Example URL's for different types of Azure Authentication
For non-interactive login:
For a v2 Token:
https://login.microsoftonline.com/<<TENANT_NAME>>.onmicrosoft.com/oauth2/v2.0/authorize?response_type=id_token&scope=openid%20profile&client_id=<<CLIENT_ID>>&redirect_uri=https%3A%2F%2Fjwt.ms&nonce=null
For a v1 Token:
https://login.microsoftonline.com/common/oauth2/authorize?client_id=<<CLIENT ID>>&response_type=id_token&nonce=null
For an interactive login (if you need to set an initial password) for B2C:
@visualjeff
visualjeff / gist:1cda46847ae3b089c2a254461ef9ffe7
Last active May 6, 2019 03:57
Publishing a NPM module from GitHub
First, be sure make sure you've set your git user.name and user.email:
git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email [email protected]
Create new local branch to work in:
git checkout -b v1.0.0
Set version number in your project's package.json!!!
import Ember from 'ember';
export default Ember.Component.extend({
});