Skip to content

Instantly share code, notes, and snippets.

View DanielFGray's full-sized avatar

Daniel Gray DanielFGray

View GitHub Profile
#!/usr/bin/env node
'use strict';
// http://www.codewars.com/kata/53db4acb1f1a7dd68700040a/train/javascript
function canReach(from, to, movements) {
//FIXME: attempt in multiple moves
const offset = [ Math.abs(from[0] - to[0]), Math.abs(from[1] - to[1]) ];
const valid_offsets = [ [1, 2], [2, 1] ];
return valid_offsets.some(o => {
#!/usr/bin/env bash
# DanielFGray 2016
# https://gist.github.com/d47925487840bb445296
err() {
local c_red="${esc}[31m"
echo -e "${c_red}$1${c_reset}" >&2
}
'use strict';
function validISBN10(isbn) {
if(! /\d{9}[X0-9]/.test(isbn)) return false;
return isbn.split('').reduce((p, c, i) => {
return p + ((c == 'X') ? 10 : parseInt(c)) * ++i;
}, 0) % 11 == 0;
}
(function (func, cases, invert) {
#!/usr/bin/env node
'use strict';
const runlength = {};
runlength.decode = function(str) {
return str.match(/\d*\w/g)
.reduce((prev, curr) =>
prev + (curr.length > 1
? curr.slice(-1)
@DanielFGray
DanielFGray / pkgsearch.sh
Last active December 6, 2018 15:57
package searching and installing with https://github.com/junegunn/fzf
#!/usr/bin/env bash
declare esc=$(printf '\033')
declare c_reset="${esc}[0m"
declare c_red="${esc}[31m"
declare c_green="${esc}[32m"
declare c_blue="${esc}[34m"
err() {
echo -e "${c_red}$@${c_reset}" >&2
@DanielFGray
DanielFGray / collatz.js
Last active February 26, 2016 05:49
collatz conjecture
#!/usr/bin/env node
'use strict';
const range = function(start, stop) {
return Array.apply(null, { length: 1 + stop - start })
.map((v, i) => start + i);
};
const collatz = function(n, len) {
let steps = [];
#!/usr/bin/env bash
declare file="$(date +%F-%s).webm"
declare window=false
declare region=false
declare duration
declare delay=0
declare verbose
declare -A dimensions
#!/usr/bin/env bash
has() {
command -v $1 &> /dev/null
}
err() {
echo -e "\e[31m$1\e[0m" >&2
}
function! PromptQuit()
echo 'close current buffer?'
if nr2char(getchar())=~'y'
silent execute "normal \<esc>:Sayonara!\<cr>"
elseif nr2char(getchar())=~'Y'
silent execute "normal \<esc>:Sayonara\<cr>"
endif
silent! redraw!
endfunction
nnoremap <silent> Q <Esc>:call PromptQuit()<CR>
@DanielFGray
DanielFGray / fv
Last active August 29, 2015 14:24
#!/usr/bin/env bash
usage() {
cat <<'HELP'
-s string to search
-t list only text files
-c command to execute [defaults to vim]
HELP
}