Skip to content

Instantly share code, notes, and snippets.

@westc
westc / toDataURL.js
Last active March 27, 2023 18:03
toDataURL() - Turns a string that can represent a text document and returns the corresponding data URL (AKA data URI).
View toDataURL.js
/**
* Turns a string that can represent a text document and returns the
* corresponding data URL (AKA data URI).
* @param {string} text
* The text to turn into a data URL.
* @param {Object} options
* Optional. An object containing the different options to set.
* @param {boolean=} options.base64
* Optional, defaults to the `false`. Indicates if the returned data URL
* should be base64 encoded.
@westc
westc / parseUrlParams.js
Last active March 27, 2023 16:47
parseUrlParams() - Parses URL parameters.
View parseUrlParams.js
/**
* @param {string} url
* A URL or a query string starting with a question mark that will be parsed.
* @return {{
* first: {[k: string]: (boolean|number|string|undefined)};
* multi: {[k: string]: (boolean|number|string|undefined)[]};
* last: {[k: string]: (boolean|number|string|undefined)};
* }}
* An object containing the URL parameters. The `first` property will be an
* object where a key corresponds to a URL parameter name and the value
@westc
westc / slice.js
Last active March 23, 2023 14:55
slice() - A generator function that allows you to get a slice of the values within the given array-like object.
View slice.js
/**
* Generator function allowing you to get a slice of the values within the given
* array-like object.
* @template T
* @param {T[]} list
* The array or array-like object that will be iterated over.
* @param {Object} options
* Optional. The options to change the order of the returned values.
* @param {number=} options.start
* The starting index within `list`. If this is a negative value the starting
@westc
westc / quoteRegExp.js
Last active March 8, 2023 16:48
quoteRegExp() - This is an example of overloading a function and annotating it with JSDoc.
View quoteRegExp.js
/**
* @type {{
* (input: string): string;
* (input: string, returnRegExp: true): RegExp;
* (input: string, flags: string): RegExp;
* }}
*/
const quoteRegExp = function(input, flags) {
input = input.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
if (flags === true) flags = '';
@westc
westc / irange.js
Last active March 23, 2023 05:58
Definitions for generator functions range() and irange()
View irange.js
/**
* Gives a range of numbers starting with `start` and ending before or at
* `boundary` while incrementing each time by `increment`.
* @param {number} start
* The number at which position to start.
* @param {number} boundary
* The number at which position to stop (inclusive).
* @param {number=} increment
* Defaults to `1`. The amount to increment by between each iteration.
* @yields {number}
@westc
westc / getPathsComparer.js
Created March 7, 2023 04:54
getPathsComparer() - Makes it possible to easily compare multiple nested objects. This was designed to easily be used in conjunction with Array.prototype.sort().
View getPathsComparer.js
/**
* Makes it possible to easily compare multiple nested objects.
* @param {...(number|string|(number|string)[])} paths
* The paths to the values within the 2 arguments passed to the returned
* function. The values at these paths will be compared.
* @returns
* A function which accepts 2 values that will be compared.
*
* @example
* console.log([
@westc
westc / getBinarySearch.js
Last active March 27, 2023 16:11
getBinarySearch() - Takes an array of values and returns a function that can be used to carry out the binary search on those values.
View getBinarySearch.js
/**
* Takes an array of values and returns a function that can be used to
* carry out the binary search on those values. The returned function
* takes one argument to indicate which direction the desired value may
* be found (send a negative number to look further back, a positive
* number to look further ahead or a `0` to return the same value as
* before). It doesn't matter what value you pass the first time you
* call the returned function.
* @template T
* @param {T[]} values
@westc
westc / findIndexInSorted.js
Created February 7, 2023 00:43
findIndexInSorted() - Takes a sorted array of values to search, a target value to look for and a function that will be called to determine if target is found within values. This function uses a binary search to quickly determine if target is inside of values. Outputs the index where the target was found or if not found -1 is returned.
View findIndexInSorted.js
/**
* Takes a sorted array of `values` to search, a `target` value to look for and
* a function that will be called to determine if `target` is found within
* `values`. This function uses a binary search to quickly determine if
* `target` is inside of `values`. Outputs the index where the `target` was
* found or if not found `-1` is returned.
* @template T, V
* @param {V[]} values
* @param {T} target
* @param {(target: T, value: V) => number} check
@westc
westc / selectFiles.js
Created February 6, 2023 14:22
Provides selectFile() and selectFiles() to be able to select one or more files on a webpage.
View selectFiles.js
function getSelectFiles(multiple) {
/**
* @param {selectFile_Options} options
*/
function f(options) {
options = Object(options);
const input = Object.assign(document.createElement('input'), {
type: 'file',
multiple,
onchange: () => options.callback(input.files),
@westc
westc / Personal Study - Desempleo.md
Created January 27, 2023 01:55
Personal Study - Desempleo
View Personal Study - Desempleo.md

Desempleo

Proverbios 3:5,6

  1. Confía en Jehová con todo tu corazón y no te apoyes en tu propio entendimiento.
  2. Tómalo en cuenta en todos tus caminos, y él hará rectas tus sendas.

Mateo 6:25-34

  1. ”Por eso les digo: dejen de angustiarse por su vida, por lo que van a comer y beber; o por su cuerpo, por lo que van a ponerse. Al fin y al cabo, ¿no vale más la vida que el alimento y el cuerpo que la ropa?