Tech Tidbits - Ruby, Ruby On Rails, Merb, .Net, Javascript, jQuery, Ajax, CSS...and other random bits and pieces.

Thursday, May 21, 2009

New Blogs -, Learning Erlang

I'll be posting all Ruby, Rails, and related topics at my new blog, (and I'll probably move over my old posts as well)

I'm also getting ready to start another new blog, "Learning Erlang," currently located at which I may move it to its own domain once I get started.

Friday, February 6, 2009

Rails & Testing - Resources

This is an in-progress set of testing resources aimed at the Ruby/Rails developer...

Rails Guides

Behavior Driven Development (BDD)





Tools (BDD & Cucumber)

Tuesday, November 18, 2008

Nginx, Mongrel, Merb

Quick notes on installing and configuring nginx and running with existing mongrel and Merb app on my MacBookPro.

1) Download and install PCRE (if needed)

$ ./configure
$ ./make
$ ./make install

2) Download and install nginx:
The latest stable version is nginx-0.6.32, the change log.

$ ./configure
$ ./make
$ ./make install

# Edit nginx.conf file (/usr/local/nginx/conf/nginx.conf)
# Note - based on Ezra's blog post (see notes below)

user nobody;
worker_processes 2;

error_log logs/error.log notice;
pid logs/;

events {
worker_connections 1024;

http {
include mime.types;
#include conf/mime.types;
default_type application/octet-stream;

# no sendfile on OSX uncomment
#this if your on linux or bsd
#sendfile on;
tcp_nopush on;

keepalive_timeout 65;
tcp_nodelay on;

upstream mongrel {

gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;

server {
listen 80;
#server_name localhost;
root /Users/dsparlingimbp/git/dougsparlingdotcom/public;

access_log off;
rewrite_log on;

location ~ ^/$ {
if (-f /index.html){
rewrite (.*) /index.html last;
proxy_pass http://mongrel;

location / {
if (!-f $request_filename.html) {
proxy_pass http://mongrel;
rewrite (.*) $1.html last;

location ~ .html {
root /Users/dsparlingimbp/git/dougsparlingdotcom/public;

location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ {
root /Users/dsparlingimbp/git/dougsparlingdotcom/public;

location / {
proxy_pass http://mongrel;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


4) Commands for starting and stopping nginx
start: sudo /usr/local/nginx/sbin/nginx
stop: sudo kill `cat /usr/local/nginx/logs/`

5) Start Mongrel cluster (I'm using 3 Mongrels):
$ merb -c 3
$ merb -p 4000 -c 3

6) Resources

Sunday, November 9, 2008

Ruby - Randomize arrays and strings

Randomize the elements of an array:

random_array = my_array.sort_by{rand}

Randomize a string (jumble a given word):

jumbled_word = word.split("").sort_by{rand}.join

Saturday, November 8, 2008

Updating to RubyGems 1.3.0 on Mac OS X Leopard 10.5.4

When attempting to stall final release of Merb 1.0, I got an error message that I needed RubyGems version >=1.3.0:

ERROR: Error installing merb:
merb-core requires RubyGems version >= 1.3.

So I did the usual "gem update --system" but got an error:

$ sudo gem update --system
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.3.0
ERROR: While executing gem ... (NameError)
undefined local variable or method `remote_gemspecs' for #
$ gem --version

I found that you have to run a second set of instructions:

$ sudo gem install rubygems-update
Successfully installed rubygems-update-1.3.0
1 gem installed
$ sudo update_rubygems
Installing RubyGems 1.3.0

More info here:

Wednesday, August 27, 2008

Dynamic Details Row in GridView

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Configuration" %>

<script runat="server">

void GridView1_PreRender(object sender, EventArgs e)
if (GridView1.SelectedRow != null)
Table table = GridView1.SelectedRow.Parent as Table;

if (table != null)
CreateRow(table, GridView1.SelectedIndex);

void CreateRow(Table table, int index)
GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
table.Rows.AddAt(index + 2, row);

private TableCell CreateColumn()
TableCell cell = new TableCell();
cell.ColumnSpan = GridView1.Columns.Count;
cell.Width = Unit.Percentage(100);

DataSourceControl ds = CreateDataSourceControl();

return cell;

private static DetailsView CreateDetailsView(DataSourceControl ds)
DetailsView dv = new DetailsView();
dv.AutoGenerateRows = true;
dv.DataSourceID = ds.ID;
return dv;

private DataSourceControl CreateDataSourceControl()

SqlDataSource ds = new SqlDataSource();
ds.ConnectionString = WebConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
ds.SelectCommand = "SELECT * FROM [Users] WHERE [UserID] = @UserID";
ds.ID = "SqlDataSource2";

Parameter cp = new Parameter("UserID", TypeCode.String, GridView1.SelectedValue.ToString());
return ds;


<html xmlns="" >

<head id="Head1" runat="server">
<title>Untitled Page</title>

<form id="form1" runat="server">

 <asp:GridView ID="GridView1" Runat="server" DataSourceID="SqlDataSource1" DataKeyNames="UserID"
AutoGenerateColumns="False" OnPreRender="GridView1_PreRender" EnableViewState="False">
<asp:CommandField ShowSelectButton="True">
<asp:BoundField ReadOnly="True" HeaderText="UserID" DataField="UserID" SortExpression="UserID">
<asp:BoundField HeaderText="UserName" DataField="UserName" SortExpression="UserName"></asp:BoundField>

<asp:SqlDataSource ID="SqlDataSource1" Runat="server" SelectCommand="SELECT [UserID], [UserName] FROM [Users]"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>">



About Me

My photo
Developer (Ruby on Rails, iOS), musician/composer, Buddhist, HSP, Vegan, Aspie.