#ruby
15 posts tagged ruby. Clear filter
-
Rails Style Params in Python and Flask
Ruby on Rails does a great job of parsing arrays in form data and populating a params hash, for quick and easy access in your controllers. For instance <input name="item[]" value="item 1"/ <input...
-
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...
-
Generate a Gravatar URL with Ruby
To get a Gravatar you need to hash an email address with the MD5 algorithm. MD5 is a part of the Ruby standard library. Rails loads it by default, but otherwise you will have to require it...
-
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...
-
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 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...
-
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...
-
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...
-
How to Add Additional Sub Directories to the Default Rails Test:Unit File Structure
Edit Rakefile in project root Add a new rake test task... E.g., rake test:lib, below everything else in that file... Alternatively, add a task in lib/tasks/ directory and plop in the same code...