Skip to content

Instantly share code, notes, and snippets.

View sderosiaux's full-sized avatar
💭
Need help?

Stéphane Derosiaux sderosiaux

💭
Need help?
View GitHub Profile
@sderosiaux
sderosiaux / push-to-git
Last active August 29, 2015 14:17
Transform a classic node project folder into a git repo
## Project in ./project (with its classic packages.json and subfolders node_modules etc.) non-git
# The simpler solution would be to
# - create a remote repo on github.com
# - clone it
# - add your files into
# - commit/push
#
# clone inject already all the necessary config to work
@sderosiaux
sderosiaux / Default (Windows).sublime-keymap
Last active August 29, 2015 14:22
My SublimeText Configuration
[
{ "keys": ["f2"], "command": "side_bar_move" }, // f2 just to rename the selected file
]
@sderosiaux
sderosiaux / .eslintrc
Last active August 29, 2015 14:22
.eslintrc with babel-eslint + eslint-plugin-react
{
"env": {
"browser": true,
"node": true
},
"parser": "babel-eslint",
"plugins": [
"eslint-plugin-react"
],
"rules": {
@sderosiaux
sderosiaux / funfunc.js
Last active August 29, 2015 14:23
Fun with functional and hierarchy
const nodes = [{
name: 'A',
nodes: [{
name: 'x'
}]
}, {
name: 'B',
expanded: true,
nodes: [{
name: 'x',
@sderosiaux
sderosiaux / foreachAsync.js
Last active August 29, 2015 14:24
Async, Await, Promises, foreachAsync
const echo = (msg, delay = 50) => new Promise((resolve) => setTimeout(() => resolve(msg), delay));
const echoUpperCase = (msg, delay = 50) => new Promise((resolve) => setTimeout(() => resolve(new Date().toISOString() + ' ' + msg.toUpperCase()), delay));
const foreachAsync = async (array, cb) => { for (let i = 0, l = array.length; i < l; i++) await cb(array[i]);};
const severalDelays = async (...msgs) => {
//msgs; // BABEL HACK https://github.com/babel/babel/issues/1882
// var ret = '';
// we can't use forEach because the await is inside another method.
// so we have to async the function
// but if it's async, we need to await it
@sderosiaux
sderosiaux / functional-and-context.js
Created July 2, 2015 12:34
Functional and context
// context based, functional? :-(
function foo() {
const format = (name) => name.toUpperCase();
const mapper = (item) => format(item);
['foo', 'bar'].map(mapper);
}
// no context based, functional! :-)
function bar() {
const format = (name) => name.toUpperCase();
@sderosiaux
sderosiaux / metaReducer.js
Last active August 29, 2015 14:24
From acdlite/reduce-reducers, variable renamed to be more explicit
function reduceReducers(...reducers) {
return (initialState, action) =>
reducers.reduce((state, mutator) => mutator(state, action), initialState);
}
const metaReducer = reduceReducers(
(state, action) => ({ name: state.name, value: state.value + 1 }),
(state, action) => ({ name: state.name.toUpperCase(), value: state.value })
);
@sderosiaux
sderosiaux / webkit-scrollbar.css
Created July 17, 2015 10:35
Style the browser scrollbars (webkit only ofc)
::-webkit-scrollbar-track {
background-color: rgba(113,112,107,0.2);
}
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
@sderosiaux
sderosiaux / Dockerfile
Created July 25, 2015 12:28
A Slack HuBot in a Docker container using Alpine distribution (on top of busybox)
# To start: docker run -e HUBOT_SLACK_TOKEN=xxx_from_slack_integration_tool_xxx hubot
# another image could be used. It seems to not be up to date with alpine?
FROM mhart/alpine-node
RUN npm i -g coffee-script
RUN npm i -g yo generator-hubot
# can't yo as root, let's create a user
RUN adduser -h /hubot -D hubot
USER hubot
@sderosiaux
sderosiaux / requestAnimationFrameOnce.js
Last active August 29, 2015 14:25
An implementation of requestAnimationFrameOnce
function requestAnimationFrameOnce(fn) {
var requested = false;
return function(lastState) {
if (!requested) {
requested = true;
requestAnimationFrame(function() {
fn(lastState);
requested = false;
});
}