Writing
Notes on building software — the decisions that age well, the ones that don't, and what I learn in between.
-
How To Remove Duplicates From a Table with Postgres
Let's create a table that will hold some dummy data. create table fruits (id serial primary key, name varchar, color varchar); insert into fruits (name, color) values ('apple', 'red'); insert into...
-
How to cast a string of comma separated numbers into an array of integers for Postgres
If you have an string of numbers like and you want to turn it into an array of integers you need to cast it into an integer array type. This is commonly used together when grabbing a set using the...
-
Using Grep To Find or Match All Links in an HTML Document
You can further reduce to just return the images by piping again. The -r flag is for a recursive directory scan.
-
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.
-
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...
-
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. You should see something like "Loaded...
-
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. After installing you can run from the command line You can run this from your Ruby scripts with...
-
Roll Your Own Full Page Caching in Sinatra
It's as simple as this. Use File.basename to make sure that params[:page] doesn't contain path information. This way arbitrary requests aren't able to traverse the filesystem. Then just check to...
-
A Regular Expression to Generate Dash Separated Slugs AKA Pretty URLs
This regular expression matches non alphanumeric characters in a string. You can use it to create URL friendly slugs. In combination with Stringgsub it will replace the non alphanumeric characters...
-
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.
-
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. The regular expression here matches everything between the title tags. Anything within the parens "(.\)" is...
-
Testing current_user and Sessions with Sinatra and Rack Test
Assume you have your standard Sinatra application. app.rb require 'sinatra' configure do enable :sessions end get '/' do if session[:userid] "OK" else raise "NOT OK!" end end To test this you need...
-
How To Use Rake to Run Your Test Suite with Sinatra
If you're using Sinatra and you want to use rake to run your test suite, you will need to create a Rakefile and put this in it. This assumes your test suite is under the 'test/' directory and the...
-
Pretty Formatted JSON from the Command Line
Sometimes you want to see JSON from the command line. I'm sure there are better tools for the job, but here is a little snippet you can throw in your /.bash\profile. Usage
-
Deploying Wordpress on Heroku
\ This post is out of date - Heroku officially supports PHP now w/ buildpacks Heroku runs Apache version 2.2.22 PHP version 5.3.10 Deploying Wordpress to Heroku requires that you throw the...