Skip to content

Instantly share code, notes, and snippets.

@through-a-haze
through-a-haze / stringifyAnything.js
Last active June 1, 2025 22:07
Converts any JavaScript value to its string representation
/**
* Converts any JavaScript value to its string representation
* @param {*} value any value to convert to string
* @returns {string} string representation of the value
*/
exports.stringifyAnything = function (value) {
try {
// handle basic primitives
if (value === undefined) return 'undefined';
if (value === null) return 'null';
@through-a-haze
through-a-haze / PDFViewer.js
Last active July 21, 2024 22:36
A module that uses PDF.js to view, zoom in/out, and switch pages of PDF files.
function PDFViewer({ bufferData, onAllPagesViewed, onNextPage, onPrevPage } = {}) {
const container = document.getElementById('pdf-viewer-container');
if (!container)
throw new Error(
'PDFViewer: Element with id "pdf-viewer-container" not found. Did you forget to add it to your HTML?'
);
const _bufferData = bufferData || container.dataset.bufferData;
if (!_bufferData)
throw new Error(
const { ObjectId } = require('mongodb'); // optional
const VALUE_CREATED = 'created';
const VALUE_UPDATED = 'updated';
const VALUE_DELETED = 'deleted';
const VALUE_UNCHANGED = 'unchanged';
const isFunction = function (x) {
return Object.prototype.toString.call(x) === '[object Function]';
};
@through-a-haze
through-a-haze / getNextDate.js
Last active July 22, 2021 21:42
Calculates next date in seconds/milliseconds (depends on unix option) based on start and step params without dependencies
/**
* Calculates next date in seconds/milliseconds (depends on unix option)
* based on start and step params
*
* @param {number} start date in seconds (unix = true), or milliseconds (unix = false)
* @param {number} step in hours/minutes/seconds
* @param {number} [finish=0] date in seconds (unix = true), or milliseconds (unix = false)
* also if this param is passed then it will calculate the next date after this date
* @param {*} [options] { unix: true, stepType: 'hours' }
* @returns {number}
@through-a-haze
through-a-haze / Oracle_BLOBs_to_files.sql
Created September 23, 2020 17:12
Save Oracle BLOBs from a table to files (pl/sql). You have to setup EXPORT_DIR before by "CREATE DIRECTORY EXPORT_DIR AS '/path/to/your/directory';"
DECLARE
file_exists_index NUMBER(38,0) := 0;
file_exists NUMBER(38,0) := 0;
v_amount NUMBER(38,0);
v_start NUMBER(38,0);
v_size CONSTANT NUMBER( 5,0) := 32767;
v_len NUMBER(38,0);
v_buffer RAW(32767);
v_file UTL_FILE.FILE_TYPE;
v_filename VARCHAR2(32767);
@through-a-haze
through-a-haze / prepare-commit-msg
Last active July 22, 2021 19:23
Prepend the commit with a number of the task/issue/card taken from the branch name
#!/bin/bash
# e.g. if the branch name is feature/123-new-awesome-feature
# after running
# git commit -am 'add a new super feature'
# the commit will look as '[123] add a new super feature'
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
@through-a-haze
through-a-haze / parse_dotenv.bash
Created December 3, 2019 08:44 — forked from judy2k/parse_dotenv.bash
Parse a .env (dotenv) file directly using BASH
# Pass the env-vars to MYCOMMAND
eval $(egrep -v '^#' .env | xargs) MYCOMMAND
# … or ...
# Export the vars in .env into your shell:
export $(egrep -v '^#' .env | xargs)
@through-a-haze
through-a-haze / isInRect.js
Created July 22, 2019 17:26
A function to check if the mouse cursor is inside a canvas rectangle.
// initial values are given as an example
const rect = {
x: 10,
y: 10,
width: 100,
height: 30
}
/**
* @param {number} x - mouse X position inside the canvas
@through-a-haze
through-a-haze / isOnBorders.js
Last active July 22, 2019 12:44
A function to check if the mouse cursor is on canvas rectangle borders with given lineWidth.
// initial values are given as an example
const lineWidth = 6;
const rect = {
x: 10,
y: 10,
width: 100,
height: 30
}
/**

Keybase proof

I hereby claim:

  • I am through-a-haze on github.
  • I am through_a_haze (https://keybase.io/through_a_haze) on keybase.
  • I have a public key ASBOY7vc18v2wsuipB-k92pmcIxNxrmtdroo_wPmXXT7jQo

To claim this, I am signing this object: