Skip to content

Instantly share code, notes, and snippets.

@MWarCZ
MWarCZ / Ukázka funkci.md
Last active March 10, 2024 09:31
SQL PV
-- Přejmenování sloupců
SELECT 'abc' AS Text, 123 AS 'Číslo 123';

-- Převod desetinného čísla na celé číslo
SELECT CONVERT(INT, 11.526); -- 11.526 => 11
-- Převod celého čísla na desetinné číslo
SELECT CONVERT(REAL, 11); -- 11 => 11.000
@MWarCZ
MWarCZ / lazyLoadScript.js
Last active February 6, 2022 14:30
Lazy loading scripts after the first user interaction with the site.
// Source: https://marketingmakers.net/en/how-to-improve-zopim-zendesk-chat-load-time-or-any-other-external-javascript/
// Lazy loading scripts after the first user interaction with the site
function setupInteractLoad(fn) {
function fn_tmp() {
destroyInteractLoadEvent(fn_tmp);
fn();
}
createInteractLoadEvent(fn_tmp);
}
@MWarCZ
MWarCZ / copyToClipboard.js
Last active February 6, 2022 14:29
Copy content of element to clipboard.
function copyToClipboard(elWitchText) {
if(navigator.clipboard) {
// For newer web browser
var value = elWitchText.value ? elWitchText.value : elWitchText.innerText;
return navigator.clipboard.writeText(value)
}
else {
// For older web browser (<2020)
var tmp = document.createElement('textarea')
tmp.value = elWitchText.value ? elWitchText.value : elWitchText.innerText;
@MWarCZ
MWarCZ / IntersectionObserverWithDirection.js
Last active November 4, 2024 06:17
Intersection observer with detection of vertical scroll direction.
function createIntersectionObserver(callback, opts = { root: null, rootMargin: '0px', threshold: 0}) {
var previousY = new Map();
var observer = new IntersectionObserver(function(entries, observer){
console.log(entries);
entries.forEach(function (entry) {
var currY = entry.boundingClientRect.y;
var prevY = previousY.get(entry.target);
if(currY<prevY) { /* scroll down */ entry.scrollDirectionY = 'down'; }
@MWarCZ
MWarCZ / ResTable.js
Last active August 19, 2021 19:55
Responsive table
function ResTable(tableSelector, options = {}) {
var opts = Object.assign({
breakpoint: '600px',
separator: ': ',
}, options)
this.tableSelector = tableSelector
this.style = document.createElement('style')
document.head.append(this.style)
this.setStyle(opts.breakpoint, opts.separator)
this.table = document.querySelector(tableSelector)
@MWarCZ
MWarCZ / explorer.sh
Created September 7, 2019 10:04
Script for WLS on Windows 10. Useful script for opening file from bash with windows explorer.
#! /usr/bin/env bash
# Nastaveni barev, pokud jde vystup na terminal.
# Set colors if output is terminal.
if [ -t 1 ] ; then
cl_ok="\e[1;32m"
cl_ko="\e[1;31m"
cl_h1="\e[1;36m"
cl_cl="\e[0m"
fi