Skip to content

Instantly share code, notes, and snippets.

Avatar

Kermin Zahirovic kerminz

View GitHub Profile
@kerminz
kerminz / conditionedGoals.js
Last active Aug 19, 2018
Conditioned Goals for Blogpost
View conditionedGoals.js
// Click on Navigation/Menu & check location
if (window.location.match("url.de/foo/product-category")) {
document.querySelector("#element").addEventListener("mousedown", function() {
sessionStorage.setItem("nav-click", true);
});
}
// Breadcrumb
if (window.location.href.match("url.de/foo/product-overview") && document.referrer.match("url.de/foo/product-category") && sessionStorage.getItem("nav-click")) {
console.log("proceed");
View waitForElement.js
function waitForElement(selector, target, callback) {
// observer target node
var target = document.querySelector(target);
// create new observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
var addedNodes = mutation.addedNodes;
for (var i=0; i < addedNodes.length; i++) {
var node = addedNodes[i];
View whenConditionIsMet.js
function whenConditionIsMet(condition, callback, interval, timeout) {
if (typeof interval !== "number") {
interval = 150;
}
var runInt = setInterval(function() {
try {
if (condition() === true) {
callback();
clearInterval(runInt);
}
@kerminz
kerminz / tensorflow._tip.js
Last active Sep 20, 2018
Tensorflow.js example from blogpost on kerm.in
View tensorflow._tip.js
const trainX = [10.90, 30.60, 50.70, 25.10, 7.80, 42.50, 35.20, 40.40, 25.30, 12.30, 60.20, 47.80, 45.70, 27.50, 15.10, 20.10, 47.50, 32.50, 37.50, 20.00];
const trainY = [2.00, 3.00, 7.00, 2.00, 2.50, 6.00, 5.00, 4.00, 6.00, 1.00, 7.00, 5.50, 7.00, 4.50, 1.50, 4.00, 9.00, 3.00, 6.50, 2.50];
const m = tf.variable(tf.scalar(Math.random()));
const b = tf.variable(tf.scalar(Math.random()));
function predict(x) {
return tf.tidy(function() {
return m.mul(x).add(b);
@kerminz
kerminz / simple-kNN-classifier.js
Created Sep 28, 2018
Simple kNN classifier to determine if a given dog (weight, height) whether is a Labrador oder a Bernese Mountain Dog
View simple-kNN-classifier.js
// Training Data
const weightX = [40,42,42.5,48,50,51,37,38.5,42.5,44.5,45.5,46.5,43.5,51.5,52,47.0,49.5,48.0,48.5,50.5,38,30,35,38,32,30,33,36,36,40,41,37,34,32,31.5,35.5,36,37.5,37,40,38,39]
const heightY = [60,62,62,72,70.5,69.5,55,53.5,61,62,62.5,65,65.5,69,70.5,62.5,59,58,61,64,58,52,54,56,50,48,50.5,51.5,57,59,58,55,52,50,51,49,49.5,52,53,55,52,56.5]
// Label – 0 stands for Berner Sennenhund, 1 for Labrador Retriever
const label = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
const k = 4;
const distances = [];
@kerminz
kerminz / numToCurr.js
Last active Apr 27, 2019
Number To Local Currency Format
View numToCurr.js
// Convert any number to a local currency format with Intl Objects
function numToCurr(number) {
return new Intl.NumberFormat("de-DE", {style: "currency", currency: "EUR"}).format(number)
}
numToCurr(50.00)
// expected output: "50,00 €"
@kerminz
kerminz / single-page-application-flickering-2-yt.js
Last active Apr 27, 2019
Code aus Youtube Video SPA + Flickering
View single-page-application-flickering-2-yt.js
javascript: (function(e, s) {
e.src = s;
e.onload = function() {
jQuery.noConflict();
};
document.head.appendChild(e);
})(document.createElement('script'), '//code.jquery.com/jquery-latest.min.js')
var event = new Event('abtest');
@kerminz
kerminz / restoreConsoleLog.js
Created Apr 28, 2019
Restore console.log()
View restoreConsoleLog.js
// Restore console.log()
javascript: (function() {
var i = document.createElement('iframe');
i.style.display='none';
document.body.appendChild(i);
window.console=i.contentWindow.console;
}());
@kerminz
kerminz / swapElements.js
Created Apr 28, 2019
Swaping two elements in plain JS
View swapElements.js
// Swaping two elements in plain JS
function swapElements(obj1, obj2) {
// create marker element and insert it where obj1 is
var temp = document.createElement("div");
obj1.parentNode.insertBefore(temp, obj1);
// move obj1 to right before obj2
obj2.parentNode.insertBefore(obj1, obj2);
@kerminz
kerminz / single-page-application-1-yt.js
Last active May 8, 2019
Testen auf Single-Page-Application mit DOM Observer (YouTube)
View single-page-application-1-yt.js
var event = new Event('abtest');
// Listen for the event.
window.addEventListener('abtest', function (e) {
console.log("AB Test running...");
console.log("Sign In Page");
}, false);
function waitForElement(selector, target, callback) {