Skip to content

Instantly share code, notes, and snippets.

View gregblass's full-sized avatar

Greg Blass gregblass

View GitHub Profile
@remino
remino / wpautop for ruby
Created July 3, 2012 00:44 — forked from goofmint/wpautop for ruby
WordPress's wpautop function port to ruby.
def wpautop(pee, br = true)
return '' if pee.strip == ''
pee = "#{pee}\n" # just to make things a little easier, pad the end
pee = pee.gsub(/<br \/>\s*<br \/>/s, "\n\n")
# pace things out a little
allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
pee = pee.gsub(Regexp.new('(<'+allblocks+'[^>]*>)'), "\n"+'\1')
pee = pee.gsub(Regexp.new('(<\/'+allblocks+'[^>]*>)'), '\1' + "\n\n")
pee = pee.gsub(/\r\n|\r/, "\n") # cross-platform newlines
if pee.include?('<object')
@turadg
turadg / subdomains.rb
Last active January 21, 2024 19:45 — forked from rtekie/subdomains.rb
Drop-in utility to test your app subdomains with Capybara, Rspec, and a Javascript driver (Poltergeist, Webkit, or Selenium)
# Support for Rspec / Capybara subdomain integration testing
# Make sure this file is required by spec_helper.rb
# (e.g. save as spec/support/subdomains.rb)
def switch_to_subdomain(subdomain)
# lvh.me always resolves to 127.0.0.1
hostname = subdomain ? "#{subdomain}.lvh.me" : "lvh.me"
Capybara.app_host = "http://#{hostname}"
end
@micahroberson
micahroberson / estimate.rb
Created July 13, 2013 00:35
Generate and save a pdf to S3 with wicked_pdf and paperclip
# Main reference was lascarides' post at http://stackoverflow.com/questions/14743447/getting-pdf-from-wickedpdf-for-attachment-via-carrierwave
# estimate.rb
# ...
has_attached_file :pdf,
storage: :s3,
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket: ENV['AWS_BUCKET']
@ejholmes
ejholmes / pusher.turbolinks.js
Last active December 20, 2015 12:59
Turbolinks support for Pusher.js
@tomas-stefano
tomas-stefano / Capybara.md
Last active July 3, 2024 12:47
Capybara cheatsheet

Capybara Actions

# Anchor
click_link 'Save'

# Button
click_button 'awesome'

# Both above
@virtualstaticvoid
virtualstaticvoid / active_relation_extensions.rb
Last active May 22, 2019 17:51
A better `find_each` and `find_in_batches` for ActiveRecord, which preserves the original order of the query
module ActiveRelationExtensions
def find_each_with_order(options = {})
find_in_batches_with_order(options) do |records|
records.each { |record| yield record }
end
end
# NOTE: any limit() on the query is overridden with the batch size
def find_in_batches_with_order(options = {})
@basti
basti / application.rb
Last active March 1, 2021 10:42 — forked from keighl/application.rb
Local Rails 4 assets precompilation using Capistrano 3 and rsync
# Speed things up by not loading Rails env
config.assets.initialize_on_precompile = false
@JamesChevalier
JamesChevalier / gist:6868539286a5c291522b
Created November 3, 2014 16:36
MailChimp signup in Ruby using mailchimp-api gem without double opt-in
require 'mailchimp'
mailchimp = Mailchimp::API.new(ENV['mailchimp_api_key'])
mailchimp.lists.subscribe(ENV['mailchimp_list_id'],
{ email: 'test@example.com' },
{ 'FNAME' => 'First Name', 'LNAME' => 'Last Name' },
'html',
false)
# So the format is:
# mailchimp.lists.subscribe(list_id, { email: address }, { merge_vars }, 'email type', double_optin_boolean)

The issue:

..mobile browsers will wait approximately 300ms from the time that you tap the button to fire the click event. The reason for this is that the browser is waiting to see if you are actually performing a double tap.

(from a new defunct https://developers.google.com/mobile/articles/fast_buttons article)

touch-action CSS property can be used to disable this behaviour.

touch-action: manipulation The user agent may consider touches that begin on the element only for the purposes of scrolling and continuous zooming. Any additional behaviors supported by auto are out of scope for this specification.

@fernandoaleman
fernandoaleman / mysql2-mojave.md
Last active February 7, 2024 19:19
Install mysql2 on MacOS Mojave

For MacOS Catalina, visit Install mysql2 on MacOS Catalina

Problem

Installing mysql2 gem errors on MacOS Mojave.

Solution

Make sure openssl is installed on Mac via Homebrew.