Skip to content

Instantly share code, notes, and snippets.

View coreyward's full-sized avatar

Corey Ward coreyward

View GitHub Profile
@coreyward
coreyward / usePersistantState.js
Created July 26, 2020 19:32
Async Storage backed `useState` for React Native
import { useState, useEffect, useCallback } from "react";
import { useAsyncStorage } from "@react-native-community/async-storage";
/**
* @example
* const [isReady, setReady, refresh] = usePersistantState(199, "ready")
*/
export default (id, property, defaultValue = null) => {
const [value, setValue] = useState(defaultValue);
const { getItem, setItem } = useAsyncStorage(`${id}#${property}`);
@coreyward
coreyward / README.md
Last active November 7, 2021 09:39
I wrote this hook to persist a simple user settings (think dark mode) to local storage in a cross-tab compatible way.

useStorage React Hook

Similar to useState but with some lightweight behind-the-scenes writing to localStorage; also subscribes to changes in localStorage to allow for cross-tab changes to sync automatically.

Example Usage

The first argument is the name of the local storage property/key you want to control with this hook. The second argument, options, really just has one available directive: bool. Setting bool to true has the effect of evaluating the data

@coreyward
coreyward / date_formatting.rb
Created July 21, 2017 00:57
Copy-pasteable Rails initializer that will handle date to string conversion and parsing (with output as MM/DD/YYYY by default)
Date::DATE_FORMATS[:default] = "%m/%d/%Y"
module FixDateFormatting
class EasyDate < ActiveRecord::Type::Date
def cast_value(value)
default = super
parsed = Chronic.parse(value)&.to_date if value.is_a?(String)
parsed || default
end
end
@coreyward
coreyward / theme.css
Created April 6, 2017 20:00
Acton Wufoo Theme
html,
body {
font-family: "Open Sans", Helvetica, Arial;
background: #1A293E;
color: #fff;
}
#logo,
#header {
display: none;

Keybase proof

I hereby claim:

  • I am coreyward on github.
  • I am coreyward (https://keybase.io/coreyward) on keybase.
  • I have a public key whose fingerprint is 588A B309 8DE7 3379 60A5 6BE5 8095 E17F 15D4 EE89

To claim this, I am signing this object:

@coreyward
coreyward / gist:60b7eb23373f40f9ebcb
Created June 30, 2014 21:21
Track outbound link clicks in Google Analytics (Universal / analytics.js) with fallback
# only bind if/when GA loads
ga ->
$('a[href*="//"]').click (e) ->
e.preventDefault()
url = $(this).attr('href')
# define the callback
action = -> document.location = url
# record the click as an event
@coreyward
coreyward / gist:e34898d09968f5aa4aa6
Created June 30, 2014 21:13
Non-blocking iFrame loads, because Vimeo embeds are slow to load, and iFrames block onLoad firing (and thus negatively impact pageload measurements).
# Non-Blocking iFrames
$ ->
$('iframe[data-src]').each ->
this.setAttribute 'src', this.getAttribute 'data-src'
@coreyward
coreyward / baseline_tattler.js
Last active August 29, 2015 13:57
Quick and dirty way to find DOM elements that are breaking your vertical baseline grid.
$('div,p,section,header,footer,ul,ol,li').each(function(){
var h, el, baseline;
el = $(this);
height = el.outerHeight();
baseline = 13;
if (Math.round(height) % baseline > 0) {
el.addClass('boink');
console.log( height, this );
@coreyward
coreyward / The Back Bar.md
Last active December 27, 2015 12:59
The standard bar stock at PDT in NYC, per *The PDT Cocktail Book*.

PDT Stocked Liquors

Vodka

  • Absolut 100
  • Belvedere
  • Heart of the Hudson
  • Karlsson's
  • Smirnoff Black