Skip to content

Instantly share code, notes, and snippets.

View MartinMuzatko's full-sized avatar
🐈

Martin Muzatko MartinMuzatko

🐈
View GitHub Profile
@aradnom
aradnom / riotjs-router.js
Created July 15, 2015 05:43
First attempt at a simple router in Riot.js.
// Create new observable for watching route changes
var Router = riot.observable();
// Process routes on both route change and initial load
riot.route( processRoute );
riot.route.exec( processRoute );
// Expose the Router object
riot.mixin( 'Router', Router );
@MartinMuzatko
MartinMuzatko / webcam.js
Created November 17, 2016 15:17
WebRTC Instant Webcam
navigator.mediaDevices.getUserMedia({audio:0,video:1})
.then(function(mediaStream) {
document.body.innerHTML='<video>'
var video = document.querySelector('video')
video.srcObject = mediaStream
video.onloadedmetadata = function(e) {
video.play()
}
})
@eirikb
eirikb / load-vue-components-from-folder.js
Created May 24, 2017 19:24
Load all Vue components from a given folder, no need for an "index.js"-file
const req = require.context('./components/', true, /\.(js|vue)$/i);
req.keys().map(key => {
const name = key.match(/\w+/)[0];
return Vue.component(name, req(key))
});
@sumardi
sumardi / gist:5559896
Created May 11, 2013 12:56
Subdirectory checkouts with Git sparse-checkout
# New repository
mkdir <repo> && cd <repo>
git init
git remote add –f <name> <url>
git config core.sparsecheckout true
echo some/dir/ >> .git/info/sparse-checkout
echo another/sub/tree >> .git/info/sparse-checkout
git pull <remote> <branch>
# Existing repository
@bendrucker
bendrucker / test.js
Created October 1, 2014 09:52
Truncate data during tests with knex
'use strict';
var Promise = require('bluebird');
var knex = require('../../src/db').knex;
var tables = [
'organizations',
'campaigns',
'donors',
'pledges',
@domenic
domenic / portable-node.md
Created May 25, 2012 21:03
Tips for Writing Portable Node.js Code

Node.js core does its best to treat every platform equally. Even if most Node developers use OS X day to day, some use Windows, and most everyone deploys to Linux or Solaris. So it's important to keep your code portable between platforms, whether you're writing a library or an application.

Predictably, most cross-platform issues come from Windows. Things just work differently there! But if you're careful, and follow some simple best practices, your code can run just as well on Windows systems.

Paths and URLs

On Windows, paths are constructed with backslashes instead of forward slashes. So if you do your directory manipulation

@joyrexus
joyrexus / README.md
Created March 28, 2014 16:59
Nested grouping of arrays

nest.js

A multi-level groupBy for arrays inspired by D3's nest operator.

Nesting allows elements in an array to be grouped into a hierarchical tree structure; think of it like the GROUP BY operator in SQL, except you can have multiple levels of grouping, and the resulting output is a tree rather than a flat table. The levels in the tree are specified by key functions.

See this fiddle for live demo.

@GianlucaGuarini
GianlucaGuarini / post-merge
Last active August 22, 2023 20:54 — forked from sindresorhus/post-merge
Git hook that gets triggered after any 'git pull' whenever one of the files specified has changed. Useful to update any web application dependency using bower npm or composer
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# forked by Gianluca Guarini
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep -E --quiet "$1" && eval "$2"
}
@davatron5000
davatron5000 / the-state-of-element-container-queries.md
Last active August 23, 2023 15:43
The State of Element/Container Queries

The State of Container Queries

tl;dr Developers would like the idea to style components based on a parent's width rather than depend solely on the viewport media query. This would allow modular components to style themselves while being agnostic to the viewport.

There is currently a lot of developer interest in getting a feature like Container Queries (née "Element Queryies") shipped in a browser.

2-min Catchup

Here are official'ish documents to outline the developer community's desires.