Skip to content

Instantly share code, notes, and snippets.

@idettman
idettman / get-obj-type.js
Last active October 3, 2025 18:53
Get Object Type using Object.toString()
function getType(obj) {
const type = Object.prototype.toString.call(obj);
// toString returns '[object <type>]'
// I only want the <type> value, so skip '[object ' chars and ending ']' char
return type.substring(7, type.length-1);
}
const tests = [
'str: ' + getType('foobar'),
'num: ' + getType(10),
@idettman
idettman / request-animation-frame.js
Created October 3, 2025 16:01
Old request animation frame code
function animationLoop(render, element) {
const running, lastFrame = +new Date;
function loop(now) {
// stop the loop if render returned false
if (running !== false) {
requestAnimationFrame(loop, element);
const deltaT = now - lastFrame;
// do not render if deltaT is too high
if ( deltaT < 160 ) {
running = render(deltaT);
@idettman
idettman / animation-performance-test.js
Last active October 3, 2025 15:53
HTML Animation Performance Test
const boxes = [];
const button = document.getElementById("toggle-button");
const boxContainer = document.getElementById("box-container");
const animationType = document.getElementById("type");
// create boxes
for (let i = 0; i < 1000; i++) {
const div = document.createElement("div");
div.classList.add("css-animation");
div.classList.add("box");
@idettman
idettman / example-module-w-import-maps.js
Last active October 3, 2025 15:36
Test if Import maps type is supported on the html script element
/*
The import map is defined using a JSON object inside a <script> element with the type attribute set to importmap.
Note that an import map only applies to the document — the specification does not cover how to apply an import map in a worker or worklet context.
With this map you can now use the property names above as module specifiers.
If there is no trailing forward slash on the module specifier key then the whole module specifier key is matched and substituted.
For example, below we match bare module names, and remap a URL to another path.
*/
// Bare module names as module specifiers
@idettman
idettman / js-testing.js
Last active October 29, 2025 04:43
JavaScript Interview EP
/**
* @param {Object} obj
* @returns {string}
*/
function getFirstKey(obj) {
return Object.keys(obj)[0];
}
/**
* @type {Object}
/*
* Module for getting and setting Prebid configuration.
*/
/**
* @typedef {Object} MediaTypePriceGranularity
*
* @property {(string|Object)} [banner]
* @property {(string|Object)} [native]
* @property {(string|Object)} [video]
@idettman
idettman / mergeConfig.js
Created May 12, 2021 06:24
prebid global method mergeConfig
function mergeConfig(config) {
// exit on invalid config
if (!config) return;
// default behavior is override using new values except for ortb2 which appends to certain array props
const existingConfig = utils.getConfig() || {};
if (config.ortb2) {
const existingOrtb2 = existingConfig.ortb2 || { user: { data: [] } };
if (config.ortb2.site) {
@idettman
idettman / smooth-mouse.js
Last active October 29, 2025 04:51
Smooth mouse
/*
distance you are computing is NOT used. (in fact only to see if we get less than a distance of 1, which can be done much easier/faster).
The value (v) that we want to become target value (tv) Choose k, the proportion ( within [ 0 ; 1.0 ] ) of the actual value you want to keep, the rest you will update.
For example if you choose keep 90% and you change 10% for each movement, then in 10 frames you reached goal.
v = k * v + (1 - k ) * tv;
expl : v = 0.9 * v + 0.1 * tv;
*/
/**
* @param {Object} obj
* @returns {string}
*/
function getFirstKey(obj) {
return Object.keys(obj)[0];
}
@idettman
idettman / prebid-pull-request-example.md
Last active April 8, 2020 18:36
Prebid.js Pull Request Example

Type of change

  • Other

Description of change

Updated Prebid Server bid adapter to check for the site object in the prebid configuration. If exists, this will be copied over into the request and publisher/page will either be created properties or will overwrite existing config defined values. This will allow other OpenRTB fields within the site object to be passed to Prebid Server, i.e. site.content

Other information

#3783 pass site.{} into prebid server request