Skip to content

Instantly share code, notes, and snippets.

@ottonascarella
ottonascarella / p01-matraka-explained.js
Created August 22, 2012 05:26 — forked from tlack/p01-matraka-explained.js
p01's Matraka javascript demo decoded
// Matraka's source code decoded and beautified
// by @tlack
//
// Matraka is a 1005 byte Javascript "demo" by p01. It includes an 'evolving animation'
// and great dirty synth music. View here:
//
// http://www.p01.org/releases/MATRAKA/matraka.png.html
//
// I fondly recall the demo scene of my youth, puzzling over the work of Future
// Creators and those guys. I was puzzled by this worked so I had to figure it
@ottonascarella
ottonascarella / LICENSE.txt
Created September 6, 2012 14:55 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@ottonascarella
ottonascarella / function.thorttle.js
Created June 26, 2016 06:10
Function throttling Vanilla JS
Function.prototype.throttle = function(delay) {
var outter = this,
timer, control = false;
return function() {
if (control) return;
control = true;
var inner = this,
@ottonascarella
ottonascarella / function.debounce.js
Created June 26, 2016 06:11
Function debouncing Vanilla JS
Function.prototype.debounce = function(delay) {
var outter = this,
timer;
return function() {
var inner = this,
args = [].slice.apply(arguments);
clearTimeout(timer);
@ottonascarella
ottonascarella / matches.js
Created June 26, 2016 06:34
Polyfill matches DOM method (depends on querySelectorAll)
/* improved version of the one found at https://developer.mozilla.org/docs/Web/API/Element/matches */
(function(p) {
if (p.matches) return;
p.matches =
p.matchesSelector ||
p.mozMatchesSelector ||
p.msMatchesSelector ||
p.oMatchesSelector ||
p.webkitMatchesSelector ||
function(s) {
(ns flatten-it)
(defn flatten-it [coll]
(loop [acc [], aseq coll]
(let [[fst & rst] aseq]
(cond
(empty? aseq) (seq acc)
(sequential? fst) (recur (into acc (flatten-it fst)) rst)
:otherwise (recur (into acc [fst]) rst)))))
@ottonascarella
ottonascarella / flatten.js
Last active December 28, 2017 04:28
Flatten Array in any depth
function flatten(xs) {
return xs.reduce((acc, item) => {
if (Array.isArray(item)) {
return acc.concat(flatten(item));
}
acc.push(item);
@ottonascarella
ottonascarella / type.js
Last active May 18, 2017 04:01
get type from javascript value
function type (v) {
if (typeof v.constructor['@@type'] === 'string') return v.constructor['@@type'];
if (isNaN(v)) return 'NaN';
return ({}).toString.call(v).replace(/\[object\s|\]/g, '');
}
@ottonascarella
ottonascarella / getIn.js
Created December 28, 2017 04:20
gets nested values from within object/array
const getIn = (...path) => target => {
return path.reduce((obj, k) => {
return (obj == null) ? obj : obj[k];
}, target);
}

Keybase proof

I hereby claim:

  • I am ottonascarella on github.
  • I am ottonascarella (https://keybase.io/ottonascarella) on keybase.
  • I have a public key ASCbxUbhsdCT9B9aWy0v8Rk36QTs9bu3KZC_pQ0V0-kj9go

To claim this, I am signing this object: