Some time ago gemspec files for ruby gems added the ability to specify the short identifier for the license type …
read moreOther articles
"Ruby Methods and Splat"
Ruby methods can set default values for optional arguments:
def commit(path=Dir.pwd)
To take an optional number of …
read more"Thor Adding --verbose"
With a command line Ruby application using Thor for the option parsing I want to be able to run:
read more$ thor_app …
"Thor Variable Arguments"
"Ruby Print Array"
"Ruby iterate over lines in a string"
"Monkey Patch Octopress"
Based on post_filters by imathis.
First Move the original method out the way with
read morealias_method
then create a new method …"Ruby Evaluate Envvars in string."
In ruby Dir.entries takes a path and returns a list of its contents. However it does not deal with …
read more"Ruby: optionally add path separator"
I was wanting to use Dir.glob to get a file list and wanted to do
read moreDir.glob( path + '*')
but …"Ruby duck typing Strings and Arrays"
How to get method which handles a single string input or an array of strings?
Splat *
* turns single strings into …
read more"Print nested array structures in table format"
Problem
Take an array of arrays and format it for displaying to the terminal or outputting to a text file …
read more"Converting flat structure into a nested structure"
Given a flat hierarchy of data comprising level and a label, aim to nest the lower level of objects in …
read more"Mountain Lion Setup, Part 2 Homebrew & RVM"
Following on from Macbook Pro Setup, Now it is time to install some of the command line tools.
I have …
read more"Web Automation with Watir"
"Create And,Or of multiple booleans"
To reduce an array of Booleans to a single Boolean using enumerables reduce method:
read more[true, true, true].reduce( :| ) ## OR => true …
"rspec testing exceptions"
"rspec testing exceptions (old post)"
"Ruby special exception variables made mnemonic"
In ruby you can catch StandardErrors using begin rescue end
read morebegin #Some thing which might fails rescue $stderr.puts $! end …
"Handle www. and no-www for better google juice"
There was an interesting post on hacker news recently, safeshepherd suddenly fell off the google for their own name. The …
read more"Syntax error: Not a valid color stop: Sass::Script::String: white"
After making a few updates to my site it stopped working after deploying. The issue was that the gem version …
read more"Minify your HTML from Sinatra"
There are gzip compression options available but when I looked at this a long time ago I found that the …
read more"Sinatra application in ./lib and views, public routes not working"
I have been setting up my recent Sinatra projects with a standard ruby project layout putting all of the application …
read more"Update your RVM Ruby and migrate gemsets"
Update RVM
$ rvm get head
List current versions, and all versions
$ rvm list $ rvm list known
Select the version you …
read more"Encoding::UndefinedConversionError - "
Are you running into the following error
Encoding::UndefinedConversionError - "\xE2" from ASCII-8BIT to UTF-8:
If you are using Ruby and …
read more"irb as a Megapixels calculator"
I have just added the method below to my ruby .irbrc file for quickly calculating image megapixels. from OS X …
read more"matrix: A Ruby Standard Library"
Originally written as an assignment for Ruby Mendicant University.
matrix is part of the Ruby Standard Library
Usage
A note …
read more"Ruby get a users real name"
There does not appear to be a nice way to get a current users real name in ruby. The best …
read more"Ruby send message to stderr"
"Suppressing Warnings in Ruby Scripts"
Suppressing warnings is usually a bad idea but if you understand the risk and want to carry on regardless. When …
read more"Setting Ruby Defaults '||' vs 'fetch(){}'"
There is a very good presentation Confident Code by Avdi Grimm author of http://exceptionalruby.com/. Previously presented at Cascadia …
read more"Benchmarking Ruby, explicit vs implicit returns"
Back in 2009 barkingiguana wrote about how explicit returns
read more'return "String"'
was slower than an implicit return, ie just letting …"Tagging a git repo and pushing tag to github"
This assumes that
origin
is the label for github.
Tagging a github repo for my gem releases I do:read more$ git …
"Arrays 3, write idiomatic Ruby"
Previous posts arrays and arrays2
Based on a post by barkingiguana, some idiomatic ruby ways to handle arrays. Ruby tries …
read more"Ruby Search and Replace Script."
A small standalone script that search through a file doing text substitutions.
read more1 2 3 4 5 6 7 8 …
"warning: already initialized constant"
Do you some times see:
read moreFileUtils.rb:93: warning: already initialized constant OPT_TABLE FileUtils.rb:1176: warning: already initialized constant …
"Ruby Arrays Concatenation and Subtraction"
Building on my original Ruby Arrays article a few more things you can do with Ruby Arrays.
Concatenation
read morea = [1 …
"Ruby Blocks for better code reuse"
While working on some disk space / folder structure scripts I had several functions which hierarchically search the disk then performed …
read more"Get latest Ruby 1.9.2 build with RVM"
"Ruby Basic File Read and Write"
Read text file with one line:
Write text with one line :
Explanation and other ways
When reading a text file …
read more"Sinatra ActiveRecord DB config on Heroku"
To make an automatic ActiveRecord database connection using ENV['DATABASE_URL'] The following snippet can be used:
From ActiveRecord 3.2 …
read more"Ruby script connect to DB using database.yml"
To connect to a rails style DB config outside of the normal workflow, or using a database.yml in a …
read more"Setting up PostgreSQL on OS X"
An old guide is written on the Apple Developer Forum however if you are using Homebrew it is much simpler …
read more"Ruby Arrays, Part 1"
"Installing gist.vim"
This vim plugin will allow you to gist directly from vim, simple way is just :Gist to gist entire file …
read more"Obnoxious gem warnings"
recenlty after updating rubygems Istarted getting a lot of warning like this when running ruby or executable gems:
NOTE: Gem …
read more"Recent issue with building Gems"
When running gem build on a new library I have been working on I started getting the following error:
read more[ruby_svg_light …
"Behaviour and State"
Classes are a basic Object Orientated Structure which encapsulate state and behaviour. Some times you just require to capture state …
read more"Better Open Source Project Setup, with RVM & Bundler"
Based on 'Raise the bar, lower the pressure' given by Durran Jordan at ScotRubyConf 2011.
There has been some debate …
read more"Schwartzian Transform"
I recently heard about the Schwartzian transform, which is a sorting idiom from perl. It allows an array of objects …
read more"Ruby CLI user input using gets"
Using a while true loop with 'gets' and a case statement, can create a compact command line interface for ruby …
read more"ORM(Activerecord) or Ruby Sort"
Based on an old Article I wrote, investigating incase sensitive sorting performance.
I have an active record model call Tag …
read more"Activerecord Find All/Multiple"
Using Tags (An active record model) to find tags by the tag property:
read moreTag.find_by_tag("Ruby") Ruby Tag.find_by_tag(["Ruby …
"gem permissions on WebFaction"
After making a few updates to my site I decided to upgrade the version of sinatra I was using in …
read more"Sinatra regex routes"
The routes for my site have been growing since adding pagination (/articles/older/) and tag filtering. As well as the …
read more"Ruby Block Selection in Vim (Plugin)"
A new very cool plugin for Rubyists using Vim. RubyBlock TextObjects created by Drew Neil from Vimcasts.org. Once installed …
read more"Put methods not working with Classy Sinatra apps"
Since moving to Classy Sinatra applications I have not been able to get put and delete methods to work correctly …
read more"rake aborted! undefined method `info' for nil:NilClass"
I am currently switching between runing migrations locally on an sqlite3 database and postgres for production on Heroku.
When switching …
read more"Sinatra Heroku and config.ru"
Rack applications often require a config.ru for deployment. The standard config.ru for classic sinatra applications is well documented …
read more"Sinatra Session Extension"
I have just started to use a sinatra extensions called Sinatra Session. The write up on the main site is …
read more"Sinatra reload source file changes in development mode"
Sinatra Reloader is a sinatra extension which reloads source files while in development mode, this functionality was removed from base …
read more"Ruby each or delete_if"
In ruby some times you want to iterate over an array and remove items that meet certain conditions, if using …
read more"Storing secret keys in Ruby config files an approach"
I have for a while wondered about an ideal (good) approach to storing api keys in config files in ruby …
read more"Ruby Regular Expressions Lookahead / Lookbehind"
I recently discovered a feature of regular expressions called lookahead. This means for a match the lookahead must exist but …
read more"Ruby Time save and Restore (serialise)"
One method to save a time and restore it correctly:
read moredef get_time_run ## File Access based on ## http://rubylearning.com/satishtalim …
"Active Record create unique or return existing element"
When working with databases it is often a requirement to have unique elements (columns) which are not the primary key …
read more"Activerecord queries on table joins"
An example of joining tables through active record models. There is a good tutorial on the basics of Activerecord joins …
read more"Get client IP on Heroku"
I have been trying to use the GeoIP Rack App, by copying this gist in my Rack stack with a …
read more"Sinatra running on Heroku"
"Creating executable gems"
This is not necessarily the correct way of creating executable gems but a method which worked for me.
Assuming we …
read more"gem install memory_usage"
Just released my first gem 'memory_usage' Version 0.0.1.
$ gem install memory_usage
Assuming the gems folder has been set-up …
read more"Ruby runnable and includeable"
I might have just made up includable, but I like it.
Some times you have written a ruby script (using …
read more"GitHub command line tools with static paths"
I have written a few command line tools in ruby which I use to perform file system maintenance. Mainly sorting …
read more"Ruby parsing torrent files for meta info"
There currently does not appear to be any really good torrent file parsers available via the gems system.
rubytorrent seems …
read more"Super simple Ruby list directory contents"
"Installing Ruby Enterprise on Mac OS X"
Download ruby enterprise and follow instructions on page. The exact commands I used are:
read more$ cd ~/bin $ wget http://rubyforge.org …
"Ruby Memory Issue on Web Faction"
"Ruby, Ruby, Ruby, why are you so wierd at times?"
This feature of ruby keeps catching me out as the behaviour is quite unexpected (by me).
I can use a …
read more"Ruby incase sensitive sort"
Ruby has a .sort method which sorts basic objects. it is case sensitive though so Zebra is before apple. Using …
read more"Ruby and gemspec"
I have just forked and cloned a project on github and discovered *.gemspec files. They are a nice way of …
read more"Ruby .nil? tests fail ? you really want ||="
I recently discovered ||= in ruby. Its main use is for initialising a variable if it does not already exists, this …
read more"Installing the ruby gem twitter on webfaction"
[Update]
read more
As this is a long post I am putting this update at the top. If you just want to …"gem install with out the docs"
When I install gems on my server I do not get any of the documentation which is normally 3-5 times …
read more"Sinatra blog retrieving next and previous ids"
When displaying blog/articles it is often nice to have previous and next posts. Simply -1 +1 from the current …
read more"Sequel ORM Migrations"
"FourThirds Sinatra RESTful example"
"Ruby include (require) local files"
"Ruby Logger"
"Ruby Performance Measure"
"Sinatra 1.0 Released"
Sinatra 1.0 has been released!
When you install the new version the old one are still left behind. This …
read more"Sinatra and compass sending compressed cached CSS"
"Ruby Time Formats"
I have been playing around with getting my blog posts timestamped I found the Ruby Time Docs to be very …
read more