Skip to content

Instantly share code, notes, and snippets.

View Enado95's full-sized avatar

O'Dane Brissett Enado95

  • Jamaica
View GitHub Profile
@miguelmota
miguelmota / nearestDate.js
Created March 16, 2022 03:37
JavaScript get nearest date timestamp from list of date timestamps
function nearestDate (dates, target) {
if (!target) {
target = Date.now()
} else if (target instanceof Date) {
target = target.getTime()
}
let nearest = Infinity
let winner = -1
@joshnuss
joshnuss / httpStore.js
Last active October 11, 2023 11:29
A Svelte store backed by HTTP
import { writable } from 'svelte/store'
// returns a store with HTTP access functions for get, post, patch, delete
// anytime an HTTP request is made, the store is updated and all subscribers are notified.
export default function(initial) {
// create the underlying store
const store = writable(initial)
// define a request function that will do `fetch` and update store when request finishes
store.request = async (method, url, params=null) => {
@slavafomin
slavafomin / nodejs-custom-es6-errors.md
Last active January 30, 2026 17:29
Custom ES6 errors in Node.js

Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.

I've tried to make it as lean and unobtrusive as possible.

Defining our own base class for errors

errors/AppError.js