Transform Matching Text with Gsub in Ruby and Regular Expression
Here is a gist that demonstrates how easy it is to transform text using #gsub and a block with Ruby.
"Scs Epc Score".gsub (/scs|epc/i) { |i| i.upcase }
# => SCS EPC Score
For more helpful string extensions in Ruby check out our Ruby Gem on GitHub...
Written by Sean Behan on 06/17/2012
How to Extract all Images from a Webpage with Ruby
Here is a little ruby snippet that will download all pictures from a webpage.
Rather than using XPath, we are going to first reduce the source code to capture everything inside of quotes. Some websites use JSON w/in a script tag to lazy load images an...
Written by Sean Behan on 08/01/2018
link_to_function Rails Ajax Reference
Link_to_function syntax for Haml template. Notice the "|" pipe which will allow for new lines in your code.
= link_to_function( "Add Line Item") |
{|page| page.insert_html :bottom, :invoice_line_items, |
:partial => "line_item", :locals=>{:line_item=...
Written by Sean Behan on 06/17/2012
Carrier Email Addresses for Sending SMS over Email
Just for reference, here are the carrier email addresses for sending email as an SMS. Look up the carrier for the phone in question, then send an email in this format [telephonenumber]@[carrier-name.com]
Carrier Email to SMS Gateway
Alltel [10-digit p...
Written by Sean Behan on 06/17/2012
Roll Your Own Full Page Caching in Sinatra
It's as simple as this.
# app.rb
get '/:slug' do
@slug = File.basename("#{params[:slug]}")
@cache = "public/cache/#{@slug}.html"
if File.exists?(@cache)
File.read(@cache)
else
@post = Post.find_by(page: params[:slug])
...
Written by Sean Behan on 08/23/2013