Skip to content

Instantly share code, notes, and snippets.


Chris Sandvik csandman

  • PrivCo
  • Somerville, MA
View GitHub Profile
csandman / itunes.js
Last active February 22, 2022 20:24
Grab the response from the iTunes API for a book search and get the hi-res cover url in the process
View itunes.js
import { URLSearchParams } from "url";
* Check whether a URL string is in a proper format
* @param {string} str A URL string to check for the correct structure
* @returns
const isUrl = (str) => {
if (typeof str !== "string") {
csandman / query-string.js
Created April 16, 2021 19:54
Utility functions for parsing a query parameter string and stringify-ing a query parameter object
View query-string.js
* Stringify an object containing query parameters to be used in a request
* @param {object} paramObj An object containing query paramaters
* @returns {string} A string in the format of a query param
export const stringifyQuery = (paramObj) =>
new URLSearchParams(paramObj).toString();
csandman /
Last active March 9, 2023 00:26
Chakra UI React Select

Chakra React Select

UPDATE: I finally made an NPM package for this component! It is made with TypeScript, and now has a fully customizable styling system. It is also far ahead of this wrapper at this point. Check it out here if you'd like:

In order to use this component, you can implement it and use it like you would normally use react-select. It should accept all of the props that the original takes, however customizing the theme or the components could break this implementation. There are also a few extra things you can do with this wrapper that pull from the chakra library.

  • You can pass the size prop with either sm, md, or lg. These will reflect the sizes available on the Chakra <Input /> component (with the exception of xs because it's too small to work).
  • In your options objects, you can add the key isFixed to emulate the exa
View date-utils.js
// milliseconds in 1 second
export const MS_IN_S = 1000;
// seconds in 1 minute
export const S_IN_M = 60;
// minutes in 1 hour
export const M_IN_H = 60;
// hours in 1 day
export const H_IN_D = 24;
// days in 1 year
export const D_IN_Y = 365;
csandman / debounce-swr.js
Last active January 28, 2023 16:48
Debounce useSwr
View debounce-swr.js
// originally from:
import useSWR from 'swr';
import useDebounce from 'hooks/use-debounce';
const App = () => {
const [search, setSearch] = useState('');
const debouncedSearch = useDebounce(search, 1000);
const { data: res, isValidating } = useSWR(
() => debouncedSearch ? `/api/suggestion?value=${debouncedSearch}` : null,
csandman / compare-emails.sql
Last active March 4, 2021 22:32
Check if 2 emails in match in tsql
View compare-emails.sql
-- Written for TSQL
CREATE FUNCTION dbo.CompareEmails(
@Email1 AS NVARCHAR(MAX) = '',
@Email2 AS NVARCHAR(MAX) = ''
-- Basic check to see if each string is an email
IF LEN(@Email1) = 0
csandman /
Created February 12, 2021 20:09
A git command to remove all files that have been added to the .gitignore from github
git rm -r --cached . && git add . && git commit -am "Remove ignored files" && git push
csandman / use-scroll.js
Last active October 7, 2020 18:37
A react hook to add a scroll event listener with optional callbacks
View use-scroll.js
// inspired by:
import { useEffect, useState } from 'react';
const isValidFunction = (func) => {
return func && typeof func === 'function';
export default function useScroll({ onScroll, onScrollUp, onScrollDown }) {
const [scroll, setScroll] = useState(
csandman / fetch-with-timeout.js
Created June 17, 2020 20:11
An implementation of the fetch api with a timeout option
View fetch-with-timeout.js
function fetchWithTimeout(url, options, timeout, onTimeout) {
const timer = new Promise((resolve) => {
setTimeout(resolve, timeout, {
timeout: true,
return Promise.race([fetch(url, options), timer])
.then((response) => {
if (response.timeout) {
csandman /
Last active May 1, 2020 16:55
A simple process for squashing commits before (or after) making a pull request

How to Squash Git Commits

Borrowed from wprig

Some applications that interact with git repos will provide a user interface for squashing. Refer to your application's document for more information.

If you're familiar with Terminal, you can do the following: