Skip to content

Instantly share code, notes, and snippets.

View richardvanbergen's full-sized avatar
🐛
Debugging

Richard Vanbergen richardvanbergen

🐛
Debugging
View GitHub Profile
aeschli.vscode-css-formatter
ahmadawais.shades-of-purple
andys8.jest-snippets
asvetliakov.vscode-neovim
austenc.tailwind-docs
bierner.color-info
bmewburn.vscode-intelephense-client
bradlc.vscode-tailwindcss
burkeholland.simple-react-snippets
capaj.vscode-standardjs-snippets
import AWS from 'aws-sdk'
import { UploadedFile } from 'express-fileupload'
import {
BeforeOperationHook,
BeforeValidateHook,
BeforeChangeHook,
AfterChangeHook,
BeforeReadHook,
AfterReadHook,
BeforeDeleteHook,
@richardvanbergen
richardvanbergen / flatteningarraysofintegers.js
Created March 6, 2019 07:47
Flattens an array of integers, throws if invalid input.
// DEMO: https://observablehq.com/@richardvanbergen/flattening-arrays-of-things
function flatten(arr) {
let flatArr = []
for (let num of arr) {
if (!Array.isArray(num) && !Number.isInteger(num)) {
throw new Error(`Input '${num}' is not an integer!`)
}
if (Array.isArray(num)) {
export function flatten(inputArr) {
return inputArr.reduce((outputArr, input) => {
if (Array.isArray(input)) {
return outputArr.concat(flatten(input))
}
outputArr.push(input)
return outputArr
}, [])
}
exports.default = complete(grid) => {
// not really necessary but not a negative either, this function can just be init code at the top
createGrid = createGrid() => {}
// again, this function can be init code if you want it to be, not important
identifyMissing = identifyMissing() => {}
// now you don't have to pass around `grid` all the time, your functions aren't as pure but this isn't really
// a functional programming style anyway and it's fine in this instance to be honest
availableRow = availableRow(row, num) => {}
@richardvanbergen
richardvanbergen / lodash-comparison.js
Last active October 21, 2015 11:17
A comparison of using lodash vs not using it.
/**
* With lodash
*/
const fetchDestinationsFor = (city, excludeUncommon, sortFn) => {
const chain = _.chain(city)
.result('destinations', [])
.filter(excludeUncommon ? (x => x.common == true) : (x => true))
.map(x => fetchBySlug(x.reference))
.sortBy(sortFn || (x => true));
@richardvanbergen
richardvanbergen / gist:45c833b7bdf40cf274c0
Created August 27, 2014 13:26
Method to improve Angular.js's handling of module definitions without modifying angular itself.
(function(window, angular) {
'use strict';
/**
* Register or fetch a module. Angular doesn't handle modules in this way usually, overriding the module instead of
* extending it. So controllers/services/directives/etc can't share the same namespace without separating the
* module definition from the module implementation, leading to files with one line in them or one file of module
* definitions.
*
* @param name {string} Module name.
// earlier in the document
// cache DOM object lookups
$.app.elems = {
body: $('body'),
appContainer: $('#app-page'),
pages: $('.page'),
nav: $('#nav'),
focusInputs: $(
'select,' +
@richardvanbergen
richardvanbergen / aliases
Created June 6, 2013 15:16
List of aliases.
-='cd -'
..='cd ..'
...='cd ../..'
1='cd -'
2='cd +2'
3='cd +3'
4='cd +4'
5='cd +5'
6='cd +6'
7='cd +7'