Skip to content

Instantly share code, notes, and snippets.

View igorvolnyi's full-sized avatar

Igor Volnyi igorvolnyi

View GitHub Profile
@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 / 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:

@igorvolnyi
igorvolnyi / magic-methods.js
Created May 29, 2019 12:04 — forked from loilo/magic-methods.js
PHP Magic Methods in JavaScript
function magicMethods (clazz) {
// A toggle switch for the __isset method
// Needed to control "prop in instance" inside of getters
let issetEnabled = true
const classHandler = Object.create(null)
// Trap for class instantiation
classHandler.construct = (target, args) => {
// Wrapped class instance
@igorvolnyi
igorvolnyi / split-pull-requests.md
Created May 29, 2019 12:03 — forked from loilo/split-pull-requests.md
Split a large pull request into two
@igorvolnyi
igorvolnyi / DomKeepAlive.md
Created May 29, 2019 12:00 — forked from loilo/DomKeepAlive.md
Keep pre-existing DOM nodes alive inside Vue components

Keep pre-existing DOM alive in Vue

For my use cases, Vue has one critical pitfall: I frequently have/want to use Vue components with <slot>s as wrappers for content from a CMS which I don't have control over. That is, the content comes over the wire via HTML, and I have to activate Vue for some of it.

<interactive-element>
  <p>Slot content I don't have control over</p>
</interactive-element>

I need to activate the Vue component <interactive-element>.

@igorvolnyi
igorvolnyi / pass-slots.md
Created May 29, 2019 11:56 — forked from loilo/pass-slots.md
Vue: Pass Slots through from Parent to Child Components

Vue: Pass Slots through from Parent to Child Components

The Situation

  • We've got some components A, B and C which provide different slots.
    const A = {
      template: `<div><slot name="a">Default A Content</slot></div>`
    }

const B = {

touch ~/.zsh_functions
vim ~/.zsh_functions
function jcurl() {
  curl -s "$@" | json | pygmentize -l json
}

function tojson(){