Skip to content

Instantly share code, notes, and snippets.

@lyatziv
lyatziv / targets.txt
Created December 1, 2023 17:57
Verify Pages
http://github.com
@lyatziv
lyatziv / asymmetricEntropicConcat.ts
Created November 30, 2023 17:06
Asymmetric Entropic Concat
export const asymmetricEntropicConcat = (arr1: any[], arr2: any[]): any[] => {
const concatenatedArray = arr1.concat(arr2);
for (let i = concatenatedArray.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
// Swap elements using a temporary variable
const temp = concatenatedArray[i];
concatenatedArray[i] = concatenatedArray[j];
concatenatedArray[j] = temp;
@lyatziv
lyatziv / arrayRandom.js
Created August 7, 2023 17:16
javascript random entries from an array
const getRandomPercentageElements = (array, percentage) => {
if (!Array.isArray(array) || array.length === 0 || typeof percentage !== 'number' || percentage < 0 || percentage > 100) {
throw new Error('Invalid input');
}
const numberOfElements = Math.ceil(array.length * (percentage / 100));
return getRandomEntriesFromArray(array, numberOfElements);
}
const getRandomEntriesFromArray = (array, numberOfElements) => {
if (!Array.isArray(array) || array.length === 0 || typeof numberOfElements !== 'number' || numberOfElements < 0 || numberOfElements > array.length) {
@lyatziv
lyatziv / parseColor.js
Created July 14, 2022 17:01
Get an array of rgb values for a color
// Requires window
const parseColor = (input) => {
var div = document.createElement('div');
document.body.appendChild(div)
div.style.color = input;
const style = window.getComputedStyle(div);
const ret = style.color.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i);
document.body.removeChild(div);
if(ret) {
@lyatziv
lyatziv / addFixed
Created April 13, 2022 16:55
javascript math is weird. I wrote this because I got tired of getting a headache whenever trying to add decimals.
export const addFixed = (a: number, b: number, p = 0) => {
const t = Number(`1${'0'.repeat(p)}`);
return (a * t + b * t) / t;
};
@lyatziv
lyatziv / addFixed
Last active April 13, 2022 18:02
javascript math is weird.
export const addFixed = (a: number, b: number, p = 0) => {
const countDecimal = (a: number): number => String(a).split('.')[1].length;
const dec = isNaN(p) ? Math.max(countDecimal(a), countDecimal(b)) : p;
const t = Number(`1${'0'.repeat(dec)}`);
return (a * t + b * t) / t;
};
@lyatziv
lyatziv / makePamphlet.js
Created March 17, 2022 23:00
Get page numbering for booklet printing
const makePamphlet = (suspectInput) => {
const input = Boolean(suspectInput % 2) ? suspectInput + 1 : suspectInput;
const evenPages = [
...Array(input / 2)
.fill(0)
.map((_el, idx) => (idx + 1) * 2),
].reverse();
const oddPages = [
...Array(input)
.fill(0)
@lyatziv
lyatziv / isBlank.js
Last active December 18, 2020 16:23
A presumptive function with exhaustive data type tests for empty, null, values.
export default (tr) => {
const hasLength = (val) => val.length
const noTest = () => true
const notZero = (val) => val !== 0
const types = {
'symbol': (val) => val.description === "",
'function': noTest,
'undefined': noTest,
'bigint': notZero,
'object': (val) => Object.is(val, {}),
{
"$schema": "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json",
"basics": {
"name": "Lavi Yatziv",
"label": "Senior Web Developer",
"image": "",
"email": "lavi.yatziv@gmail.com",
"phone": "",
"url": "http://www.fixedspace.com",
"summary": "A graduate of Carleton University's Film program as well as Algonquin College's Radio and TV Broadcasting studies, my work is situated at the juncture between digital and more traditional media. My thorough understanding of both allows me to create beautiful yet functional websites, promotional videos and animation. Troubleshooting and improving functionality for existing websites are among my specialties.",
@lyatziv
lyatziv / object2qs.js
Created May 5, 2020 21:13
object2qs.js
/**
* Converts object properties to query string.
* @param {object} props - The object used to construct the query string.
* @return {string} The query string.
*/
export default (props) => {
return typeof props === 'object'
? `?${Object.keys(props).map((prop) => `${prop}=${props[prop]}`).join('&')}`
: ''
}