Skip to content

Instantly share code, notes, and snippets.

@sr9yar
sr9yar / gist:2af4630f0a9538e373fd8b28be89d836
Last active August 17, 2020 06:10
Detect Location Change
var oldHref = document.location.href;
window.onload = function() {
var bodyList = document.querySelector("body");
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (oldHref != document.location.href) {
oldHref = document.location.href;
console.log("LOCATION CHANGE:", oldHref);
@sr9yar
sr9yar / gist:45036c77d3a692eb33df4e9d99d42b23
Created January 8, 2021 16:09
Download a file by URL with JS
/**
* Version 1
*/
download(doc?: any): void {
const filename = 'https://via.placeholder.com/350x150';
const link = document.createElement('a');
link.style.display = 'none';
link.href = filename;
link.target = '_blank';
@sr9yar
sr9yar / gist:46d07785eac774682c681acf1eeb1a47
Created February 20, 2021 12:17
Scroll to top animation with js
goToTop() {
const scrollToTop = window.setInterval(() => {
const pos = window.pageYOffset;
if (pos > 0) {
window.scrollTo(0, pos - 20);
} else {
window.clearInterval(scrollToTop);
}
FROM debian:stable-slim
RUN apt update
RUN apt install -y \
curl git wget python3 \
zip unzip apt-transport-https \
ca-certificates gnupg clang \
cmake ninja-build pkg-config \
libgconf-2-4 gdb libstdc++6 \
libglu1-mesa fonts-droid-fallback \
@sr9yar
sr9yar / measure-code-execution-in-js.js
Created April 10, 2025 08:48
Simple code execution measurement
const start = new Date();
const hrStart = process.hrtime();
// process.hrtime();
// https://nodejs.org/api/process.html#processhrtimetime
// [seconds, nanoseconds]
setTimeout(() => {
const end = new Date() - start;