Skip to content

Instantly share code, notes, and snippets.

Avatar
🌞
Hello

Stephen Hanson stevehanson

🌞
Hello
View GitHub Profile
View ajax.js
// 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 / readme.md
Created Mar 28, 2020
Standard VS Code Settings
View readme.md

The autoFixOnSave rule requires Standard JS VS Code extension

I do not have "Format on Save" turned on globally because Standard is not configurable as formatter for JS or Ruby.

You can try by opening command palette from file and typing "Format document with", then "Set default for language".

View App.css
.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 Aug 1, 2019
Alternative to OpenURI for Rails Active Storage
View attach_file.rb
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 Feb 27, 2019
Circle CI config for Create React App
View config.yml
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 Jan 11, 2019
Typescript Factories
View factories-library.ts
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 Apr 16, 2018
Webpacker - When running tests, compile only if necessary
View rails_helper.rb
# 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 Mar 29, 2017
Node -- Upload directory to S3
View sync.js
// 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 Jan 23, 2017
Stripe Billing Period Logic
View billing_period.rb
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 Jun 17, 2016
Rails -- Google Sign In
View .env
# Create an app in the Google API console and paste ID and secret here
GOOGLE_CLIENT_ID=xxxxx
GOOGLE_CLIENT_SECRET=xxxxx