Skip to content

Instantly share code, notes, and snippets.

View ndemengel's full-sized avatar

Nicolas Grisey Demengel ndemengel

View GitHub Profile
package snippet;
import static snippet.Snippet.ClassPattern.inCaseOf;
import static snippet.Snippet.IntegerPattern.inCaseOf;
import static snippet.Snippet.OtherwisePattern.otherwise;
import static snippet.Snippet.StringPattern.inCaseOf;
import com.google.common.base.Function;
public class Snippet {
@ndemengel
ndemengel / whisper-calculator.py
Last active August 24, 2016 11:36 — forked from jjmaestro/whisper-calculator.py
Add weeks support to jjmaestro's script
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def archive_to_bytes(archive):
def to_seconds(s):
SECONDS_IN_A = {
's': 1,
'm': 1 * 60,
'h': 1 * 60 * 60,
@ndemengel
ndemengel / wizard-spec.js
Last active November 13, 2016 19:14
jsdom example
const tu = require('../tu'); // tu == test utils
const expect = tu.expect;
const withDocument = tu.withDocument;
const componentHtmlAndScript = {
html: `
<textarea id="editableArea"></textarea>
<div id="counter"></div>
`,
// load the JS module under test
@ndemengel
ndemengel / index.js
Last active November 13, 2016 19:59
(part of) Hopwork's front JS test harness
const path = require('path');
const _ = require('lodash');
const AssertionError = require('assertion-error');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const jsdom = require('jsdom');
const Q = require('q');
const sinonChai = require('sinon-chai');
@ndemengel
ndemengel / expected.html
Created November 13, 2016 19:59
JSP pseudo-interpretation in JS
<p>should be shown 1</p>
<p>should be shown 2</p>
<p>should be shown 3</p>
<form modelAttribute="formModel">
<input type="number" value="form model member value" id="formModelMember" name="formModelMember" data-plop="name 1"/>
<input type="date" value="toto">
<input type="number" value="42">
<input type="number" value="form model member value" id="formModelMember" name="formModelMember" data-plop="name 2"/>
<input type="date" value="toto">
@ndemengel
ndemengel / editable-rating-stars-spec.js
Last active November 13, 2016 20:58
Example of JS test "interpreting" a JSP (the JSP can be found here: https://gist.github.com/ndemengel/54df1425968d9e8d05d052e71b31e4d9)
const tu = require('../tu');
const expect = tu.expect;
const withDocument = tu.withDocument;
const ratingStarsJspAndScript = {
jsp: 'include/editableRatingStars',
hopModules: 'Hop/components/editable-rating-stars',
attributes: {
param: {path: 'someRadioInput'}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<div class="no-mg editable-rating-stars">
<div class="stars">
<ul class="inline-list no-lstyle">
<c:forEach begin="1" end="5" var="rate">
<li class="star">
@ndemengel
ndemengel / handlebars-example.hbs
Last active November 20, 2016 21:04
Handlebars example
<p>Handlebars escapes all texts by default. This is safe: {{htmlEscapedVariable}},
this is not {{{nonEscapedVariable}}}.</p>
<ul>
{{#each items}}
{{!-- Within this #each block, "name", "link" and "url" are properties of the current item. --}}
{{!-- Also: @first, @last and @index are automatically provided for convenience. --}}
{{#if @first}}
<li>First item: {{name}}</li>
{{else if link}}
@ndemengel
ndemengel / webpack-handlebars-config.js
Last active November 20, 2016 20:56
Webpack configuration for Handlebars templates
jspackConfiguration.module.loaders.push({
test: /\.hbs$/,
loader: 'handlebars-loader' +
// Tell handlebars-loader where our custom helpers are to be found.
// Note: helpers' names are derived from their file name.
'?helperDirs[]=' + __dirname + '/handlebars-helpers' +
// Force handlebars-loader not to include Handlebars runtime,
// since it is already included in our common bundle.
@ndemengel
ndemengel / hello.hbs
Last active November 20, 2016 16:25
Webpack: JS entry point importing Handlebars template (result here: https://gist.github.com/ndemengel/69efe8357a5cdf91a1f7ee9671c4e0cc)
Hello {{name}}!