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 / _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) {
@branneman
branneman / profile.ps1
Last active August 29, 2015 13:57
Powershell custom prompt & some coloring. Here's how it looks: http://bran.name/dump/powershell-prompt.png
# Aliasses
Set-Alias l ls
Set-Alias e explorer
# Force coloring of git and npm commands
$env:TERM = 'cygwin' # windows-ansi | cygwin
$env:LESS = 'FRSX'
#
# Custom prompt
@branneman
branneman / gruntfile.js
Last active August 29, 2015 14:02
Example `grunt-htmllint-http` setup when using http://frntndr.com/
'use strict';
var glob = require('glob');
module.exports = function Gruntfile(grunt) {
var config = grunt.file.readJSON('./app/config');
grunt.loadNpmTasks('grunt-htmllint-http');
@branneman
branneman / Registry.js
Created November 6, 2014 14:58
AMD Registry Pattern implementation
/**
* @module Registry pattern implementation
*/
define(function() {
'use strict';
/**
* Constructor
*/
@branneman
branneman / client.js
Created November 8, 2014 14:51
Node.js TCP Socket - if either of them breaks, they'll keep trying to reconnect
var net = require('net');
//
// Client
//
function openSocket() {
var socket = net.connect(3e3);
socket.setKeepAlive(true);
socket.on('connect', onConnect.bind({}, socket));
@branneman
branneman / skills.md
Last active August 23, 2020 20:47
Front-End Software Craftsmanship

JavaScript knowledge

  • Operators, operands, operator precedence (unary, binary, ternary)
  • Dynamic Type system: types and conversion
    • Value type vs. Reference type
  • Expression vs. Statement
  • Scope
  • Hoisting
  • Overloading
  • Prototypal inheritance vs. Classical inheritance
  • Instancing
@branneman
branneman / MyModule.js
Last active June 15, 2016 13:26
Conditioner.js blueprint module
/**
* @module MyModule
*/
define(['dep1'], function(dep1) {
"use strict";
/**
* @param {HTMLElement} element
* @param {Object} options
@branneman
branneman / getMousePosition.js
Last active July 7, 2019 10:40
getMousePosition(event) - cross browser normalizing of: clientX, clientY, screenX, screenY, offsetX, offsetY, pageX, pageY
/**
* @param {Event} evt
* @return {Object}
*/
function getMousePosition(evt) {
var pageX = evt.pageX;
var pageY = evt.pageY;
if (pageX === undefined) {
pageX = evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
@branneman
branneman / algebraic-data-types.js
Last active August 22, 2019 14:35
Simple Algebraic Data Types (ADTs) implementing fantasy-land: Identity, Const, Maybe, Either, IO
const fl = require('fantasy-land')
const inspect = require('util').inspect.custom
// Fantasy Land
// of :: Applicative f => a -> f a
// map :: Functor f => f a ~> (a -> b) -> f b
// ap :: Apply f => f a ~> f (a -> b) -> f b
// chain :: Chain m => m a ~> (a -> m b) -> m b
/**
@branneman
branneman / pair.js
Last active September 27, 2016 12:06
Pairs (length 2 tuples) in JavaScript
/**
* Pair
* @todo Implement algebraic structures: Setoid, Functor
*/
var Pair = function(fst, snd) {
if (this instanceof Pair) {
if (Array.isArray(fst) && fst.length === 2 && typeof snd == 'undefined') {
this[0] = fst[0];
this[1] = fst[1];
} else {