Skip to content

Instantly share code, notes, and snippets.

View stephancom's full-sized avatar

stephan.com stephancom

View GitHub Profile
@stephancom
stephancom / stripe_customer.rb
Created March 21, 2014 03:54
Stripe Customer rails concern
# _ _
# __| |_ _ _(_)_ __ ___
# (_-< _| '_| | '_ \/ -_)
# /__/\__|_| |_| .__/\___|
# |_|
# __ _ _ __| |_ ___ _ __ ___ _ _
# / _| || (_-< _/ _ \ ' \/ -_) '_|
# \__|\_,_/__/\__\___/_|_|_\___|_|
#
# (c) 2013 stephan.com
@stephancom
stephancom / _poly_picker.html.slim
Last active August 21, 2019 14:48
polyPicker - allows for picking a polymorphic object in ActiveAdmin formtastic with select
/ _ ___ _ _
/ _ __ ___| |_ _| _ (_)__| |_____ _ _
/ | '_ \/ _ \ | || | _/ / _| / / -_) '_|
/ | .__/\___/_|\_, |_| |_\__|_\_\___|_|
/ |_| |__/ s.c14
/ This partial is meant to allow for picking an object of polymorphic type, returning both a type and id
/ It is comprised of two select elements, the first of which controls the available choices in the second
/ It relies on the poly_picker.js.coffee script on the front end
/ It expects to find these locals:
@stephancom
stephancom / footer.html.slim
Created July 1, 2014 21:10
footer trick for year
@stephancom
stephancom / 5x5.rb
Created July 25, 2014 03:39
blacksmith gunpowdery
#!/usr/bin/ruby
# (c) 2007 stephan.com
# A program to impress Grace
# Finds five words of five letters using all unique letters
Goodwords = []
CompareMatrix = {}
# returns true if any letters are shared between two strings
def has_common_letters?(a, b)
@stephancom
stephancom / txt_rotate.coffee
Last active February 21, 2016 11:51
coffeescript text carousel
# by: _ _
# __| |_ ___ _ __| |_ __ _ _ _ __ ___ _ __
# (_-< _/ -_) '_ \ ' \/ _` | ' \ _/ _/ _ \ ' \
# /__/\__\___| .__/_||_\__,_|_||_(_)__\___/_|_|_|
# |_| stephan@stephan.com
# Unobtrusive txtRotate
# http://codepen.io/stephancom/details/pgXypp/
# applies to all elements with data-rotate
@stephancom
stephancom / preloader.coffee
Last active February 21, 2016 11:52
unobtrusive coffee script preloader
# by: _ _
# __| |_ ___ _ __| |_ __ _ _ _ __ ___ _ __
# (_-< _/ -_) '_ \ ' \/ _` | ' \ _/ _/ _ \ ' \
# /__/\__\___| .__/_||_\__,_|_||_(_)__\___/_|_|_|
# |_| stephan@stephan.com
# unobtrusive preloader
# applies to all elements with data-preload
# expects
@stephancom
stephancom / active_admin_aasm.rb
Created May 2, 2016 03:38
Automatic admin for AASM
@resource.aasm.events.each do |event|
member_action event.name, method: :post do
resource.send(event) if resource.aasm.may_fire_event?(event.name)
end
action_item event, only: :show, if: -> { resource.aasm.may_fire_event?(event.name) } do
link_to event.name.capitalize, action: event.name, controller: :ties, method: :post
end
batch_action event.name do |ids|
klass = controller_name.classify.constantize
@stephancom
stephancom / fizzbench.rb
Created January 4, 2017 06:24
FizzBuzz - generalized, improved, tested, benchmarked
# fizzbuzz benchmark - comparing different versions of the classic
# stephan.com
require 'rspec'
require 'benchmark'
require 'formatador'
# suppress output
def no_stdout
ostd = $stdout
@stephancom
stephancom / recurse_keys.rb
Created March 24, 2017 21:01
recursive hash keys
# Returns keys from a hash recursively when that hash can contain hashes
# Handy for use with StrongParameters
recurse_keys = lambda do |h| h.inject([]) { |a, (k, v)| a << (v.is_a?(Hash) ? { k => recurse_keys.call(v) } : k) } rescue [] end
# Example
parms = {:foo=>:bar, :baz=>{:a=>:b, :c=>:d, :e=>:f}}
recurse_keys.call(parms)
# returns [:foo, {baz: [:a, :b, :c]}]
@stephancom
stephancom / rspec-crud.sublime-snippet
Last active April 5, 2017 15:25
Sublime snippet for sketching out CRUD+index in rspec
<snippet>
<content><![CDATA[
describe '${1:model_name} collection' do
${2:pending 'needs tests'}
end
describe 'CRUD ${1:model_name}' do
describe 'create' do
${3:pending 'needs tests'}
end
describe 'read' do