Writing
Notes on building software — the decisions that age well, the ones that don't, and what I learn in between.
-
A Ruby Regex for Removing Links and Images from Text
r = /https?:\/\/[\S]+/i youstring.gsub(r, '') Here's the rubular regex to play around with yourself http://rubular.com/r/SRKkYrW4IJ
-
How To Fix ActiveRecord::ConnectionTimeoutError with Sinatra
If you get this error message ActiveRecord::ConnectionTimeoutError could not obtain a database connection within 5.000 seconds (waited 5.001 seconds) Try closing the connection after each request...
-
Find a File On Your File System with the Unix Find Command By Extension
find path/ -name .txt
-
Open Files in TextMate 2 with A Single Click
To open files with a single click from the file browser inside of TextMate 2 run this command from the terminal defaults write com.macromates.TextMate.preview fileBrowserSingleClickToOpen -bool...
-
How to Create A Unix Timestamp or the Epoch in Python
It's a little convoluted. Seeing as it's a pretty common thing you use when programming computers one might think that there would be a quick and easy method for it. But from what I can tell there...
-
Roll Your Own Session Based Flash Messaging w/ Sinatra
Session based flash messages are fairly common in web apps. They work well when you have a temporary status to report back to the user, such as successfully saving a form. If you use Rails it comes...
-
How to Fix Line Wrap Bug in iPython Terminal on OS X Mavericks
There is annoying line wrap issue present after installing iPython on OS X Mavericks for the first time. The issue has to do with readline being missing. To fix the problem uninstall iPython,...
-
Change the Default Controller Name in Rails Functional Tests
Rails will infer the controller you want to test from the class name of the test case. For example... class PeopleControllerTest < ActionController::TestCase end will test the...
-
How to Use RVM and POW with Ruby 2.0.0
In your project's root directory add a .ruby-version file and add the ruby version to the file ruby-2.0.0-p247 Next source RVM in the .powrc file, also in your project's root directory. source...
-
A Couple of Usefule Snippets When Working with Textmate
Here is the snippet f path/to/directory 'search string' | open\in\mate This snippet (technically 2 snippets) will recursively scan the contents of files in a directory and then open all the files...
-
How To Pipe To A Ruby Command Line Application
You need to read from STDIN rather than parse command line arguments. while $stdin.gets puts $ end
-
How To Write Your Own Time Comparison Function in Ruby Like time_ago_in_words Without Rails
-
How to Boot Up Multiple Sinatra Applications at the Same Time with Foreman
Foreman is a process management gem for ruby applications. It is used in combination with a Procfile for configuration instructions. A typical Procfile looks something like this Example Rack...
-
How to Render Partials with an Underscore in Sinatra
Sinatra doesn't have a method for rendering partials. It defers to the template language of your choice. For instance, if you're using ERB, it's as simple as Rails has a nice convention of using an...
-
How to Split a Large File Into Smaller Files on OSX or Unix
Use the split command. You can set the number of lines (the "-l" flag) to split on and also the location of where the split files should be saved. Note, the output directory must already exists.