Skip to content

Instantly share code, notes, and snippets.

import NavigationService from 'admin/services/navigation';
export default {
name: 'navigation',
initialize(container, app) {
var navigation = NavigationService.create({
links: [
{ name: 'Posts', link: 'posts'},
{ name: 'Settings', link: 'settings'},
],
@stevehanson
stevehanson / bug.rb
Last active March 28, 2017 17:30
Bug Tracking
class Bug
# log an error message to standard out
def self.log(message, data = {})
raise StandardError.new(message)
rescue => e
log_error(e, data)
end
# log an error/exception to standard out
def self.log_error(error, data = {})
@stevehanson
stevehanson / Readme.md
Last active March 16, 2016 21:50
Gulp WP setup

Gulp WP setup

Includes a Gulp task that will watch the JavaScript and SCSS files and automatically build (compile, concat, minify, etc) them when they change. To set this up, perform the following steps:

  • Install Node.js and NPM
  • place package.json and gulpfile.js in your WP theme directory (eg. wp-content/themes/my-theme)
  • Navigate in your terminal to your theme directory
  • Install dependencies: npm install
  • Install the Gulp CLI: npm install -g gulp-cli
  • Run the Gulp watch task: gulp
@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
@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 / 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 / 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 / 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 / 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 / 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