Skip to content

Instantly share code, notes, and snippets.

Konrad Dzwinel kdzwinel

Block or report user

Report or block kdzwinel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kdzwinel
kdzwinel / main.js
Last active Dec 12, 2019
List all undefined CSS classes
View main.js
/*
This script attempts to identify all CSS classes mentioned in HTML but not defined in the stylesheets.
In order to use it, just run it in the DevTools console (or add it to DevTools Snippets and run it from there).
Note that this script requires browser to support `fetch` and some ES6 features (fat arrow, Promises, Array.from, Set). You can transpile it to ES5 here: https://babeljs.io/repl/ .
Known limitations:
- it won't be able to take into account some external stylesheets (if CORS isn't set up)
- it will produce false negatives for classes that are mentioned in the comments.
@kdzwinel
kdzwinel / optimizely.js
Created Jun 17, 2015
Calculating A/B Test Sample Size
View optimizely.js
"use strict";
//based on https://www.optimizely.com/resources/sample-size-calculator/
function getSampleSize() {
let effect = 0.05; // Minimum Detectable Effect
let significance = 0.95; // Statistical Significance
let conversion = 0.05; // Baseline Conversion Rate
let c = conversion - (conversion * effect);
let p = Math.abs(conversion * effect);
@kdzwinel
kdzwinel / catch-globals.js
Last active Oct 10, 2019
Unfinished globals proxy
View catch-globals.js
function evalCode(code) {
const func = new Function ('window', `with (window) { ${code} }`);
const obj = {};
const proxy = new Proxy(obj, {
get(target, propKey, receiver) {
console.log(`GET ${String(propKey)}`);
if (propKey === 'window') return proxy;
return Reflect.get(window, propKey, receiver);
},
set(target, propKey, value, receiver) {
@kdzwinel
kdzwinel / trilateration.js
Created Jan 3, 2014
Simple trilateration algorithm implementation in JavaScript.
View trilateration.js
function getTrilateration(position1, position2, position3) {
var xa = position1.x;
var ya = position1.y;
var xb = position2.x;
var yb = position2.y;
var xc = position3.x;
var yc = position3.y;
var ra = position1.distance;
var rb = position2.distance;
var rc = position3.distance;
@kdzwinel
kdzwinel / filter-out-ads.js
Last active Mar 22, 2018
TrackJS custom onError callback that tries to filter out noise from ads
View filter-out-ads.js
// ES5 for compat
window._trackJs.onError = function(error) {
try {
var fileURL = new URL(error.file);
if (fileURL) {
// safelist includes current domain + some third-parties we want to track
var safe = domainSafelist.some(function (domain) {
return fileURL.host.endsWith(domain);
});
@kdzwinel
kdzwinel / lhjson.js
Created Jan 25, 2018
__LIGHTHOUSE_JSON__ analysis script
View lhjson.js
(function() {
function strSize(obj) {
const string = JSON.stringify(obj);
return string ? string.length : 0;
}
const lhj = __LIGHTHOUSE_JSON__;
const fullSize = strSize(lhj);
const maxLevels = 5;
@kdzwinel
kdzwinel / kata.js
Last active Jan 19, 2018
Code kata featuring: fetch, promises, array.sort, array.reduce, array.map
View kata.js
// 1) fetch members of polish parlament (poslowie)
// 2) group them by occupation
// 3) sort occupations by number of members and occupation name
// 4) get top 5 entries
// 5) print result on the screen
(function() {
'use strict';
const POSLOWIE_ENDPOINT = 'https://api-v3.mojepanstwo.pl/dane/poslowie/';
@kdzwinel
kdzwinel / ps4devtools.js
Created Oct 8, 2017
Gamepad - Chrome DevTools integration
View ps4devtools.js
(function(){
let gamepad = null;
let loopInterval = null;
window.addEventListener("gamepadconnected", connectHandler);
window.addEventListener("gamepaddisconnected", disconnectHandler);
function connectHandler(e) {
if (!gamepad) {
@kdzwinel
kdzwinel / get-selector-simple.js
Created Dec 8, 2017
Simple alternative to the axe-core getSelector
View get-selector-simple.js
const commonNodes = [
'div', 'span', 'p',
'b', 'i', 'u', 'strong', 'em',
'h2', 'h3',
];
/**
* @param {Array<string>} attributes
* @returns {Map<string, string>}
*/
View index.html
<head>
...
<meta name="viewport" content="width=device-width">
...
</head>
You can’t perform that action at this time.