Skip to content

Instantly share code, notes, and snippets.

@KimSarabia
KimSarabia / bulk_removal.py
Last active October 30, 2023 22:52
Script accepts a list of database names from a .txt file and perform the add or del operation on a specified dblist (e.g., legacy-vector).
import subprocess
import argparse
# Command: `python bulk_removal.py del dbnames.txt legacy-vector`
def execute_composer_commands(operation, dblist_file, dblist_name):
# Check if the operation is valid
if operation not in ("add", "del"):
print("Invalid operation. Use 'add' or 'del'.")
return
@KimSarabia
KimSarabia / getComputedFontSizes.js
Created September 6, 2023 21:00
Quick tool for grabbing calculated font sizes in the browser given an array of classes
function getComputedFontSizes(classNames) {
const results = {};
classNames.forEach(className => {
// Get all elements with the specified class name.
const elementsWithClass = document.getElementsByClassName(className);
if (elementsWithClass.length > 0) {
// Select the first element with the specified class.
const targetElement = elementsWithClass[0];
@KimSarabia
KimSarabia / extract_font_sizes.py
Created August 31, 2023 22:02
Quick tool for grabbing all font-size rules in a directory
import csv
import os
import re # Import the re module for regular expressions
# Define the directory path containing Less files
less_directory = 'YOUR_DIRECTORY_PATH'
output_csv_file = 'font_sizes.csv' # Define the output CSV file name
# Initialize a list to store font-size values along with filename, line number, class name/ID
font_sizes_info = []
@KimSarabia
KimSarabia / focusBacktoTrigger.js
Last active January 24, 2020 18:55
Event emitter so focus goes back to modal trigger on close (MJS-4011)
// Sample of opening the cart via componentEvents.emitEvent.
// NOTE: openerElement needs to be populated with an actual DOM Node
// or jQuery object and not just a selector.
// In this instance, test is the trigger element with the ID flyout-test.
const test = document.getElementById('flyout-test')
// Event emitter
componentEvents.emitEvent('open-cart-flyout', [{
openerElement: test
@KimSarabia
KimSarabia / range-es6.js
Last active October 31, 2017 20:18
Print Range in JavaScript (ES6)
//Print 1 to 20 (Source: https://stackoverflow.com/questions/3895478/does-javascript-have-a-method-like-range-to-generate-an-array-based-on-suppl)
Array.from(new Array(20), (x,i) => i)
//Result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
@KimSarabia
KimSarabia / prime-number-for-loop.js
Created October 17, 2017 20:54
Prime Number For Loop
for (var c = 2; c <= 100; c++) {
for (var i = c - 1; i >= 1; i--) {
if (i === 1) {
console.log(c);
}
if (c % i === 0) {
break;
}
}
}
@KimSarabia
KimSarabia / sum-an-array-ES6.js
Created October 16, 2017 21:52
Summing an Array ES6
var sum = [1, 2, 3].reduce((a, b) => a + b, 0);
@KimSarabia
KimSarabia / sumstrings.js
Created October 16, 2017 19:25
Sum of Large Number Strings
//Source: https://codereview.stackexchange.com/questions/92966/multiplying-and-adding-big-numbers-represented-with-strings
function add(a, b) {
if ((a | 0) == 0 && (b | 0) == 0) {
return '0';
}
a = a.split('').reverse();
b = b.split('').reverse();
var result = [];
@KimSarabia
KimSarabia / mixed-number-converter.js
Created October 15, 2017 17:56
Simple fraction to mixed number converter
// https://www.codewars.com/kata/simple-fraction-to-mixed-number-converter/
var greatest = (a,b) => (b===0) ? a : greatest(b,a%b)
function mixedFraction(s){
arr = s.split('/')
dividend = Number(arr[0])
divisor = Number(arr[1])
if(divisor === 0){
throw "ZeroDivisionError";
} else {
if(dividend%divisor === 0){
@KimSarabia
KimSarabia / greatest-common-denominator.js
Created October 13, 2017 21:05
Greatest Common Denominator in JavaScript
function gcd(a,b){if(b===0) return a; return gcd(b,a%b)}
// ES6
let gcd = (a,b) => (b===0) ? a : gcd(b,a%b)
// Original: Java
// public int GCD(int a, int b) {
// if (b==0) return a;
// return GCD(b,a%b);