Skip to content

Instantly share code, notes, and snippets.

View stevehanson's full-sized avatar
🌞
Hello

Stephen Hanson stevehanson

🌞
Hello
View GitHub Profile
@stevehanson
stevehanson / setup
Created November 4, 2022 16:14
React Native bin/setup
#!/bin/bash
#
# Script to be run on new project setup. Run with `bin/setup`. Does the following:
#
# * Installs ENV and key files from 1Password (does not overwrite existing)
# * Runs bundle install, yarn install
# * Sets project environment to 'staging'
downloadFile() {
if [ -e $1 ]
@stevehanson
stevehanson / ajax.js
Created October 28, 2020 17:55
wait_for_ajax
// wrapper around axios for ajax functionality
// sets globals when fetching content to help with Rspec wait_for_ajax
// adapted from: https://gist.github.com/sheharyarn/7f43ef98c5363a34652e60259370d2cb
import axios from 'axios'
export const request = (options) => {
const onSuccess = (response) => {
popAjax()
window.current_ajax_request = null // for rspec wait_for_ajax
@stevehanson
stevehanson / App.css
Created February 5, 2020 17:48
React Pokedex
.pokemons {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
grid-column-gap: 1em;
grid-row-gap: 1em;
max-width: 700px;
margin: 0 auto;
}
.poke {
@stevehanson
stevehanson / attach_file.rb
Last active August 1, 2019 13:48
Alternative to OpenURI for Rails Active Storage
def attach_file(url)
with_downloaded_file(url) do |file|
my_model.attach(io: file, filename: "filename.jpg")
end
end
# this example requires the 'httparty' gem
def with_downloaded_file(url)
file = Tempfile.new
file.binmode
@stevehanson
stevehanson / config.yml
Last active February 27, 2019 19:00
Circle CI config for Create React App
version: 2
jobs:
build:
docker:
- image: circleci/node:10.11.0
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
- run:
@stevehanson
stevehanson / factories-library.ts
Last active January 11, 2019 16:25
Typescript Factories
import { times, upperFirst } from 'lodash';
type GeneratorFnOptions = {
sequence: number;
};
type GeneratorFn<T> = (opts: GeneratorFnOptions) => T;
type GeneratorsMap = {
[key: string]: GeneratorFn<any>;
};
@stevehanson
stevehanson / rails_helper.rb
Last active April 16, 2018 11:04
Webpacker - When running tests, compile only if necessary
# spec/rails_helper.rb
require_relative 'support/webpack_test_helper.rb'
# ...
config.before(:suite) do
# Compile webpack if necessary.
# Only runs if checksum of JS files has changed
WebpackTestHelper.compile_webpack_assets
end
@stevehanson
stevehanson / sync.js
Created March 29, 2017 19:10
Node -- Upload directory to S3
// requires following dependencies: yarn add s3 dotenv
var s3 = require('s3');
require('dotenv').config()
var client = s3.createClient({
s3Options: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
});
@stevehanson
stevehanson / billing_period.rb
Created January 23, 2017 16:35
Stripe Billing Period Logic
class BillingPeriod
attr_reader :start, :end
def initialize(start_dt, end_dt)
@start = start
@end = end_dt
end
# the bill day can always be determined from any given period
# eg: if bill day is 1-28, the start and end will both always be on 28
@stevehanson
stevehanson / .env
Created June 17, 2016 22:08
Rails -- Google Sign In
# Create an app in the Google API console and paste ID and secret here
GOOGLE_CLIENT_ID=xxxxx
GOOGLE_CLIENT_SECRET=xxxxx