Skip to content

Instantly share code, notes, and snippets.

Avatar

Dusan Krstic inter-coder

  • Institute for public health of Vojvodina, BeeMon Solution
  • Serbia
View GitHub Profile
@inter-coder
inter-coder / heatMapColorforValue.js
Created Jul 6, 2021
Calculating heat map colours
View heatMapColorforValue.js
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 / int2roman.js
Created Jul 6, 2021
convert integer to roman numeral javascript
View int2roman.js
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 / copy2clipboard.js
Last active Nov 14, 2017
Copy to clipboard as typing
View copy2clipboard.js
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 / c2l2c.js
Created Apr 25, 2017
Preslovljavanje LATINICE <=> Ћирилицу
View c2l2c.js
Object.defineProperty(String.prototype,'lat2cir',{get:function(){return this.toString().replace(/A/g,"А").replace(/B/g,"Б").replace(/V/g,"В").replace(/G/g,"Г").replace(//g,"Џ").replace(//g,"Џ").replace(/Đ/g,"Ђ").replace(/DJ/g,"Ђ").replace(/Dj/g,"Ђ").replace(/D/g,"Д").replace(/E/g,"Е").replace(/Ž/g,"Ж").replace(/Z/g,"З").replace(/I/g,"И").replace(/K/g,"К").replace(/LJ/g,"Љ").replace(/Lj/g,"Љ").replace(/L/g,"Л").replace(/M/g,"М").replace(/NJ/g,"Њ").replace(/Nj/g,"Њ").replace(/J/g,"Ј").replace(/N/g,"Н").replace(/O/g,"О").replace(/P/g,"П").replace(/R/g,"Р").replace(/S/g,"С").replace(/T/g,"Т").replace(/Ć/g,"Ћ").replace(/U/g,"У").replace(/F/g,"Ф").replace(/H/g,"Х").replace(/C/g,"Ц").replace(/Č/g,"Ч").replace(/Š/g,"Ш").replace(/a/g,"а").replace(/b/g,"б").replace(/v/g,"в").replace(/g/g,"г").replace(//g,"џ").replace(/đ/g,"ђ").replace(/dj/g,"ђ").replace(/d/g,"д").replace(/e/g,"е").replace(/ž/g,"ж").replace(/z/g,"з").replace(/i/g,"и").replace(/k/g,"к").replace(/lj/g,"љ").replace(/l/g,"л").replace(/m/g,"м").replace
View DoesServiceExist.py
#!/usr/bin/env python
# Determining whether the services are working at a remote location
from socket import *
def DoesServiceExist(host, port):
targetIP = gethostbyname(host)
s = socket(AF_INET, SOCK_STREAM)
s.settimeout(1)
result = s.connect_ex((targetIP,port))
s.close()
@inter-coder
inter-coder / ArrayLoop.html
Last active Aug 31, 2016
Polyfill array object in order to enable the loop in steps
View ArrayLoop.html
<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',{
get: function(){this.onPassLastFN(this)},
set: function(fn){this.onPassLastFN=fn;}
});
@inter-coder
inter-coder / ajax_get.js
Created Mar 15, 2016
Ajax for loading documents from local and crossdomain
View ajax_get.js
var ajax_get = function(p) {
var cors = false;
if (p.url.split("//").length == 1) {
var url = p.url + "?" + this.timeStamp();
} else {
cors = true;
var url = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html WHERE url="' + p.url + '" AND xpath="//body"') + '&format=xml&callback=cb';
}
return new Promise(function(resolve, reject) {
var xhttp = new XMLHttpRequest();
@inter-coder
inter-coder / changeValueDetection.js
Last active Dec 17, 2019
changeValueDetection - Observer
View changeValueDetection.js
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 / btngroup.js
Last active Sep 25, 2015
Simple class for creating bootstrap button groups.
View btngroup.js
var btngroup=function(){
this.desc="Simple class for creating bootstrap button groups";
};
btngroup.prototype={
addBtnGroup:function(p){
p.container.innerHTML="";
p.bscont=document.createElement("div");
p.bscont.setAttribute("class","btn-group");
p.bscont.setAttribute("role","group");
p.bscont.setAttribute("aria-label","...");
@inter-coder
inter-coder / dependencies.js
Last active Oct 1, 2019
Class for providing the sequence of interdependent scripts that should be loaded into the Web page
View dependencies.js
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){