Skip to content

Instantly share code, notes, and snippets.

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 EMAILADDRESS@SOMEWHERE.COM
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({
});
//You could use faker.js to generate some testData
function chunk(arr, chunkSize) {
const R = [];
for (let i = 0, len = arr.length; i < len; i += chunkSize) {
R.push(arr.slice(i, i + chunkSize));
}
return R;
}
@visualjeff
visualjeff / gist:0ec717c964620b75f050c93ee286a936
Last active August 21, 2018 03:11
Easy way to generate fake user records with faker.js
const faker = require('faker');
const testData = new Array(100).fill({}).map((v, i) => {
return {
name: faker.name.findName(),
address: faker.address.streetAddress(),
city: faker.address.city(),
state: faker.address.stateAbbr(),
postal: faker.address.zipCode(),
email: ''
@visualjeff
visualjeff / gist:ca00c48f3bfc95f6551302d47cb45040
Created August 9, 2018 22:04
Generating a good nonce in the browser to prevent replay (in Javascript SPA's)
const crypto = crypto.subtle;
async function sha256(message) {
const msgBuffer = new TextEncoder('utf-8').encode(message); // encode as UTF-8
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer); // hash the message
const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert ArrayBuffer to Array
const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join(''); // convert bytes to hex string
return hashHex;
}
let randomNumber = window.crypto.getRandomValues(new Uint32Array(1)); //Generate randomNumber and store in local storage.