Skip to content

Instantly share code, notes, and snippets.

View branneman's full-sized avatar

Bran van der Meer branneman

View GitHub Profile
@branneman
branneman / scale.js
Last active November 26, 2015 06:35
Map a value in a range to another range
/**
* Map a value in a domain to a value in a range
*/
function scale(domainMin, domainMax, value, rangeMin, rangeMax) {
var perc = (value - domainMin) / (domainMax - domainMin)
return ((rangeMax - rangeMin) * perc) + rangeMin
}
scale(50, 100, 75, 100, 200) //=> 150
scale(10, 110, 50, 200, 300) //=> 240
@branneman
branneman / mixin-before-after.scss
Last active December 16, 2015 20:49
SASS Mixin — Single/double colon generated content
@mixin before-after {
@if $old-ie {
&:before, &:after {
@content;
}
} @else {
&::before, &::after {
@content;
}
}
@branneman
branneman / _rem.scss
Last active December 24, 2015 07:19
Sass (scss) rem function and mixin. Based on and improved upon: https://github.com/bitmanic/rem
//
// Sass rem function and mixin
// https://gist.github.com/branneman/6762906
// Based on and improved upon https://github.com/bitmanic/rem
//
// Baseline, measured in pixels
// The value should be the same as the font-size value for the html element
// If the html element's font-size is set to 62.5% (of the browser's default font-size of 16px),
// then the variable below would be 10px.
@branneman
branneman / articles.js
Last active December 30, 2015 21:50
Example code style I use of a Node.js module. Uses @felixge's Node Style Guide and some more conventions on naming and formatting.
//
// Articles controller
// Optional module description line.
//
'use strict';
var fs = require('fs');
var path = require('path');
@branneman
branneman / howto.md
Last active January 3, 2016 21:39
Howto install Ruby & DevKit on Windows

Howto install Ruby & DevKit on Windows

  1. Install Ruby 2, x64
    inside a directory without spaces

  2. Install a matching Ruby DevKit, instructions here
    inside a directory without spaces

  3. Install extra dependencies:

@branneman
branneman / 0-usage.js
Last active January 25, 2016 18:40
JavaScript Mixins
/**
* Original class
*/
class Todo {
constructor(name) {
this.name = name || 'Untitled';
this.done = false;
}
do() {
this.done = true;
@branneman
branneman / _position.scss
Last active April 5, 2016 15:27
[Sass] Mixin to provide short-hand positioning syntax
//
// Mixin to provide short-hand positioning syntax
// https://gist.github.com/branneman/9248961
//
// Usage:
// @include position(0 false 0 20rem);
// @include position(absolute, 0 false 0 20rem);
//
@mixin position ($position: relative, $coordinates: 0 0 0 0) {
/**
* @param {HTMLElement} element - The element's coordinates to calulate
* @param {HTMLElement} relativeElement - An optional relative element, defaults to `document.body`
* @returns {{ offsetY: Number, offsetX: Number }}
*/
const getElementCoordinates = function(element, relativeElement = document.body) {
const relativeRect = relativeElement.getBoundingClientRect();
const elementRect = element.getBoundingClientRect();
const offsetY = elementRect.top - relativeRect.top;
const offsetX = elementRect.left - relativeRect.left;
@branneman
branneman / getFormElementValue.js
Last active April 22, 2016 08:36
getFormElementValue() - Returns the value of a form element, given it's name and type
/**
* getFormElementValue()
* Returns the value of a form element, given it's name and type
*
* @param {String} name - An element's `name=""` attribute
* @param {String} type - An element type string, e.g. 'text', 'radio', 'select'
* @returns {String|Boolean}
*/
const getFormElementValue = (function(){
const getElement = name => document.querySelector('[name="' + name + '"]');
@branneman
branneman / detects-flexbox.js
Last active May 12, 2016 09:14
Feature detect Flexbox support with JavaScript
define(function() {
var cssomPrefixes = 'Moz O ms Webkit'.split(' ');
var modElem = {
elem: document.createElement('modernizr')
};
var mStyle = {
style: modElem.elem.style
};