Skip to content

Instantly share code, notes, and snippets.

View shawndumas's full-sized avatar

Shawn Dumas shawndumas

View GitHub Profile
(new Array(101)).join(0).split(0).map(function (v, i) {
var r = '';
i += 1;
(i%3 < 1) && (r += 'Fizz');
(i%5 < 1) && (r += 'Buzz');
!r && (r = i);
return r;
}).join('\n');
@shawndumas
shawndumas / requiredParam.js
Created May 8, 2014 17:49
ES6 -- Required Parameter
var throwMissinParamError = function () {
throw new Error('Missing parameter');
},
requiredParamFn = function (requiredParam = throwMissinParamError()) {
// use required parameter
return requiredParam;
};

Keybase proof

I hereby claim:

  • I am shawndumas on github.
  • I am shawndumas (https://keybase.io/shawndumas) on keybase.
  • I have a public key whose fingerprint is 52D9 9BC6 417C D7BD F1AC AA5D 4DEF 01E1 B398 982C

To claim this, I am signing this object:

@shawndumas
shawndumas / spawn.js
Created March 27, 2014 18:04
ES6 Spawn
var spawn = function (generatorFn) {
var continuer = function (verb, arg) {
var r;
try {
r = generator[verb](arg);
} catch (error) {
return Promise.reject(error);
}
@shawndumas
shawndumas / contains.js
Created February 9, 2014 05:32
Contains
!!(~('xxxXXXxxx').indexOf('xxx'));
@shawndumas
shawndumas / IsBalanced.js
Last active October 7, 2015 16:19
IsBalanced
const isBalanced = (s, open, close) => {
return !!(
s.split('').reduce((p, c, i) => {
if (c === close && i === 0 || p === false) { p = false; }
else if (c === open ) { p += -1; }
else if (c === close) { p += 1; }
return p;
}, 0)
);
};
@shawndumas
shawndumas / range.js
Last active August 29, 2015 13:56
Stupid Hack for a Range Function
var range = function (from, to) {
if (arguments.length === 1) { to = from; }
var a = new Array(to + 1).join(0).split(0).map(function (v, i) { return i; });
if (from !== to) { a = a.slice(from, a.length); }
return a;
};
@shawndumas
shawndumas / obsession.sh
Last active January 2, 2016 12:49
hn leaders
lynx -dump -nonumbers -nolist https://news.ycombinator.com/leaders | head -14 | tail
@shawndumas
shawndumas / th.sh
Last active November 30, 2023 12:50
toggle AppleShowAllFiles
#!/bin/bash
#
# toggle AppleShowAllFiles
#
current_value=$(defaults read com.apple.finder AppleShowAllFiles)
if [ $current_value = "TRUE" ]
then
defaults write com.apple.finder AppleShowAllFiles FALSE
else
@shawndumas
shawndumas / explain
Last active December 27, 2015 18:49
Explain
#!/bin/bash
#brew install gnu-sed
#ln -s /usr/local/bin/gsed /usr/local/bin/sed
URL=$(echo "http://explainshell.com/explain?cmd=$1+${@:2}" | sed -e 's/ /+/g')
curl -s "$URL" | sed -n '/<pre/,/<\/pre>/p' | sed -n '/<pre/,/<\/pre>/p' | sed -s 's/<[^>]*>//g' | \
sed -e 's/^ *//g;s/ *$//g' | grep '.' | cat