Skip to content

Instantly share code, notes, and snippets.

View reneviering's full-sized avatar

René Viering reneviering

View GitHub Profile
@reneviering
reneviering / distinct.js
Created November 19, 2015 14:05
Find distinct values of an Array.
[1,1,2,2].filter(function(value, index, self) {
return self.indexOf(value) === index;
});
@reneviering
reneviering / readmore.js
Created December 1, 2015 13:45
Simple snippet to implement read more functionality.
function shorten(options) {
var item = $(options.selector);
var sourceText = $(item).text().trim();
var firstSection = sourceText.substring(0, options.textLength);
var lastSection = sourceText.substring(options.textLength, sourceText.length);
var firstItem = $('<span>');
firstItem.text(firstSection);
var readMoreItem = $('<a>');
var chai = require('chai');
var expect = chai.expect;
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
chai.use(sinonChai);
var eventBus = (function () {
var _eventHandler = null;
@reneviering
reneviering / redux-mocha.js
Created February 5, 2016 19:53
Simple redux todo implementation with mocha tests
var expect = require('chai').expect;
// store
const createStore = (reducer) => {
let listeners = [];
let state;
const getState = () => state;
const subscribe = (listener) => {
// 1: template strings - basics
// To do: make all tests pass, leave the asserts unchanged!
describe('a template string, is wrapped in ` (backticks) instead of \' or "', function() {
describe('by default, behaves like a normal string', function() {
it('just surrounded by backticks', function() {
var str = `like a string`;
assert.equal(str, 'like a string');
// 2: template strings - multiline
// To do: make all tests pass, leave the asserts unchanged!
describe('template string, can contain multiline content', function() {
it('a normal string can`t span across multiple lines', function() {
var normalString = 'line1' +
'\n' +
'line2';
assert.equal(normalString, 'line1\nline2');
// 3: template strings - tagged
// To do: make all tests pass, leave the asserts unchanged!
describe('tagged template strings, are an advanced form of template strings', function() {
it('syntax: prefix the template string with a function to call (without "()" around it)', function() {
function tagFunction(s) {
return s.toString();
}
var evaluated = tagFunction `template string`;
// 4: template strings - String.raw
// To do: make all tests pass, leave the asserts unchanged!
describe('on tagged template strings you can use the `raw` property like so `s.raw`', function() {
it('the `raw` property accesses the string as it was entered', function() {
function firstChar(strings) {
return strings.raw;
}
assert.equal(firstChar`\n`, '\\n');
// 5: arrow functions - basics
// To do: make all tests pass, leave the asserts unchanged!
describe('arrow functions', function() {
it('are shorter to write', function() {
var func = () => {
return 'I am func';
};
assert.equal(func(), 'I am func');
// 6: arrow functions - binding
// To do: make all tests pass, leave the asserts unchanged!
class LexicallyBound {
getFunction() {
return () => this
}
getArgumentsFunction() {