Skip to content

Instantly share code, notes, and snippets.

@ottonascarella
ottonascarella / index.html
Last active June 14, 2020 01:41
Reactive Web with Dart HTML
<button class="plus">+</button>
<code>0</code>
<button class="minus">-</button>
@ottonascarella
ottonascarella / keymap.edn
Created December 4, 2018 20:29
Light Table sublime keymap user.keymap
[
[:editor "ctrl-shift-m" :editor.sublime.selectBetweenBrackets]
[:editor "pmeta-shift-d" :editor.sublime.duplicateLine]
[:editor "pmeta-shift-space" :editor.sublime.selectScope]
[:editor "pmeta-ctrl-up" :editor.sublime.swapLineUp]
[:editor "ctrl-shift-up" :editor.sublime.selectLinesUpward]
[:editor "ctrl-shift-k" :editor.delete-line]
[:editor "pmeta-shift-l" :editor.sublime.splitSelectionByLine]
[:editor "ctrl-m" :editor.sublime.goToBracket]
[:editor "pmeta-ctrl-down" :editor.sublime.swapLineDown]

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:

@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);
}
@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 / 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);
(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 / 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) {
@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 / 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,