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 / Gemfile
Last active February 4, 2021 23:06
Rails – Simple Google Login
gem "omniauth"
gem "omniauth-google-oauth2"
@stevehanson
stevehanson / Email.java
Created May 8, 2014 14:37
Mailgun Example - Java
package com.abc.model;
import java.util.List;
public class Email {
private String from;
private List<String> to;
private List<String> cc;
private List<String> bcc;
@stevehanson
stevehanson / es-attach-full.py
Last active November 22, 2020 21:22
Interactive Python script to recursively index files in directory tree to elasticSearch using the elasticsearch-mapper-attachments (https://github.com/elasticsearch/elasticsearch-mapper-attachments) plugin to index files (pdf, docx, html, etc).
import os
import sys
# constants, configure to match your environment
HOST = 'http://localhost:9200'
INDEX = 'test'
TYPE = 'attachment'
TMP_FILE_NAME = 'tmp.json'
# for supported formats, see apache tika - http://tika.apache.org/1.4/formats.html
INDEX_FILE_TYPES = ['html','pdf', 'doc', 'docx', 'xls', 'xlsx', 'xml']
@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 / emblem_to_hbs.rb
Last active February 22, 2019 21:54
Convert all project Emblem files to handlebars
class EmblemToHbs
def convert
Dir.glob("**/*.emblem").each do |file|
convert_file(file)
end
end
def convert_file(file)
`emblem2hbs #{file}`
File.delete(file)
@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>;
};