Skip to content

Instantly share code, notes, and snippets.

View christophemarois's full-sized avatar

Christophe Marois christophemarois

  • Pathway Medical
  • Montreal
View GitHub Profile
input[type="text"][role="password"] {
width: 200px;
padding: 5px 7px;
font-size: 14px;
}
var createWorker = function(workerFn) {
// Convert function to string, and get rid of the
// wrapping `function(){}`
var workerFnContents = workerFn.toString()
.replace(/^\s*function[^(]*\([^)]*\)\s*{/igm, '')
.replace(/}\s*$/, '');
var blob = new Blob([workerFnContents], {type: 'application/javascript'});
return new Worker(window.URL.createObjectURL(blob));
};
@christophemarois
christophemarois / smartunderline.jade
Last active August 29, 2015 14:03
Smart underlines for good typography - http://jsbin.com/rafoko
html
head
meta( charset = 'utf-8' )
link( href = 'http://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic', rel = 'stylesheet', type = 'text/css')
body
#container.
What I would really like <u>to see on the web is beautiful typography</u> mixed in with simple, responsive content and <strong>beautiful images</strong>.
/*
* Generate document fragment from HTML string
* @param { HTML string } str
*
* Example:
* -> document.createDocumentFragmentFromString('<b>sup</b>&nbsp;');
* <- #document-fragment
*/
document.createDocumentFragmentFromString = function (str) {
@christophemarois
christophemarois / flatten.js
Created July 28, 2015 18:37
Recursive-based, dependency-free, vanilla array flattening
function flatten (arr, deep) {
if (deep) arr = arr.map(function(e){
return Object.prototype.toString.call(e) ===
'[object Array]' ? flatten(e, true) : e;
});
arr = Array.prototype.concat.apply([], arr || []);
return arr;
}
@christophemarois
christophemarois / multiSplit.js
Created July 28, 2015 18:50
Split a string with multiple regular expressions, then flatten the results
// var splitResults = multisplit(str, regExp1[, regExp2[, ...[, regExpN]]])
// returns single-leveled array of split results
var multiSplit = function (str) {
var regexps = [].slice.call(arguments).slice(1);
var parts = [str];
while (regexps.length) {
parts = parts.map(function(part){ return part.split(regexps[0]); });
parts = Array.prototype.concat.apply([], parts);
.viewportRatio(@x, @y) {
width: 100vw;
height: @y * 100vw / @x;
max-width: @x / @y * 100vh;
max-height: 100vh;
}
.first {
.viewportRatio(5, 1);
background-color: blue;
@christophemarois
christophemarois / shouldTextBeDark.js
Last active December 28, 2015 04:19
shouldTextBeDark v 1.0 Determines whether text color should be dark or not to contrast nicely with the background color, based on the visual contrast algorithm suggested by the W3C (http://www.w3.org/WAI/ER/WD-AERT/#color-contrast).
// shouldTextBeDark v 1.0
// (formerly colorContrast)
// Determines whether text color should be dark or not to
// contrast nicely with the background color.
// Based on the visual contrast algorithm suggested by the W3C
// (http://www.w3.org/WAI/ER/WD-AERT/#color-contrast)
// Call it with a RGB color:
@christophemarois
christophemarois / mkdirpSync.js
Created December 29, 2015 21:10
Create folder or use existing
function mkdirpSync (dirpath) {
var fs = require('fs');
var parts = dirpath.split(path.sep);
for( var i = 1; i <= parts.length; i++ ) {
try {
fs.mkdirSync(path.join.apply(null, parts.slice(0, i)));
} catch(e) {
if ( e.code != 'EEXIST' ) throw e;
}
}