Skip to content

Instantly share code, notes, and snippets.

View danielmcq's full-sized avatar

Daniel McQuiston danielmcq

View GitHub Profile
@danielmcq
danielmcq / version.js
Created April 20, 2020 14:56
Update changelog based off of version tags. Useful as the `version` script in an npm package.
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const { promisify } = require("util");
const { spawn } = require("child_process");
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
SELECT
sql_id,
COUNT(*)
FROM
(
SELECT
t.sql_id,
s.sid,
COUNT(*)
FROM
@danielmcq
danielmcq / fakeServer.js
Created August 28, 2018 20:47
Fake HTTP server for debugging
'use strict';
const http = require('http');
const port = process.env.PORT||9090;
const requestHandler = (request, response) => {
let body = Buffer.from('', 'utf8');
request.on('data', data => {
body = Buffer.concat([body, data]);
});
@danielmcq
danielmcq / eslint.sh
Created August 28, 2018 20:44 — forked from namnm/eslint.sh
Do eslint only changed files
# The regexp without escapse is ^[^D]{2}.*((.js)|/)$ with:
# [^D]{2} means that's not a deleted file from git output
# .* is the file name
# ((.js)|/) means it's end with .js extension, or a slash (directory)
# To use in package.json, we need to double the escapse: ^[^D]\\{2\\}.*\\(\\(\\.js\\)\\|/\\)$ pretty neat huh?
git status --porcelain | grep '^[^D]\{2\}.*\(\(\.js\)\|/\)$' | cut -c 4- | xargs eslint
@danielmcq
danielmcq / .vimrc
Last active May 8, 2018 16:06
Vim customization
" Set compatibility to Vim only.
set nocompatible
" Helps force plug-ins to load correctly when it is turned back on below.
filetype off
" Turn on syntax highlighting.
syntax on
" For plug-ins to load correctly.
@danielmcq
danielmcq / incrementColumnLetters.js
Last active January 22, 2018 20:40
Increment Excel column letters
// Only supports positive numbers for now
function column (letters, numberOfColumnsAway=0) {
let newColumnLetters = letters.trim().toUpperCase()
for (let i = 0; i < Math.abs(numberOfColumnsAway); i++) {
newColumnLetters = incrementColumnLetters(newColumnLetters)
}
return newColumnLetters
}
@danielmcq
danielmcq / mongoIdToCreatedAt.js
Last active August 31, 2017 22:06
Convert mongo document ID to date
function mongoIdToCreatedAt (mongoId) {
const datePart = mongoId.slice(0,8)
const dateVal = parseInt(datePart,16)
return new Date(dateVal*1000)
}
// One line
const mongoIdToCreatedAt = mongoId=>(new Date(parseInt(mongoId.slice(0,8),16)*1000))
@danielmcq
danielmcq / remove-tags.sh
Last active December 8, 2017 16:30 — forked from housser/remove-tags.sh
Remove Git tags based on regular expression, and remove from remote
#!/bin/bash
for i in $( git tag | grep ^tag_name_pattern ); do
#echo item: $i
git tag -d $i
#git push origin :refs/tags/$i
git push --delete origin $i
done
# or on one line
@danielmcq
danielmcq / README.md
Last active October 6, 2016 07:02
Find open time blocks

Find open time blocks

This code written in JavaScript for Node.js finds open time blocks, given a set of intervals which are not available.

Node.js 5.x or higher is needed in order to run the code as it takes advantage of ES6 features and uses CommonJS modules. However, it can be run in a modern browser by removing the module.exports line at the end of the file team_availability.js.

To run the tests, save both JavaScript files in the same directory and run node test.js from the directory in a terminal/command prompt. The tests simply show expected and calculated results. In order to keep things simple, no external library for testing was used. Therefore, there are no asserts, expects, shoulds or anything like that. Just simple console output.