Skip to content

Instantly share code, notes, and snippets.

View csandman's full-sized avatar

Chris Sandvik csandman

View GitHub Profile
@csandman
csandman / remove-cached-git-files.sh
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
csandman / use-scroll.js
Last active October 7, 2020 18:37
A react hook to add a scroll event listener with optional callbacks
// inspired by:
// https://gist.github.com/joshuacerbito/ea318a6a7ca4336e9fadb9ae5bbb87f4
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
csandman / fetch-with-timeout.js
Created June 17, 2020 20:11
An implementation of the fetch api with a timeout option
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) {
onTimeout();
@csandman
csandman / squashing-commits.md
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:

@csandman
csandman / get-number-with-ordinal.js
Created March 27, 2020 21:32
A function to get a number string with the ordinal suffix in JS
function getNumberWithOrdinal(n) {
const s = ["th", "st", "nd", "rd"];
const v = n % 100;
return n + (s[(v - 20) % 10] || s[v] || s[0]);
}
@csandman
csandman / aac-st.mmcp.xml
Created March 9, 2020 16:04
MakeMKV Profiles
<?xml version="1.0" encoding="utf-8"?>
<profile>
<!-- profile name -->
<name lang="eng">AAC-stereo</name>
<!-- Common MKV flags -->
<mkvSettings
ignoreForcedSubtitlesFlag="true"
useISO639Type2T="false"
setFirstAudioTrackAsDefault="true"
@csandman
csandman / handbrakecli-usage.txt
Created February 18, 2020 01:27
Documentation for the handbrake cli
Usage: HandBrakeCLI [options] -i <source> -o <destination>
General Options --------------------------------------------------------------
-h, --help Print help
--version Print version
--json Log title, progress, and version info in
JSON format
-v, --verbose[=number] Be verbose (optional argument: logging level)
-Z. --preset <string> Select preset by name (case-sensitive)
@csandman
csandman / setup.md
Last active December 19, 2019 15:51
Setup for a React project using ESLint and Prettier

Setup for ESLint and Prettier

Here is a quick guide for getting set up with a basic react app with eslint and prettier

Installation

  1. First run
npx create-react-app app-name
cd app-name
@csandman
csandman / web.config
Created December 3, 2019 21:19
Web config file to make create-react-app routing work in an Azure app service
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
@csandman
csandman / popup-center.md
Last active November 26, 2019 14:19
Center a popup window with 1 or 2 monitors

A somewhat niche problem is opening a centered popup window when you have multiple monitors. One you case you might encounter for this is opening a Twitter Web Intent window, which creates a tweet for a user to post. Here is their recomended code for opening a Web Intent popup:

(function() {
  if (window.__twitterIntentHandler) return;
  var intentRegex = /twitter\.com\/intent\/(\w+)/,
      windowOptions = 'scrollbars=yes,resizable=yes,toolbar=no,location=yes',
      width = 550,
      height = 420,
      winHeight = screen.height,