Prev PageNext Page
How to cast a string of comma separated numbers into an array of integers for Postgres
If you have an string of numbers like "1,2,3" and you want to turn it into an array of integers you need to cast it into an integer array type. "{1,2,3}"::int[] This is commonly used together when grabbing a set using the ANY clause. sele...
Written by Sean Behan on 09/26/2013
Using Grep To Find or Match All Links in an HTML Document
egrep -or "(http(s)?://){1}[^'\"]+" path/to/directory You can further reduce to just return the images by piping again. grep -r src views/ | egrep -o "(mailto|ftp|http(s)?://){1}[^'\"]+" The -r flag is for a recursive directory scan....
Written by Sean Behan on 09/15/2013
Recursively Search Contents of a File with Grep
The -r flag is for recursive, meaning it will also look in sub directories. The -i flag is for case insensitivity, meaning WORD and word will both be found. grep -ir "search term" directory/path
Written by Sean Behan on 08/29/2013
How To Enable IFrame Support on Heroku with Ruby on Rails and Sinatra
This actually has more to do with Rails and/or Sinatra than it does with Heroku. You have to enable IFrame support in your headers explicitly. With Rails you can add this to your config/application.rb file config.action_dispatch.default_headers = ...
Written by Sean Behan on 08/25/2013
How To Increase or Change the File Upload Size in the PHP ini file for Wordpress
You need to find which configuration ini file has been loaded by PHP. The easiest way to do this is to run the phpinfo() function from the command line. php -r "phpinfo(); " | grep -i "loaded configuration file" You should see something like...
Written by Sean Behan on 08/24/2013
How To Create Blurry Background Images Programmatically from the Command Line or with Ruby
Turn this into this You can use ImageMagick to make blurry images. To install with Homebrew on OS X. brew install imagemagick After installing you can run from the command line convert yourimage.png -channel RGBA -blu...
Written by Sean Behan on 08/24/2013
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
A Regular Expression to Generate Dash Separated Slugs AKA Pretty URLs
This regular expression matches non alphanumeric characters in a string. r = /[^a-z0-9]{1,}/i You can use it to create URL friendly slugs. slug = "hello world!".gsub(/[^a-z0-9]{1,}/i, '-').downcase # => hello-world In combination wit...
Written by Sean Behan on 08/22/2013
JSON::GeneratorError: only generation of JSON objects or arrays allowed
If you run into this error message try switching to an earlier version of ExecJs. JSON::GeneratorError: only generation of JSON objects or arrays allowed # Gemfile gem 'execjs', '~> 1.4' gem 'coffee-script' gem 'sass' ...
Written by Sean Behan on 08/22/2013
How to Extract the Title From an HTML Page with Ruby
This snippet will make a request to this page and extract the title from the title tag. require 'open-uri' html = open('http://www.seanbehan.com/how-to-extract-the-title-from-an-html-page-with-ruby').read title = html.match(/(.*)/) { $1 } pu...
Written by Sean Behan on 08/22/2013
Prev PageNext Page