Skip to content

Instantly share code, notes, and snippets.

View inter-coder's full-sized avatar

Dusan Krstic inter-coder

  • Institute for public health of Vojvodina, BeeMon Solution
  • Serbia
View GitHub Profile
@inter-coder
inter-coder / copy2clipboard.js
Last active November 14, 2017 13:12
Copy to clipboard as typing
document.querySelector("input").addEventListener('keyup',function(){
var pom=document.createElement("textarea");
document.body.appendChild(pom);
pom.value=this.value;
pom.select();
try {
document.execCommand('copy');
pom.parentNode.removeChild(pom);
this.focus();
}
@inter-coder
inter-coder / dependencies.js
Last active October 1, 2019 06:56
Class for providing the sequence of interdependent scripts that should be loaded into the Web page
var dps=function(p){
this.desc="Class for providing the sequence of interdependent scripts that should be loaded into the Web page";
this.loadCSS=function(url,cb){
var style=document.createElement("link");
style.href=url+"?"+new Date().getTime();
style.rel="stylesheet";
document.head.appendChild(style);
style.onload=function(){if(cb!=undefined)cb(style);};
};
this.loadJS=function(url,cb){
@inter-coder
inter-coder / tableToExcel.js
Created May 14, 2015 19:13
Easy way to transfer HTML tables to Excel files, but with limited possibilities of customization
function tableToExcel(p){
var dlink=document.createElement('a');
document.body.appendChild(dlink);
var uri='data:application/vnd.ms-excel;base64,';
var template='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8"></head><body><table>{table}</table></body></html>';
var base64=function(s){return window.btoa(unescape(encodeURIComponent(s)));};
var format=function(s,c){return s.replace(/{(\w+)}/g,function(m,p){return c[p];});};
if(!p.table.nodeType) p.table = document.getElementById(p.table);
var ctx = { worksheet: p.worksheet || 'Worksheet', table: p.table.innerHTML };
dlink.h
@inter-coder
inter-coder / changeValueDetection.js
Last active December 17, 2019 17:03
changeValueDetection - Observer
HTMLElement.prototype.changeValueDetection = function(){
var element=this;
var oldVal=element.value;
var GUID = function (){var S4 = function () {return(Math.floor(Math.random() * 0x10000).toString(16));};return (S4() + S4() + "-" +S4() + "-" +S4() + "-" +S4() + "-" +S4() + S4() + S4());};
var uiq="GUID-"+GUID();
if(window.changeValueDetectionEvents==undefined)window.changeValueDetectionEvents=new Event('changeValueDetection');
element.setAttribute("data-uiq",uiq);
window[uiq]=setInterval(function(){
if(element.value!=oldVal){
oldVal=element.value;element.setAttribute("value",oldVal);
@inter-coder
inter-coder / int2roman.js
Created July 6, 2021 10:23
convert integer to roman numeral javascript
Object.defineProperty(Number.prototype,'int2roman',{
get: function(){
const map = {
M: 1000,
CM: 900,
D: 500,
CD: 400,
C: 100,
XC: 90,
L: 50,
@inter-coder
inter-coder / heatMapColorforValue.js
Created July 6, 2021 10:29
Calculating heat map colours
function heatMapColorforValue(value,alpha,max){
alpha=100*alpha;
value=value/max;
var h = parseInt((1.0 - value) * 240)
return "hsl(" + h + "deg 100% 50% / "+alpha+"%)";
}
@inter-coder
inter-coder / ArrayLoop.html
Last active December 13, 2022 06:34
Polyfill array object in order to enable the loop in steps
<html>
<body>
<span id='counter' style='position:fixed;bottom:10px;right:10px;color:white;background:black;padding:10px;'></span>
</body>
<script>
Object.defineProperty(Array.prototype,'onPassLast',{//function to execute after the last pass of the array element
get: function(){this.onPassLastFN(this)},
set: function(fn){this.onPassLastFN=fn;}
});
@inter-coder
inter-coder / disable_dev-tool.js
Last active December 23, 2022 08:53
Clearing the console alone is not enough, and a better approach is to disable the developer tool from being opened in any meaningful way
(function() {
'use strict';
Object.getOwnPropertyNames(console).filter(function(property) {
return typeof console[property] == 'function';
}).forEach(function (verb) {
console[verb] =function(){return 'Sorry, for security reasons...';};
});
window.addEventListener('devtools-opened', ()=>{
// do some extra code if needed or ...
// maybe even delete the page, I still like to add redirect just in case