Skip to content

Instantly share code, notes, and snippets.

@StephaneTrebel
StephaneTrebel / test.js
Last active February 27, 2020 08:08
Unit testing in nodejs with proxyquire and sinon
// Awesomeness first
const _ = require('lodash');
const proxyquire = require('proxyquire');
const sinon = require('sinon');
// Mocha + Chai are used here but feel free to use your test framework of choice !
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
# 1 make your app listen on a port while serving (here we'll use the common 8100 port)
# 2 Run
sudo docker run -it -p 8100:8100 -v /local_project_folder:/docker_project_folder -e ENV_VAR=content -e ANOTHER_ENV_VAR=anothercontenxt image_name
@StephaneTrebel
StephaneTrebel / commitmsg.sh
Last active August 11, 2017 07:48
Automagically add the JIRA branch name to the commit message
#!/bin/sh
# Add "commitmsg": "./commitmsg.sh ${GIT_PARAMS}" to your package.json and use Husky to add it as a githook
TICKET=$(git symbolic-ref HEAD | rev | cut -d/ -f1 | rev | grep -o -E "[A-Z]+-[0-9]+")
if [ -n "${TICKET}" ]; then
# sed -e "1s/^/[${TICKET}] /" $1
echo -n "[$TICKET]"' '|cat - "$1" > /tmp/out && mv /tmp/out "$1"
fi
{
"extends": "tslint:recommended",
"rules": {
"object-literal-key-quotes": [true, "as-needed"],
"quotemark": "single",
"arrow-parens": [true, "ban-single-arg-parens"],
"ordered-imports": false,
"object-literal-sort-keys": false,
"no-var-requires": false,
"max-classes-per-file": [true, 2]
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"removeComments": true,
"lib": ["es2015", "dom"],
"strict": true,
"noUnusedLocals": true,
@StephaneTrebel
StephaneTrebel / Dockerfile
Created August 11, 2017 08:05
Generic node8 dockerfile
FROM ubuntu:zesty
MAINTAINER Stephane Trebel <myemail.email.com>
ENV DEBIAN_FRONTEND=noninteractive \
NODE_VERSION=8.2.1 \
SONAR_SCANNER=3.0.0.702-linux \
SONAR_URL=http://localhost:9000
# Setup environment
ENV PATH ${PATH}:/opt/sonar-scanner/bin
@StephaneTrebel
StephaneTrebel / Dockerfile
Created August 11, 2017 08:07
Generic Ionic2 dockerfile
FROM ubuntu:trusty
MAINTAINER Stéphane Trebel <[email protected]>
ENV DEBIAN_FRONTEND=noninteractive \
ANDROID_HOME=/opt/android-sdk-linux \
NODE_VERSION=8.2.1 \
SONAR_SCANNER=3.0.0.702-linux \
SONAR_URL=http://localhost:9000 \
DISPLAY=":1"
@StephaneTrebel
StephaneTrebel / .bashrc
Created September 19, 2017 08:21
Git branch in prompt
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ '

Reading data before application startup in Angular 2

In this demonstration I will show you how to read data in Angular2 final release before application startup. You can use it to read configuration files like you do in other languages like Java, Python, Ruby, Php.

This is how the demonstration will load data:

a) It will read an env file named 'env.json'. This file indicates what is the current working environment. Options are: 'production' and 'development';

b) It will read a config JSON file based on what is found in env file. If env is "production", the file is 'config.production.json'. If env is "development", the file is 'config.development.json'.

@StephaneTrebel
StephaneTrebel / commit-msg.sh
Last active October 21, 2022 06:01
git commitmsg hook: Idempotently add ticket number in the footer part of a commit message
#!/bin/bash
#
# DESCRIPTION:
# Add the ticket identifier found in the branch name in the footer part of
# the commit message. This action is idempotent (meaning if the ticket is already
# in the message, it will not be added again).
# Please note that this apply to «git commit» and its variations
# (most notably «--amend»). Il will not apply to «reword» actions during an
# interactive rebase, for instance.
#