Skip to content

Instantly share code, notes, and snippets.

Avatar

Brook Jordan brookjordan

View GitHub Profile
@brookjordan
brookjordan / get-yarn-lock-dupes.js
Created Aug 4, 2020
Pass in an entire yarn.lock file contents and this will spit out duplicate resolutions
View get-yarn-lock-dupes.js
function getYarnLockDupes(yarnLock) {
return yarnLock
.split('\n')
.filter(a => !a.startsWith(' ') && !a.startsWith('#'))
.map(a => a.replace(/[:"]/g, ''))
.flatMap(a => a.split(/, ?/g))
.filter(a => a)
.flatMap(a => {
const versions = a.split(' || ');
if (versions.length === 1) { return a; }
@brookjordan
brookjordan / get-yarn-lock-dupes.js
Created Aug 4, 2020
Pass in an entire yarn.lock file contents and this will spit out duplicate resolutions
View get-yarn-lock-dupes.js
function getYarnLockDupes(yarnLock) {
return yarnLock
.split('\n')
.filter(a => !a.startsWith(' ') && !a.startsWith('#'))
.map(a => a.replace(/[:"]/g, ''))
.flatMap(a => a.split(/, ?/g))
.filter(a => a)
.flatMap(a => {
const versions = a.split(' || ');
if (versions.length === 1) { return a; }
@brookjordan
brookjordan / bem-class-builder.ts
Created Jul 7, 2020
BEM-style class name builder
View bem-class-builder.ts
/**
* Used like:
* const cls = buildBEMBuilder("block-name");
*
* let blockClass = cls();
* // => "block-name"
*
* let modifiedBlockClass = cls({
* goodModifier: true,
* badModifier: false,
@brookjordan
brookjordan / bem-class-builder.js
Last active Jul 7, 2020
Simple function to aid with building BEM-style class names
View bem-class-builder.js
/**
* Used like:
* const cls = buildBEMBuilder("block-name");
*
* let blockClass = cls();
* // => "block-name"
*
* let modifiedBlockClass = cls({
* goodModifier: true,
* badModifier: false,
@brookjordan
brookjordan / paint-timing.js
Created May 6, 2020
Print paint performance metrics
View paint-timing.js
console.log(` ‾‾‾‾
Paint time for ${location}:${
performance.getEntriesByType("paint").map(({ name, startTime }) => `
${name}: ${startTime}ms`)}
____`);
@brookjordan
brookjordan / base-64-numbers.js
Last active Dec 28, 2019
Convert numbers to base 64
View base-64-numbers.js
(function() {
const BASE_64_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'.split('');
Number.prototype._toString = Number.prototype.toString;
window._parseInt = window.parseInt;
Number.prototype.toString = function(base) {
if (base < 37 && base >= 2) {
return Number.prototype._toString.call(this, ...arguments);
@brookjordan
brookjordan / test-tg-env-parse-time.js
Created Nov 29, 2019
Test how long TradeGecko's ENV takes to parse
View test-tg-env-parse-time.js
var ignoreFirstN = 10;
var iter = 0;
var iters = [];
while(iter < 20) {
let win = window._open('http://localhost:3000/', null, 'width=500,height=500');
await new Promise(res => {
function checkForParsed() {
if (win.PARSING_TIME) {
res();
} else {
@brookjordan
brookjordan / pointerLockElement-test.js
Last active Nov 18, 2019
Trying out pointerLockElement
View pointerLockElement-test.js
let cursorWidth = 14;
let cursorHeight = 20;
let pointerOffsetX = 2;
let pointerOffsetY = 3;
let c = document.createElement('div');
c.style.cssText = `
width: ${cursorWidth}px;
height: ${cursorHeight}px;
position: fixed;
View push_unlinked_images_from_tradegecko_to_all_shopify_channels_for_account_id.rb
def push_unlinked_images_from_tradegecko_to_all_shopify_channels_for_account_id(account_id)
shopify_channels = Account.find(account_id).channels.select { |channel| channel.type == 'ShopifyChannel' }
shopify_channels.each do |shopify_channel|
shopify_channel.activate
product_array = shopify_channel.owners(:product).map(&:owner)
published_product_imgs = product_array.flat_map(&:images)
unlinked_imgs_of_published_products = published_product_imgs.reject { |img| img.online_id(shopify_channel) }
unlinked_imgs_of_published_variants = unlinked_imgs_of_published_products.select { |img| img.variant&.online_id shopify_channel }
errors = []
unlinked_imgs_of_published_variants.each_with_index do |img, i|
@brookjordan
brookjordan / format-tg-zendesk.js
Last active Sep 6, 2019
Format the TradeGecko ZenDesk tickets
View format-tg-zendesk.js
!function() {
if (!location.href.includes('https://tradegecko.zendesk.com')) {
if (confirm('Shall I open Tickets page in a new window?')) {
window.open('https://tradegecko.zendesk.com/agent/filters/52413168');
}
return;
}
let red = '#CC3340';
You can’t perform that action at this time.