Skip to content

Instantly share code, notes, and snippets.

@dmmulroy
dmmulroy / atp-week1.js
Created January 24, 2018 14:00
All Tests Pass: Week 1
/**
* All Tests Pass: Week 1
* Given an array of integers, find out if any two items in the array add up to
* the target. For example, sumsToTarget([1,2], 3) should return true, but
* sumsToTarget([1,2], 4) should return false.
*/
function sumsToTarget(integers = [], target) {
const uniqueIntegers = new Set(integers);
@dmmulroy
dmmulroy / Trie.js
Created April 24, 2018 17:40 — forked from tpae/Trie.js
Trie.js - super simple JavaScript implementation
// Trie.js - super simple JS implementation
// https://en.wikipedia.org/wiki/Trie
// -----------------------------------------
// we start with the TrieNode
function TrieNode(key) {
// the "key" value will be the character in sequence
this.key = key;

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@dmmulroy
dmmulroy / pg_drive_init_twice_solution.md
Created January 31, 2019 14:46
Go postgres driver is being registered twice fix

I ran into this and figured out what was going on; for the sake of future google searchers here is what might be happing if you see this error.

I was in a project with vendored dependencies, so 2 version of lib/pq existed: one in my project's vendor/ directory and another in $GOPATH/src/github.com/lib/pq. Normally this wouldn't be an issue, since the project should use the vendored one. But I failed to vendor a third dependency (in this case mattest/migrate), so it was getting built out of my GOPATH, and that imports lib/pq so used the GOPATH version of lib/pq for that. So two lib/pq packages would get built, both have their init() called... boom

const jwt = require('jsonwebtoken');
const config = require('../../config');
module.exports = (req, res, next) => {
try {
const [_, token] = req.get('Authorization').split(' ');
if (!token) return res.status(401).end();
const decodedToken = jwt.verify(token, config.JWT_SECRET, {
const withIsRequired = validatorFn => {
const _customPropValidator = (isRequired = false) => (props, propName, componentName) => {
const value = props[propName];
if (value == null) {
if (isRequired) {
return new Error(`Required \`${propName}\` was not specified in \`${componentName}\`.`);
}
return undefined;
}
return validatorFn(props, propName, componentName);
' We declare a bunch of variables to hold which column each piece of data we want is
Public columnRange As String
Public notesColumn As String
Public ageColumn As String
Public maritalStatus As String
Public incomeColumn As String
Public occupationColumn As String
Public firstNameColumn As String
Public lastNameColumn As String
Public employerColumn As String
@dmmulroy
dmmulroy / useFetch.js
Last active November 15, 2019 03:50
Simple no nonsense useFetch hook for fetching JSON.
import React from 'react';
const defaultOpts = {};
// Technically works more like useFetchLatest
// If you supply opts make sure that it is memoized
export function useFetch(url, opts = defaultOpts) {
const [{ data, error, fetching }, setState] = React.useState({
data: null,
error: null,
function getGridColumnAndRowCount(grid, pageCount) {
let columns = 0;
let prevX;
for (const el of grid.children) {
const { x } = el.getBoundingClientRect();
if (prevX != null && x < prevX) {
break;
}
prevX = x;
columns++;
@dmmulroy
dmmulroy / rotate_windows.lua
Last active February 12, 2023 23:07
Neovim Rotate Windows command
vim.api.nvim_create_user_command("RotateWindows", function()
local ignored_filetypes = { "NvimTree", "fidget", "Outline" }
local window_numbers = vim.api.nvim_tabpage_list_wins(0)
local windows_to_rotate = {}
for _, window_number in ipairs(window_numbers) do
local buffer_number = vim.api.nvim_win_get_buf(window_number)
local filetype = vim.bo[buffer_number].filetype
if not vim.tbl_contains(ignored_filetypes, filetype) then