Skip to content

Instantly share code, notes, and snippets.

@Daniel-Hug
Daniel-Hug / clearfix.css
Created October 4, 2013 05:23
Micro clearfix CSS / LESS "hack"
/* Clearfix
---------------------------------------*/
.cf:before,
.cf:after {
content:"";
display:table;
}
.cf:after { clear:both }
.cf { *zoom:1 }
@Daniel-Hug
Daniel-Hug / box-sizing.css
Last active December 24, 2015 15:38
CSS: box-sizing: border-box
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
@Daniel-Hug
Daniel-Hug / arr-stat.js
Last active December 11, 2023 14:46
JavaScript statistical functions for arrays: max, min, range, midrange, sum, mean / average, median, modes, variance, standard deviation, mean absolute deviation, z scores
var arr = {
max: function(array) {
return Math.max.apply(null, array);
},
min: function(array) {
return Math.min.apply(null, array);
},
range: function(array) {
@Daniel-Hug
Daniel-Hug / sudo methods.js
Last active January 4, 2016 02:19
Sudo methods in JS
var sudo = (function(arr, obj) {
[
['forEach', arr, 'each'],
['map', arr],
['indexOf', arr],
['filter', arr],
['hasOwnProperty', obj, 'has'],
['toString', obj]
].forEach(function(method) {
var fn = method[1][method[0]];
@Daniel-Hug
Daniel-Hug / call.js
Last active October 8, 2017 15:25
chainable wrapper for JS setTimeout and setInterval
// call.js
// chainable setTimeout and setInterval JavaScript wrapper
//
// By Daniel Hug: https://gist.github.com/Daniel-Hug/9062765
// MIT license: http://hug.mit-license.org/
//
// use:
// var timer = call(fn, scope, args).after(1000).start();
// var interval = call(fn, scope, args).every(1000).fire().start();
// timer.stop();
@Daniel-Hug
Daniel-Hug / Geometry.md
Last active August 29, 2015 13:56
Geometry of 2D & 3D figures with π/4

#Geometry of 2D & 3D figures with $\frac{\pi}{4}$

$$ \frac{\pi}{4} = \sum\limits_{k=0}^\infty \frac{(-1)^k}{2k + 1} = \frac{1}{1}-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}+\frac{1}{9}\ldots\approx 78.5% $$

##2D figures

Area Circumference
//addEventListener polyfill 1.0 / Eirik Backer / MIT Licence
(function(win, doc){
if(win.addEventListener)return; //No need to polyfill
function docHijack(p){var old = doc[p];doc[p] = function(v){return addListen(old(v))}}
function addEvent(on, fn, self){
return (self = this).attachEvent('on' + on, function(e){
e = e || win.event;
e.preventDefault = e.preventDefault || function(){e.returnValue = false}
e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true}
@Daniel-Hug
Daniel-Hug / badchar.json
Last active August 29, 2015 14:10
This is a valid JSON file, but it wont convert to valid jsonp with https://github.com/maxogden/jsonpify
{
"content": "Wierd Char --> 
 <--"
}
function arrayTo2d(items, width) {
var rows = [];
var lastRow;
items.forEach(function(item, i) {
// add another row when cell index is divisble by width
if ((i) % width === 0) {
lastRow = [];
rows.push(lastRow);
}
@Daniel-Hug
Daniel-Hug / templating.js
Last active January 18, 2016 07:21
HTML escaping and templating; Demo: http://jsbin.com/bahimu/edit?html,js,output
// Make strings safe for innerHTML and attribute insertion (templates):
var escapeHTML = (function() {
var entityMap = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'
},
re = /[&<>"']/g;