Skip to content

Instantly share code, notes, and snippets.

@uhlenbrock
uhlenbrock / Braze > Lambda > S3
Last active February 7, 2019 17:47
Use Lambda & S3 to save a copy of all sent email via Braze
Webhook URL: https://<api_gateway_url>/prod/uploadEmail?user_id={{${user_id}}}&template_name=<template_name>
Request Body: (select raw text), paste in entire email HTML
@uhlenbrock
uhlenbrock / aggregate.rb
Created June 15, 2017 19:42
Aggregate minitest failures in S3
module Minitest
def self.plugin_aggregate_init
reporter << Aggregate.new
end
class Aggregate
attr_accessor :branch
attr_accessor :build
attr_accessor :failed_tests
attr_accessor :timestamp
@uhlenbrock
uhlenbrock / barcode_analyzer.rb
Last active June 9, 2017 19:37
Read Barcodes with a Dragonfly Analyzer
class BarcodeAnalyser
def call(app, opts = {})
# OS X: `brew install zbar`
# Ubuntu: `apt-get install zbar-tools`
app.env[:zbar_command] = opts[:zbar_command] || 'zbarimg'
app.define :barcode do
@barcode ||= begin
shell_eval { |path| "#{app.env[:zbar_command]} -q --raw #{path}" }
rescue Dragonfly::Shell::CommandFailed => e
@uhlenbrock
uhlenbrock / dragonfly.rb
Last active June 9, 2017 19:36
Read EXIF data with a Dragonfly Analyzer
require 'dragonfly'
require 'exif_analyser'
Dragonfly.app.configure do
plugin ExifAnalyser.new
end
@uhlenbrock
uhlenbrock / init.coffee
Created March 13, 2014 21:13
Open the last migration created in a rails project
atom.workspaceView.command 'last-migration', ->
migrate_directory = atom.project.getRootDirectory()
migrate_directory.path = "#{migrate_directory.path}/db/migrate"
last_migration = migrate_directory.getEntriesSync().pop()
atom.open
pathsToOpen: [last_migration.path]
@uhlenbrock
uhlenbrock / init.coffee
Created March 13, 2014 17:27
Force Atom to load rails grammar over ruby grammar
path = require 'path'
atom.workspaceView.eachEditorView (editorView) ->
editor = editorView.getEditor()
grammar = switch path.extname(editor.getPath())
when '.rb' then atom.syntax.grammarsByScopeName['source.ruby.rails']
when '.erb' then atom.syntax.grammarsByScopeName['text.html.ruby']
@uhlenbrock
uhlenbrock / sale.rb
Created October 30, 2012 20:50
Refactor a type implementation
###---------------------------------------------------- Class Methods
def sale_type
@sale_type ||= Sale.sale_type_ids[ self.sale_type_id - 1 ][0]
end
###---------------------------------------------------- Class Methods
def self.sale_type_ids
@uhlenbrock
uhlenbrock / application_controller.rb
Created April 12, 2012 13:38
Implement Lorem in Rails
require 'lorem'
class ApplicationController < ActionController::Base
layout 'public'
helper_method :lorem
def lorem
@lorem ||= LoremObject.new
end
@uhlenbrock
uhlenbrock / deploy.rb
Created December 14, 2011 17:36
Precompile assets locally for Capistrano deploy
load 'deploy/assets'
namespace :deploy do
namespace :assets do
desc 'Run the precompile task locally and rsync with shared'
task :precompile, :roles => :web, :except => { :no_release => true } do
%x{bundle exec rake assets:precompile}
%x{rsync --recursive --times --rsh=ssh --compress --human-readable --progress public/assets #{user}@#{host}:#{shared_path}}
%x{bundle exec rake assets:clean}
end
@uhlenbrock
uhlenbrock / integration_test_helper.rb
Created September 7, 2011 17:16
Integration Testing with Capybara & Devise
require 'test_helper'
require 'capybara/rails'
require 'devise/test_helpers'
class ActionController::IntegrationTest
include Capybara::DSL
include Warden::Test::Helpers
self.use_transactional_fixtures = false