Skip to content

Instantly share code, notes, and snippets.

Alex Galinier Alexgalinier

Block or report user

Report or block Alexgalinier

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Alexgalinier
Alexgalinier / spawnP.js
Created Sep 6, 2018
spawn with promise
View spawnP.js
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'
View pick.js
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 Mar 14, 2018
package.json skeleton
View package.json
{
"name": "...",
"version": "1.0.0",
"description": "...",
"main": "index.js",
"scripts": {
"build": "...",
"test": "...",
"deploy": "..."
},
@Alexgalinier
Alexgalinier / filterAndGroup.js
Created Sep 25, 2017
Filter an array of people by age and group them by gender.
View filterAndGroup.js
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 Sep 24, 2014
Load a script manually with "async" attribute
View JS: Async load js file
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);
View sm-annotated.html
<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 Dec 14, 2015
CSS: keyframe with prefixs
View gist:5003922
@-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 Dec 12, 2015
HTML: Starting file
View gist:4707701
<!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 -->
You can’t perform that action at this time.