Skip to content

Instantly share code, notes, and snippets.

View igorvolnyi's full-sized avatar

Igor Volnyi igorvolnyi

View GitHub Profile
@igorvolnyi
igorvolnyi / to-https.js
Created March 6, 2022 17:02
Replace all http links to https
Array.from(document.querySelectorAll('a[href^="http://imagetwist.com"]'))
.forEach(link => link.setAttribute('href', link.getAttribute('href').replace(/^http/, 'https')));
@igorvolnyi
igorvolnyi / flatdir.py
Last active September 25, 2021 13:51
Move or copy files from subdirectories into current directory and remove empty subdirectories (in case of moving)
#! /usr/bin/python
'''
Move or copy files from subdirectories of specified directories into them or into current directory
and optionally remove the empty subdirectories (in case of moving).
TODO: add exception handling.
'''
import sys
@igorvolnyi
igorvolnyi / rmemptydirs.sh
Created August 25, 2021 10:17
Remove all empty directories in current directory (bash, zsh)
# Say you have a directory containing thousands of subdirectories. And you want to remove all empty ones.
# NOTE: It is not recursive.
for d in *; do [[ -d "${d}" ]] && [[ `ls "${d}" | wc -l` = "0" ]] && rmdir -v "${d}"; done
@igorvolnyi
igorvolnyi / css-text-smoke-effect.css
Created June 8, 2020 11:05
CSS Text Fade-out Smoke Effect
html,
body,
#page-container {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
}
body {
@igorvolnyi
igorvolnyi / webserver.js
Created February 5, 2020 14:24 — forked from hectorcorrea/webserver.js
web server in node.js
// A very basic web server in node.js
// Stolen from: Node.js for Front-End Developers by Garann Means (p. 9-10)
var port = 8000;
var serverUrl = "127.0.0.1";
var http = require("http");
var path = require("path");
var fs = require("fs");
var checkMimeType = true;
@igorvolnyi
igorvolnyi / index.html
Created January 28, 2020 00:24
Drag-n-drop in pure JavaScript
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>Drag-n-drop на чистом JS</title>
</head>
<body>
@igorvolnyi
igorvolnyi / composition.js
Created January 27, 2020 19:51
Inheritance vs composition in JavaScript
function createProgrammer(name) {
const programmer = { name };
return {
...programmer,
...canCode(programmer)
};
}
function canCode({ name }) {
return {
@igorvolnyi
igorvolnyi / rangeslider.md
Created May 29, 2019 12:21 — forked from loilo/rangeslider.md
Rangeslider

Rangeslider

This is a small Rangeslider library. It's probably not production ready yet (i.e. not been tested in a production project), therefore it's just a Gist and not a fully-blown GitHub repo.

Try it out in this CodePen!

I created this because no existing library met all my criteria:

  • no heavy-weight third-party dependencies (i.e. no jQuery)
@igorvolnyi
igorvolnyi / deepAsync.js
Last active May 29, 2019 12:19 — forked from loilo/deepAsync.js
Deeply resolves all promises in a data structure
// Arbitrarily nested object containing Promises goes in
// Plain data structure comes out
async function deepAsync (object) {
// Walk arrays
if (Array.isArray(object)) {
return Promise.all(object.map(async item => await deepAsync(item)))
// Walk objects
} else if (object instanceof Object) {
return Object
@igorvolnyi
igorvolnyi / bubble.md
Created May 29, 2019 12:06 — forked from loilo/bubble.md
Make Vue events bubble

Make Vue events bubble

Vue events don't bubble the component tree themselves. However when writing wrapper components this can be the desired behaviour.

This code registers a global bubble directive which allows to re-emit all given events:

Let's say we want to bubble events start, accelerate and brake of our component Car.

Without any help, we'd roughly have to do this: