Skip to content

Instantly share code, notes, and snippets.

View tvthatsme's full-sized avatar

Timothy Vernon tvthatsme

View GitHub Profile
@tvthatsme
tvthatsme / index.js
Created March 9, 2021 15:59
Image Conversion
const fs = require("fs");
const sharp = require("sharp");
const arguments = process.argv.slice(2);
const directory = arguments[0];
// This function is probably the useful part
async function convertToFormats(input, output) {
await sharp(input)
.avif({ quality: 80, speed: 3 })
@tvthatsme
tvthatsme / blog-comments-ideas.md
Created May 6, 2019 10:25
Ideas for comments on blog posts
@tvthatsme
tvthatsme / point-free-use-case.md
Last active March 29, 2019 14:26
Why use a point-free code style? Consider this example.

A use case for point-free programming

There’s a lot to love about functional programming. While this isn’t the place to layout the benefits or tradeoffs of the functional programming style, its safe to say that the concepts can bring a lot of order, power, and simplicity to your code. However, in all of that, it’s also easy to get lost in the weeds of terminology and mathematical jargon. My goal in this post is to take a shallow dive into the world of functional programming, currying, and point-free functions in JavaScript and explain one use case where functional programming improves the readability of a simple function.

Motivation

I was working on a JavaScript function this week that takes a timestamp and converts it to a date object in order to compare different dates. The original function looked like this:

/**
@tvthatsme
tvthatsme / window-location.js
Created February 7, 2019 11:42
Working with window.location.search
/**
* Create a string to use for the search element in window.location
*
* @params {string} search - the original window.location.search value
* @params {Object} params - the new params to add to the search
*/
export const createNewSearchParams = ({
search = window.location.search,
params = {},
}) => {
@tvthatsme
tvthatsme / scrolling.js
Last active February 6, 2019 11:57
Smooth scrolling
// Define a default animation duration
const defaultAnimationDuration = 6000;
/**
* Smoothly scroll the browser's window up or down a certain number of pixels
*
* @param {Number} pixels - the number of pixels to scroll the screen (positive or negative)
* @param {Number} [time=300] - the amount of time in milliseconds to annimate the scroll
*/
export const smoothScroll = (pixels, time = defaultAnimationDuration) => {
@tvthatsme
tvthatsme / system-font.css
Last active March 28, 2018 04:04
System Font Stack
/* Performance matters */
.system-font {
font-family: BlinkMacSystemFont,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;
}