Skip to content

Instantly share code, notes, and snippets.

@DannyDelott
DannyDelott / getTimeLeft().js
Last active July 6, 2019 13:22
Show time left until noon using Moment.js
var getTimeLeft = function(){
var now = moment();
var deadline = now.clone().hour(12).minute(0),second(0);
if(now.isAfter(deadline) {
// disable RSVP button here
return ‘Closed’;
}else {
// enable RSVP button here
// returns “in x hours”, “in x minutes”, “in a few seconds”
return deadline.from(now);
@DannyDelott
DannyDelott / jsbin.js
Last active December 8, 2017 22:30
map.setStyle instead of addLayer/addSource
/****************************************************************
* Setting root-level styles *
* See: https://www.mapbox.com/mapbox-gl-js/style-spec/#root *
* JSBIN: https://jsbin.com/qazosufoge/1/edit?js,console,output *
****************************************************************/
mapboxgl.accessToken = 'pk.eyJ1IjoiaGVsbG8tY2EiLCJhIjoiY2lyaTdmdjNwMDF5eWc2bnJzM29rajAycyJ9.V-d5lBQ8iQ_n-vpvJ_RSIA';
var statesSource = {
'type': 'geojson',
@DannyDelott
DannyDelott / betterInterval.js
Last active March 13, 2017 13:31
Use a recursive setTimeout instead of setInterval
var betterInterval = function(execute, delay, reverse) {
execute.stop = false;
execute.stopped = false;
if(reverse){ execute(); }
(function subroutine() {
setTimeout(function() {
if(!execute.stop){
execute();
subroutine();
}else{ execute.stopped = true; }
#!/bin/bash
red=$'\e[1;31m'
grn=$'\e[1;32m'
yel=$'\e[1;33m'
blu=$'\e[1;34m'
mag=$'\e[1;35m'
cyn=$'\e[1;36m'
end=$'\e[0m'
@DannyDelott
DannyDelott / .vimrc
Last active June 15, 2016 22:45
Should work out of the box, just install Vundle (except for YCM)
set nocompatible " be iMproved
au FocusGained,BufEnter * :silent! !
au FocusLost,WinLeave * :silent! w
" so $HOME/.vim/plugin/vundle.vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Auto load changes to vimrc to vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup myvimrc
var sum = 0;
var add5Async = () => {
return setTimeoutAsync(1000)
.then(add5.bind(null, sum)) // pure function, bind global variable as input
.then(setSum); // side-effect at the end
};
asyncReduce([ add5Async, add5Async, add5Async ])
.then(() => { console.log('sum:', sum); })
@DannyDelott
DannyDelott / pre-commit.sh
Last active April 12, 2016 21:22
Pre-commit hook
#!/bin/sh
for staged_file in $(git diff --cached --name-only)
do
if [[ "$staged_file" == *\.js$* ]] && [ -f "$staged_file" ]; then
./node_modules/jscs/bin/jscs "$staged_file"
if [[ "$?" != "0" ]]; then
exit 1
fi
fi
@DannyDelott
DannyDelott / tmux.config
Last active February 3, 2016 16:56
usr/local/etc/tmux.config -> `tmux source usr/local/etc/tmux.config`
# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# split panes using | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %
@DannyDelott
DannyDelott / .gitconfig
Created January 30, 2016 01:33
prettty_git-hist
#Add to ~/.gitconfig
[alias]
hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
@DannyDelott
DannyDelott / comparesemvar.sh
Last active January 21, 2016 18:17
compare semvar bash
#!/bin/bash
vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))