Skip to content

Instantly share code, notes, and snippets.

View eswak's full-sized avatar
🚀

Erwan Beauvois eswak

🚀
  • Toulouse, France
View GitHub Profile
@eswak
eswak / mochachaisinon.js
Last active April 16, 2019 14:21
An example of asynchronous JavaScript testing using Mocha + Chai + Sinon
var chai = require('chai');
var assert = chai.assert;
var expect = chai.expect;
var should = chai.should();
var sinon = require('sinon');
function myAsyncFunction(callback) {
// 50ms delay before callback
setTimeout(function() {
console.log('hello');
@eswak
eswak / express.host.js
Created June 17, 2014 11:53
Easy & simple express static host
var express = require('express');
var app = express();
app.use('/totem', express.static(__dirname + '/totem'));
app.use('/remote', express.static(__dirname + '/remote'));
app.use('/minisite', express.static(__dirname + '/minisite'));
ap.get('/', function(req, res) {
res.send('<a href="/minisite">minisite</a><br>');
res.send('<a href="/remote">remote</a><br>');
@eswak
eswak / after&tooltips.html
Last active August 29, 2015 14:02
CSS ::after styles & pure css tooltips
<head>
<style>
section {
padding:2em 1.5em 1.5em 1.5em;
font-size:2em;
background:yellow;
font-family:sans;
position:relative;
overflow:hidden;
}
@eswak
eswak / automatic-grid.html
Created July 17, 2014 08:24
Automatic grid in CSS3
<html>
<head>
<style>
.grid *:first-child:nth-last-child(1) {
width: 100%;
}
.grid *:first-child:nth-last-child(2),
.grid *:first-child:nth-last-child(2) ~ * {
width: 50%;
@eswak
eswak / ogame.user.js
Last active March 31, 2020 14:03
Chrome userscript for ogame UI enhancements
// ==UserScript==
// @match http://*.ogame.gameforge.com/game/*
// @name OGame UI++
// @author Eswak
// @version 1.1.0
// @description Améliore l'interface utilisateur d'OGame en y ajoutant des éléments.
// @icon http://gf1.geo.gfsrv.net/cdn68/20da7e6c416e6cd5f8544a73f588e5.png
// DESCRIPTION :
// This userscript enhances the ogame UI to add some informations into it
// HOW TO INSTALL (GOOGLE CHROME) :
@eswak
eswak / svg-progress-circle.html
Last active August 4, 2016 20:42
SVG Progress circle
<!DOCTYPE html>
<html>
<head>
<style>
svg.progress-circle {
height: 1em;
}
svg.progress-circle text {
fill: #003484;
font-family: 'Roboto', arial;
@eswak
eswak / draw-svg.js
Created February 19, 2015 21:17
Progressively draw SVG to create a hand drawn effect
(function closure () {
// progressively draw each <svg> without .no-draw class
Array.prototype.forEach.call(document.querySelectorAll('svg:not(.no-draw)'), function(svg) {
// animation duration & delay (default values overriden by data attributes)
var animationTimeInSeconds = Number(svg.getAttribute('data-draw-time')) || 2;
var animationStartDelay = Number(svg.getAttribute('data-draw-start-delay'))*1000 || 0;
// init, hide all svgs
var totalFrames = animationTimeInSeconds * 60;
@eswak
eswak / origami-ui.html
Created June 19, 2015 12:25
Origami UI
<div class="paper">
<div class="paper-section">
Hello !
</div>
</div>
<div class="paper">
<div class="paper-section">
Hello !
</div>
@eswak
eswak / str2color.js
Last active February 17, 2016 11:08
JavaScript string to color
function str2num (str) {
var hash = 0, i, chr, len;
if (str == 0) return hash;
for (i = 0, len = str.length; i < len; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0;
}
return hash;
};
@eswak
eswak / flattenObj.js
Last active March 4, 2016 09:46
Get a plain object (without nested keys) based on a multi-level object
/*
* Flattens an object by creating a plain object (without nested keys).
* The returned object keys are strings with dots for nested source object.
* Example :
* flattenObj({ a: 1, b: { c: 2, d: null } }) => { 'a': 1, 'b.c': 2, 'b.d': null }
*/
function flattenObj (obj, prefix, acc) {
acc = acc || {};
prefix = prefix || '';
var separator = '.';