Browsing articles by " kyanachik"

Setting an Ubuntu 11.04 External Monitor as Primary

May 2, 2011   //   by kyanachik   //   Operating systems  //  View Comments

Ubuntu 11.04 is a great operating system, yet when I have my laptop connected to an external monitor the main bar (whatever it’s called) is still on my laptop screen and I would rather have it on my external monitor.  The following script places the bar on the external monitor by making it the primary display:

xrandr --output VGA1 --primary

Now running on Amazon EC2

Feb 18, 2011   //   by kyanachik   //   Website Development  //  View Comments

This weekend I migrated my blog (and hosting) from a shared host to my own instance on Amazon EC2.  I am pleased with the speed-boost that I’ve received and the total control of the server.

How to connect a Rails app running on Ubuntu Linux to Microsoft SQL Server

Dec 14, 2010   //   by kyanachik   //   Website Development  //  View Comments

Taken from

Install Unix ODBC

sudo apt-get install unixodbc-dev

Install Free TDS

sudo apt-get install freetds-dev tdsodbc

Install the Ruby ODBC Binding

wget http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9997.tar.gz

tar -zxvf ruby-odbc-0.9997.tar.gz

cd ruby-odbc-0.9997

ruby extconf.rb

make

sudo make install [yields:/usr/bin/install -c -m 0755 odbc.so /usr/local/lib/site_ruby/1.8/x86_64-linux]

Install the following gems

sudo gem install dbd-odbc

sudo gem install dbi

Install the Activerecord SQLServer Adapter

sudo gem install activerecord-sqlserver-adapter

Configure FreeTDS

sudo nano /etc/freetds/freetds.conf

[developer]

host = testserver.local.domain (i.e. Fully Qualified DNS)

port = 1433

tds version = 8.0

Test FreeTDS

sudo apt-get install sqsh

sqsh -S developer -U database_username -P database_password

Configure UnixODBC

sudo nano /etc/odbcinst.ini

[FreeTDS]

Description = TDS driver (Sybase/MS SQL)

Driver = /usr/lib/odbc/libtdsodbc.so

Setup = /usr/lib/odbc/libtdsS.so

CPTimeout =

CPReuse =

FileUsage = 1

Create ODBC Entries for your database

sudo nano /etc/odbc.ini

[development]

Driver = FreeTDS

Description = ODBC connection via FreeTDS

Trace = No

Server = 192.168.1.2 (IP Address of SQL Server)

Database = production

Test UnixODBC

isql -v development database_username password

SQL> select count(*) from people;

Install ruby-odbc

You have to download and compile the source yourself to set a specific flag

wget http://www.ch-werner.de/rubyodbc/ruby-odbc-0.99992.tar.gz

tar -zxvf ruby-odbc-0.99992.tar.gz

cd ruby-odbc-0.99992

ruby -Cext extconf.rb --disable-dlopen

make -C ext

sudo make -C ext install

Test ruby-odbc

irb

require 'odbc'

ODBC.connect("development", "username", "password")

ActiveRecord SQL Server Adapter

Install the activerecord-sqlserver-adapter version 2.3.5  (I believe there are problems with other versions)

sudo gem install activerecord-sqlserver-adapter -v=2.3.5

Rails 3.0 unobtrusive Ajax in Rails 2.3.x (with jQuery) – Andrew Cox

Dec 3, 2010   //   by kyanachik   //   Website Development  //  View Comments

The following instructions will get unobtrusive ajax working with jQuery in rails 2.3.x just like it is done in rails 3.x.

Rails 3.0 unobtrusive Ajax in Rails 2.3.x – Andrew Cox.

I can’t wait to implement Search, Sort, Paginate with AJAX in a rails 2.3.8 application.

The creators of no-longer-with-us products explain what went wrong

Dec 3, 2010   //   by kyanachik   //   Website Development  //  View Comments

From Signal vs. Noise
http://37signals.com/svn/posts/2682-the-creators-of-no-longer-with-us-products-explain-what-went-wrong

Wesabe launched as a site to help people manage their personal finances. While competitor Mint was acquired by Intuit, Wesabe eventually shut down. In “Why Wesabe Lost to Mint,” Marc Hedlund dissects what happened.

Mint focused on making the user do almost no work at all, by automatically editing and categorizing their data, reducing the number of fields in their signup form, and giving them immediate gratification as soon as they possibly could; we completely sucked at all of that…I was focused on trying to make the usability of editing data as easy and functional as it could be; Mint was focused on making it so you never had to do that at all. Their approach completely kicked our approach’s ass.

Rails Development Environment on Windows

Nov 23, 2010   //   by kyanachik   //   Website Development  //  View Comments

Here’s my setup for developing Rails applications on Windows:

Ruby
Ruby 1.8.7

Rails
Rails 2.3.8

Gem Files
activerecord-sqlserver-adapter (See my previous post on working with SQL Server)
ruby-odbc
composite_primary_keys
win32console

