Skip to content

Instantly share code, notes, and snippets.

View sylvaindethier's full-sized avatar

Sylvain Dethier sylvaindethier

View GitHub Profile
@sylvaindethier
sylvaindethier / Handlebars.helpers-pluralize.js
Created May 6, 2014 18:24
Handlebars helper for pluralization
/**
* Pluralization outputs singular or plural given a value
*/
Handlebars.registerHelper('pluralize', function (value, singular, plural) {
return value > 1 ? plural : singular;
});
@sylvaindethier
sylvaindethier / Handlebars.helpers-nl2br.js
Created May 6, 2014 18:26
Handlebars helper new line to br
/**
* Replace \n by <br />, such as the `nl2br` in PHP
* @see http://stackoverflow.com/questions/2919337/jquery-convert-line-breaks-to-br-nl2br-equivalent
*/
Handlebars.registerHelper('nl2br', function (text, isXhtml) {
var breakTag = (isXhtml || typeof isXhtml === 'undefined') ? '<br />' : '<br>';
return (text + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
});
@sylvaindethier
sylvaindethier / Handlebars.helpers-momentJS.fromNow.js
Created May 6, 2014 18:28
Handlebars helper that handle MomentJS `fromNow` method
/**
* Moment - fromNow
*/
Handlebars.registerHelper('moment_unix_fromNow', function (timestamp) {
return moment.unix(timestamp).fromNow();
});
/**
* MomentJS - fromNow
*/
Handlebars.registerHelper('moment_unix_fromNow', function (timestamp) {
return moment.unix(timestamp).fromNow();
});
@sylvaindethier
sylvaindethier / textarea-auto-height-adjust.html
Created October 17, 2014 11:23
Auto adjust Textarea height
<textarea data-adaptheight rows="3" cols="40" placeholder="Your input" style="padding: 16px; line-height: 1.5;"></textarea>
<script>
(function() {
function adjustHeight(textareaElement, minHeight) {
// compute the height difference which is caused by border and outline
var outerHeight = parseInt(window.getComputedStyle(el).height, 10);
var diff = outerHeight - el.clientHeight;
// set the height to 0 in case of it has to be shrinked
el.style.height = 0;
@sylvaindethier
sylvaindethier / odoo8-install.md
Created December 8, 2014 22:10
Odoo8 (OpenERP) installation on Ubuntu 14.04

1. Update OS

sudo apt-get update && sudo apt-get upgrade

2. Create the Add Odoo user (own & run application)

sudo adduser --system --home=/opt/odoo --group odoo

3. Install & configure PostgreSQL

sudo apt-get install postgresql sudo su - postgres createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt odoo

@sylvaindethier
sylvaindethier / gist:046daf1cc24006c7a243
Created February 1, 2016 18:18
Verifying that +sdethier is my blockchain ID. https://onename.com/sdethier
Verifying that +sdethier is my blockchain ID. https://onename.com/sdethier
@sylvaindethier
sylvaindethier / release.sh
Last active July 17, 2017 21:29
NPM Release
#!/bin/bash
set -e
# -e: Exit immediately if a pipeline [...] returns a non-zero status.
# @see: https://www.gnu.org/software/bash/manual/bashref.html#The-Set-Builtin-1
## prevent runing script outside the repo root
if ! [ -e scripts/release.sh ]; then
echo >&2 "Please run scripts/release.sh from the repo root"
exit 1
@sylvaindethier
sylvaindethier / post-merge
Last active May 20, 2016 09:19 — forked from sindresorhus/post-merge
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
@sylvaindethier
sylvaindethier / server.js
Created June 26, 2017 09:36
NodeJS Express server for SPA
// Express
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const PORT = 9000;
const STATIC = path.resolve(__dirname, 'dist');
const INDEX = path.resolve(STATIC, 'index.html');