Skip to content

Instantly share code, notes, and snippets.

View olivmonnier's full-sized avatar
💭
¯\_(ツ)_/¯

Olivier Monnier olivmonnier

💭
¯\_(ツ)_/¯
View GitHub Profile
@olivmonnier
olivmonnier / HashTable.js
Created August 3, 2017 12:23 — forked from alexhawkins/HashTable.js
Correct Implementation of a Hash Table in JavaScript
var HashTable = function() {
this._storage = [];
this._count = 0;
this._limit = 8;
}
HashTable.prototype.insert = function(key, value) {
//create an index for our storage location by passing it through our hashing function
var index = this.hashFunc(key, this._limit);
@olivmonnier
olivmonnier / genName.js
Created July 21, 2017 12:05
Planet name generator
const upperChar = str => str.charAt(0).toUpperCase() + str.slice(1);
const randomInArray = arr => arr[Math.floor(Math.random() * arr.length)];
const genName = (partNames) => {
let lastPart;
const firstPart = randomInArray(partNames);
do {
lastPart = randomInArray(partNames);
} while(lastPart == firstPart);
@olivmonnier
olivmonnier / SCSS.md
Created July 20, 2017 08:33 — forked from jareware/SCSS.md
Advanced SCSS, or, 16 cool things you may not have known your stylesheets could do

⇐ back to the gist-blog at jrw.fi

Advanced SCSS

Or, 16 cool things you may not have known your stylesheets could do. I'd rather have kept it to a nice round number like 10, but they just kept coming. Sorry.

I've been using SCSS/SASS for most of my styling work since 2009, and I'm a huge fan of Compass (by the great @chriseppstein). It really helped many of us through the darkest cross-browser crap. Even though browsers are increasingly playing nice with CSS, another problem has become very topical: managing the complexity in stylesheets as our in-browser apps get larger and larger. SCSS is an indispensable tool for dealing with this.

This isn't an introduction to the language by a long shot; many things probably won't make sense unless you have some SCSS under your belt already. That said, if you're not yet comfy with the basics, check out the aweso

(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
@olivmonnier
olivmonnier / canvasrecord.js
Created July 5, 2017 07:30 — forked from PaulKinlan/canvasrecord.js
Screen recorder in JS
(function() {
let canvas = document.querySelector('canvas');
// Optional frames per second argument.
let stream = canvas.captureStream(25);
var options = {mimeType: 'video/webm; codecs=vp9'};
let recorder = new MediaRecorder(stream, options);
let blobs = [];
function download(blob) {
var url = window.URL.createObjectURL(blob);
@olivmonnier
olivmonnier / monitorEvents.js
Created July 4, 2017 15:42 — forked from PaulKinlan/monitorEvents.js
monitorEvents.js
function monitorEvents(element) {
var log = function(e) { console.log(e);};
var events = [];
for(var i in element) {
if(i.startsWith("on")) events.push(i.substr(2));
}
events.forEach(function(eventName) {
element.addEventListener(eventName, log);
});
@olivmonnier
olivmonnier / applyTemplate.js
Created July 4, 2017 15:16 — forked from PaulKinlan/applyTemplate.js
Simple Templating
const applyTemplate = (templateElement, data) => {
const element = templateElement.content.cloneNode(true);
const treeWalker = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, () => NodeFilter.FILTER_ACCEPT);
while(treeWalker.nextNode()) {
const node = treeWalker.currentNode;
for(let bindAttr in node.dataset) {
let isBindableAttr = (bindAttr.indexOf('bind_') == 0) ? true : false;
if(isBindableAttr) {
let dataKey = node.dataset[bindAttr];
@olivmonnier
olivmonnier / parse.js
Created June 30, 2017 07:46
Parser CSS
const parse = (strings, ...values) => {
const evaluated = strings.reduce((acc, string, i) => {
acc.push(string)
if (values[i]) acc.push(values[i].toString())
return acc
}, [])
const rules = evaluated.join('').replace(/ /g, '').split(/;\n|;|\n/)
@olivmonnier
olivmonnier / getNbArgumentsFunction.js
Created May 31, 2017 07:05
Get nb arguments for a function
module.export = function(fn) {
return fn.length
}
@olivmonnier
olivmonnier / app.js
Last active May 30, 2017 15:35 — forked from bmorelli25/app.js
Twitter Favorite Bot
var Twitter = require('twitter');
var config = require('./config.js');
var T = new Twitter(config);
// Set up your search parameters
var params = {
q: '#nodejs',
count: 10,
result_type: 'recent',
lang: 'en'