Source Control
Git: http://git-scm.com/

IDE/Editor
Vim: http://www.vim.org

Plugins
Download this zip file and extract the contents to c:\users\USERNAME\vimfiles
vimfiles.zip

_gvimrc
Download this zip file and extract to c:\users\USERNAME\_gvimrc
_gvimrc.zip

Composite Primary Keys in Ruby on Rails

Oct 1, 2010   //   by kyanachik   //   Website Development  //  View Comments

If you’re using Microsoft SQL Server as the database server for your rails app it’s probably because you’re writing a web app for an existing database. It’s also likely that the database structure does not follow the rails default (ids for primary keys) and you probably have some tables with composite primary keys.

Install

Rails by default cannot handle composite primary keys. Luckily there’s a gem for that! Install the “Composite Primary Keys” gem from the Command Prompt with Ruby:
gem install composite_primary_keys

Configure Rails App

To use the Composite Primary Keys gem in your rails app add the following to the bottom of your environment.rb file (outside of the end tag that’s there for the Rails::Initializer.run do |config|) located in the config directory of your rails app:
require 'composite_primary_keys'

Note: If your server is running when you make the change to the envorinment.rb file you will receive an error such as “undefined method `set_primary_keys’ for #” when viewing a page on your site using the model. Restart your server so it re-loads the environment.rb file.

Define the Composite Key in the model

To define the composite key for your model use the set_primary_keys call:

class Mymodel < ActiveRecord::Base

set_primary_keys :key1, :key2

end

How to find a record with composite primary keys

Instead of passing in a single id in the find method for your model: find(1), pass an array of the ids matching the order that they were defined in your class: find([1, 1]).
mymodel = Mymodel.find([1, 1])

Getting Rails to talk to MS SQL Server from a 64-bit Windows 7 computer

Oct 1, 2010   //   by kyanachik   //   Website Development  //  View Comments

The only way I’ve been able to get a Rails application to communicate with Microsoft SQL Server is through a User DSN ODBC connection. Rails cannot connect to a System DSN using 64-bit Windows when in a development environment.

Here’s how to install the gems necessary to do this, how to setup your ODBC connection, and how to setup the database.yml file in your rails project.

ActiveRecord SQL Server Adapter

Install the activerecord-sqlserver-adapter version 2.3.5  (I believe there are problems with other versions)
gem install activerecord-sqlserver-adapter -v=2.3.5

Development Kit

Download and Extract

The ruby-odbc gem will not install without first installing the DevKit add-on from RubyInstaller.org I downloaded DevKit-4.5.0-20100819-1536-sfx.exe from http://rubyinstaller.org/downloads/ under the

Development Kit

heading.
After downloading the file run it and let it self-extract to a folder of your choice. (Warning, the self-extractor will not create a sub-folder in the location that you choose, so you might want to create your own subfolder first and then extract there)
Install

  1. Start a new Command Prompt with Ruby (Start – All Programs – Ruby187 – Start Command Prompt with Ruby) and change into the extracted DevKit directory.
  2. Run:  ruby dk.rb init
  3. Run:  ruby dk.rb install

Ruby ODBC

The ruby-odbc gem must be installed for the SQL Server adapter to connect through ODBC. From your Command Prompt with Ruby run: gem install ruby-odbc.

Connect a Rails app to SQL Server

Create the ODBC Connection

  1. Open up the ODBC Data Source Administrator (Start – Control Panel – Administrative Tools – Data Sources (ODBC)
  2. Select the User DSN tab
  3. Click on the Add Button
  4. Select SQL Server and click Finish
  5. Give the data source a name that you will refer to in your rails database configuration file (DSN_NAME)
  6. Select the server to connect to
  7. Click Next
  8. I’ve been having luck using SQL Server authentication and not Windows NT authentication (Integrated Security) so I’m selecting “With SQL Server authentication…” radio button and filling in a SQl Server username and password.
  9. Click Next
  10. Check the “Change the default database to:” checkbox and select the database that you want to work with.
  11. Click Next
  12. Click Finish

Create your Rails Application

From your Command Prompt with Ruby run: rails sqlservertest.

Configure the Database Connection

Edit the database.yml file in the config folder for the rails app.
development:
   adapter: sqlserver
   mode: odbc
   dsn: DSN_NAME
   username: USERNAME
   password: PASSWORD
   host: SERVERNAME

Generate a scaffold to test your database connectivity

In Rails a scaffold is a powerful technique for doing alot of coding for you by generating controllers, views, models, tests, etc. Using Rails’ generator create a scaffold for a Customers table with the following command from the Command Prompt with Ruby inside the sqlservertest folder (replace your field names as necessary being careful as Rails is case-sensitive with field names in the database):
ruby script/generate scaffold customer Name:string Address:string City:string State:string Zipcode:string
You should now have a customers controller in your app’s controllers folder, a customers model in your app’s models folder, a customer’s folder with edit, index, new, and show views in your app’s views folder.

Override Rail’s default convention for table name and primary key

If you’re using SQL Server you probably already have legacy tables that are setup in a manner that Rails’ convention does not work well with. To fix that we’re going to tell Rails the table name and primary key for our table. (Note: We’re doing this because Rails expects your primary key to be an identity field named id). In your customer model place set the table_name and primary_key properties. The customer.rb file in your models folder should look like the following:
class Customer < ActiveRecord::Base
  self.table_name = "Customers"
  self.primary_key = "CustomerNum"
end

Run the local development server to verify your configuration

Inside the sqlservertest folder run the following command in the Command Prompt with Ruby:
ruby script/server
Wait a few minutes for the server to start up, then open up a web browser and navigate to http://localhost:3000/customers which will then list all of the customers in your database. You can click on all of the links available because the scaffolding has generated a working app to create, list, show, edit and delete (aka CRUD) customers for you.

Developing with Ruby on Rails on Windows 7

Sep 30, 2010   //   by kyanachik   //   Website Development  //  View Comments

My development and production environment is Windows using Microsoft SQL Server, and at this point I have no choice but to continue developing on Windows using Microsoft SQL Server.  My production Rails server can be Linux, but it has to talk to Microsoft SQL Server running on a Windows server.  Here’s how I setup the development environment on my 64-bit Windows 7 box.

For those not aware, Ruby on Rails is actually a misnomer. It should be Rails on Ruby, because ruby is a programming language such as C++ and rails is simply a gem (plugin, library, extension) that extends Ruby. To get started you must install Ruby.

Ruby

I installed ruby 1.8.7 locally using Ruby Installer for Windows using all of the defaults except I checked “Add Ruby executables to your PATH”.

A good portion of the remaining installation is done in a command prompt and the best way to make sure Ruby is interpreted correctly is to run a Command Prompt with Ruby. This is done from the Start Menu – All Programs – Ruby 1.8.7 p302 (or whatever version you installed) – Start Command Prompt with Ruby.

From the command prompt with ruby run the following command to update your system:
gem update --system

Install Rails 2

As of this writing Rails 3 has recently been deployed. Most of the documentation I’m finding on the web as well as the book I own are all geared towards Rails 2, therefore I want to install Rails 2, not Rails 3. From the command prompt with ruby rin the following command to install rails:
gem install rails -v=2.3.8

After waiting for a while as if nothing was happening a series of successful install messages appeared and a final message of 8 gems installed. Next the ri and RDoc documentation for the installed gems was installed.

To view the list of installed Gems use the following command:
gem list --local

I now have the following gems installed:
actionmailer (2.3.8)
actionpack (2.3.8)
activerecord (2.3.8)
activeresource (2.3.8)
activesupport (2.3.8)
rack (1.1.0)
rails (2.3.8)
rake (0.8.7)

Non-Microsoft Databases

You might as well install the gems for Rails to talk with the two default databases MySQL and SQLite.

MySQL

gem install mysql (I received a series of “No definition for …” errors when the documentation was installed)

SQLite

gem install sqlite3-ruby

This only installs the ruby gem to talk with SQLite, it does not install SQLite on your system.  to install SQLite go to the SQLite download page http://www.sqlite.org/download.html and download the file sqlitedll-X.X.X.zip under the heading Precompiled Binaries for Windows.  Extract the sqlite3.dll file contained in the downloaded zip to your ruby’s bin folder.  Mine was located at c:\Ruby187\bin.

A Microsoft Developer migrating to Ruby on Rails

Sep 30, 2010   //   by kyanachik   //   Website Development  //  View Comments

I’ve been a Microsoft developer for my entire career starting with Microsoft Access and Visual Basic through today working on ASP.Net MVC web applications running on .Net 4 using NHibernate and Microsoft Test. The jump from ASP.Net Webforms to ASP.Net MVC was monumental and delayed my leap to Ruby on Rails until now.

Lately it feels as if I’m fighting with too many configuration, compiler, things I don’t want to worry about, problems in .Net.  The last few .Net projects that I worked on with a team always seemed to be some odd fight with some piece of code that is not crucial to the success of the project, but is making the entire project fail.  I’ve been testing out Rails to see if these issues I run into are common across the board, or .Net specific.  They are .Net specific.

All programming systems seem wonderful when looked at from a high-level, it’s not until you really get into the details when you find out the problems.  And I’m sure there will be problems.  I just don’t want to have to deal with repeating problems like I am with .Net.

I like NHibernate and feel as if it’s the best ORM in the .Net world.  Yet, it’s lacking features due to design the theoretical decisions (i.e. POCO) that required me to write functionality that I didn’t want to have to write.  I don’t want to have to write code to audit/validate my business objects before they go to the database, I want hooks.

Anyways, I will be attempting to migrate my working environment from .Net to Ruby on Rails.  This blog will be my documentation and diary.  Here we go!

Pages:123456»