Skip to content

Instantly share code, notes, and snippets.


Jared Palmer jaredpalmer

View GitHub Profile
jaredpalmer / replaceValues.ts
Last active Aug 7, 2020
Replace all values of a given key
View replaceValues.ts
* Return a copy of an object, but with values of a key replaced with value of provided key-value object.
* Useful for duplicating highly nested object, but generating new values for a key (e.g. `id`)
* @param obj An object
* @param keyToReplace The key of the values needed to be swapped
* @param mapOfOldToNewValues A key-value object with a keys of old values mapped to new ones (used for swapping)
* @example
View Formik-Autosave.jsx
import React from 'react';
import PropTypes from 'prop-types'
import debounce from 'lodash.debounce' // or whatevs
import isEqual from 'lodash.isEqual'
class AutoSave extends React.Component {
static contextTypes = {
formik: PropTypes.object
View tweet.js
* Code snippet for posting tweets to your own twitter account from node.js.
* You must first create an app through twitter, grab the apps key/secret,
* and generate your access token/secret (should be same page that you get the
* app key/secret).
* Uses oauth package found below:
* npm install oauth
* For additional usage beyond status updates, refer to twitter api
View SuspenseRedirect.tsx
import { globalHistory, navigate, RedirectProps, History } from '@reach/router';
import React from 'react';
type ReachHistory = History & {
_onTransitionComplete: () => void;
* Why is `SuspenseRedirect` necessary when @reach/router has `Redirect`?
jaredpalmer /
Created Jul 21, 2020
Search String parser
package org.formium.util;
import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SearchUtil {
public static Map<String,String> parseSearchQuery(String query) {
jaredpalmer /
Created Jul 21, 2020
US Phone Validation w/ext
package org.formium.util;
import java.util.Optional;
public class ValidateUtil {
public static Optional<String> validatePhone(String phone) {
jaredpalmer / feed.xml
Created Nov 30, 2014
feed.xml for Jekyll
View feed.xml
layout: null
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="">
<title>{{ site.title | xml_escape }}</title>
<description>{{ site.description | xml_escape }}</description>
<link>{{ site.url }}{{ site.baseurl }}/</link>
<atom:link href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}" rel="self" type="application/rss+xml"/>
jaredpalmer / Video.js
Created Jul 8, 2020
Better <video> with intersection observer.
View Video.js
import { useRef, useCallback, useEffect } from 'react'
import { useInView } from 'react-intersection-observer'
import 'intersection-observer'
export default ({ src, caption, ratio }) => {
const [inViewRef, inView] = useInView({
threshold: 1,
const videoRef = useRef()
View forwardRefWithAs.tsx
import * as React from 'react';
* React.Ref uses the readonly type `React.RefObject` instead of
* `React.MutableRefObject`, We pretty much always assume ref objects are
* mutable (at least when we create them), so this type is a workaround so some
* of the weird mechanics of using refs with TS.
export type AssignableRef<ValueType> =
| {
jaredpalmer / App.js
Created May 30, 2017
Next.js-like SSR without Next.js.
View App.js
import React from 'react';
import Route from 'react-router-dom/Route';
import Link from 'react-router-dom/Link';
import Switch from 'react-router-dom/Switch';
const App = ({ routes, initialData }) => {
return routes
? <div>
{, index) => {
You can’t perform that action at this time.