Skip to content

Instantly share code, notes, and snippets.

View Alexgalinier's full-sized avatar

Milodiw Alexgalinier

View GitHub Profile
@Alexgalinier
Alexgalinier / spawnP.js
Created September 6, 2018 06:53
spawn with promise
const { spawn } = require('child_process');
const spawnP = async command => {
return new Promise((res, rej) => {
const cmdParts = command.split(' ');
const cmdSpawm = spawn(
cmdParts[0],
cmdParts.length > 1 ? cmdParts.slice(1) : [],
{
stdio: 'inherit'
@Alexgalinier
Alexgalinier / pick.js
Last active August 16, 2018 05:41
Deep Pick
const typeOf = _ => Object.prototype.toString.call(_);
// Result can be used with db.collection.find : PARTIALLY
const arrayToSchema = keys =>
keys.reduce((schema, _) => {
if (_.indexOf('.') > -1) {
const [key, rest] = _.split('.');
schema[key] = {
...schema[key],
...arrayToSchema([rest]),
@Alexgalinier
Alexgalinier / package.json
Last active March 14, 2018 07:23
package.json skeleton
{
"name": "...",
"version": "1.0.0",
"description": "...",
"main": "index.js",
"scripts": {
"build": "...",
"test": "...",
"deploy": "..."
},
@Alexgalinier
Alexgalinier / filterAndGroup.js
Created September 25, 2017 06:38
Filter an array of people by age and group them by gender.
function filterAndGroup(data, filterFunc, groupByKey) {
return data.reduce((acc, item) => {
if (filterFunc(item)) {
if (item[groupByKey] in acc) {
acc[item[groupByKey]].push(item);
} else {
acc[item[groupByKey]] = [item];
}
}
@Alexgalinier
Alexgalinier / JS: Async load js file
Created September 24, 2014 06:36
Load a script manually with "async" attribute
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'http://yourdomain.com/script.js';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);
@Alexgalinier
Alexgalinier / gist:5003922
Last active December 14, 2015 01:09
CSS: keyframe with prefixs
@-webkit-keyframes {name} {
0% { {from} }
100% { {to} }
}
@-moz-keyframes {name} {
0% { {from} }
100% { {to} }
}
@-o-keyframes {name} {
0% { {from} }
@Alexgalinier
Alexgalinier / gist:4707701
Last active December 12, 2015 03:29
HTML: Starting file
<!doctype html>
<html class="no-js" lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="http://alexgalinier.com/static/images/alexgalinier-site-favicon_32x32.png" /> <!-- 32x32 image-->
<!-- Safari standalone web app config -->