rake db:seed | Don’t know how to build task error

So I ran into a little issue today, I wasn’t able to get my rake db:seed task to work. This is the error I was getting;

rake db:seed  don't know how to build task

The solution?

Update rails to 2.3.5

How?

gem update rails

Ordinal Number in Reporting Services

Recently I had a client request for reporting services dates to use ordinal numbers, that being, “1st instead of 1, 2nd instead of 2″ etc. To my surprise, this isn’t a standard datetime format in reporting services!

So I set out to create my own ordinal function based on a C# version I found on the Internet.

To use the below function in your report;

1) Open up your report in Reporting Services
2) Make sure you’re in the Design section and click the “Report” menu option (up the top), then “Report Properties”
3) Select “Code”
4) Copy and Paste the function below into the “Custom Code” box.

Public Function FormatOrdinal(ByVal day As Integer) as String

    ' Starts a select case based on the odd/even of num
    Select Case (day Mod 100)
        ' If the nymber is 11,12 or 13 .. we want to add a "th" NOT a "st", "nd" or "rd"
        Case 11
        Case 12
        Case 13
            Return day.ToString() + "th"
    End Select

    ' Start a new select case for the rest of the numbers
    Select Case day Mod 10
        Case 1
            ' The number is either 1 or 21 .. add a "st"
            Return day.ToString() + "st"
        Case 2
            ' The number is either a 2 or 22 .. add a "nd"
            Return day.ToString() + "nd"
        Case 3
            ' The number is either a 3 or 33 .. add a "rd"
            Return day.ToString() + "rd"
        Case Else
             ' Otherwise for everything else add a "Th"
            Return day.ToString() + "th"
    End Select
End Function

I was then able to use the function in an expression.

I wanted to format “01/01/2010″ as “1st January 2010″. My expression was;

=Code.FormatOrdinal(Day(Fields!LETTERDATE.value)) & " " & MonthName(Month(Fields!LETTERDATE.value), False) & " " & Year(Fields!LETTERDATE.value)

Will_paginate with multiple models

If you need to implement paging in your Ruby on Rails application, a quick and easy way is to use the fantastic “Will_Paginate” plugin (available here).

However I came across a need to paginate multiple models on the same page, for example; a list of users and a list of groups.

Luckily Google came to the rescue with this article, which demonstrates the use of the :page option, allowing you to specify the page against a model object.

Check out the code below (courtesay of candidcode.com)

Controller

@users = User.paginate(:page => params[:user_page], :per_page => 10)
@administrators = Administrator.paginate(:page => params[:administrator_page], :per_page => 10)

View

<%= will_paginate @users, :param_name => 'user_page' %>
<%= will_paginate @administrators, :param_name => 'administrator_page' %>

How to import your Bookmarks to Safari

So you’ve made the switch to the Safari web browser; congrats! But what about your bookmarks? If you have a rather large list of bookmarked websites then you’ll need to import them!

The following method demonstrates how to export your bookmarks from Firefox and import them using Safari.

Step 1: Export bookmarks from Firefox

The first step requires you to export your bookmarks from Firefox. Fortunately this is fairly simple process. Simply select the Bookmarks menu item, then select “Organize Bookmarks”.

Next select the “Import and Backup” dropdown and select “Export HTML”.
When prompted, save this file to your hard drive (desktop is fine for now).

That’s it! You’ve successfully exported your bookmarks from Firefox to a standard .html file.

Step 2: Import your bookmarks into Safari

Next we need to import this file back into Safari. Now for me, the primary menu toolbar wasn’t enabled and I don’t believe it’s enabled by default. If you can’t see menu bar with “File”, “Edit”, “View” etc, then you’ll need to enable this menu bar. You can do this by selecting the cog menu icon on the right of the browser, and selecting “Show Menu Bar”.

Once you’ve got the menu bar activated, simply select “File” then “Import Bookmarks” and browse to your desktop where you saved the Firefox bookmark export!

That’s it! You’ve successfully imported your bookmarks from Firefox. You can now drop and drag your bookmarks to your preference!

I dragged my most used bookmarks to the “Bookmark Bar” in Safari which allows me to quickly access the bookmarks I used most.

Capistrano issues – no such file or directory

So I was playing around with my new Slicehost the other day and following their guides to automate a Ruby on Rails deployment process using capistrano.

For those that don’t know, capistrano comes as a ruby gem which allows you to completely automate tasks. In my case, I wanted to remotely tell my Ruby on Rails application to retrieve the latest version of the application from github (remote repository) and then restart my Rails app.

The documentation tells me that a simply “cap deploy” from the root of my rails folder should execute my capistrano script. However for hours upon hours I was banging my head against a wall.

Here’s the error I was receiving;

C:\Web\xxxxx.com> cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git@github.com:xxxx/xxxx.git master"
*** [deploy:update_code] rolling back
* executing "rm -rf /home/xxxx/public_html/releases/20100222103818; true"
servers: ["173.203.207.104"]
[173.203.207.104] executing command
command finished
C:/Apps/Ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.16/lib/capistrano/recipes/deploy.rb:98:in ``': No such file or direct
ory - git ls-remote git@github.com:xxxx/xxxx.git master (Errno::ENOENT)

The solution

Ok so I’m not really going to call this a solution because I don’t know why this works (and maybe one of you can assist me in this) but running the command “cap deploy” under a MINGW32 command shell instead of the usual Windows command prompt seemed to work just fine.

(I just MINGW32 as a shell to run all my GIT repository commands)

If you don’t use Git on windows or you don’t have MINGW32 installed, I suggest you have a look at this Git on Windows page.

Remove Buzz From Your Inbox

So my gmail turned into Google Buzz this morning .. Google’s instant method for launching into the social media space. The first thing that annoyed me was .. why are buzz updates appearing in my Gmail Inbox?

My GMAIL inbox is for EMAIL – not social media status updates ..

It’s a bit of a hack to get rid of them but here goes;

1) Up the top click the “Create a filter” link (next to the search box)

2) Where it says “has the words” .. type in “label:buzz” (without the quotes of course)

3) Click “Next Step” (Ignore the warning that pops up ..)

3) Then tick the box which says “Skip the Inbox (Archive it)”

4) Then click “Create Filter”

Done! Now all buzz notifications will NOT be displayed in your GMAIL inbox. Want to turn off Buzz completely? Luckily is a piece of pie. Scroll to the bottom of Gmail and click the “turn off buzz” link. BOOM; buzz is gone and your Inbox is safe.

Error 0X80040201 while sending email

I recently had issues with an outlook error “0X80040201″ and for the life of me I couldn’t fix it.

However after much distress I was able to uncover what the problem was. I recently went from an Exchange 2007 environment to a IMAP environment and hence some of my contacts were corrupted. If I tried to send an email to anyone from my old exchange contact list – the email would fail; hence the error 0X80040201.

Simply creating new contacts in Outlook for the people I wanted to send emails too, fixed this issue!

How to fetch Last Record in Subsonic

Is it just me or is Subsonic the topic of discussion right now? :D
I had a need to retrieve the last ID that had been generated in a table; that being, the last “auto increment” ID of a table.

The following example worked a charm using Subsonic and activerecord.

var fetch_ref_id = contract.All().OrderByDescending(c => c.id).Take(1).ToList();
if (iRef_new_id != null)
{
     iRef_new_id = fetch_ref_id[0].id;
}

As you can see, it creates a new list (noted by the ToList()) by connecting to the table “category”, it then selects all results (All()) and then orders the list by Descending and finally, the take(1) simply takes the top record.

I then whack the result (if you have a column called id) into a integer.

Subsonic ordering – OrderByDescending

So the subsonic documentation sucks. If you’re new to activerecord, linq and subsonic in general; you’ll find it fairly hard to construct basic queries. However once you’ve got it under control, it’s a piece of cake.

To sort your table using activerecord, use the following examples;

To sort ascending by a column called name

var categories = category.All().OrderBy(c => c.name);

To sort descendingby a column called name

var categories = category.All().OrderByDescending(c => c.name);

You can then just bind to your gridview/dropdown list or whatever you like.

            if (categories != null)
            {
                drp.DataSource = categories ;
                drp.DataBind();
            }

How to Reset your MediaWiki Admin Password

So for some strange reason, it just took me a good 20minutes to find an article on Google to tell me how to reset the Mediawiki admin password (because yes .. I forgot it). Some articles mentioned using phpMyAdmin to edit the users table directly, however the password is stored in a TinyBLOB format – so I had no clue.

Luckily I finally found a way to reset the Admin password!

You’ll need shell/SSH access for this procedure to work.

1) Login to your media wiki installation
2) Then type the following;

cd maintenance
php changePassword.php --user=Admin --password=tada321$

This will change the “Admin” user’s password to “tada321$” ! I then highly suggest you login to MediaWiki and change the password to something more secure/familiar :D

3 of the Best CSS Tutorials

So I used to be one of those old “tables are still cool for layouts” kinda guys and proceeded to use tables for just about anything web related that I touched. But there came a moment where I decided .. you know what, everyone else is raving on about this CSS layout business, so I set out to see what could be done. Now I came across quite a few tutorials on Google; and I wanted to outline the best ones that I came across!

1) Creating a CSS layout from scratch
This is pretty much my favourite CSS tutorial .. which pretty much takes the scenario of cutting and slicing a web design into an actual functional website using CSS.

2) CSS Template Layout
This tutorial goes into a bit of detail and lacks images along the way (to break up the text), however everything just made sense whilst reading this tutorial.

3) CSS Tutorial: Layout a page using CSS
A little more detailed than the others, this tutorial aims to keep it simple; but yet goes into detail about each element and tag reference. The thing to remember, is that learning CSS is like learning to ride a bike – once you know it, it’ll stick – trust me.

SubSonic 3.0 ActiveRecord Tutorial

I wanted to demonstrate the complete and utter power of SubSonic Activerecord’s toolset. Pretty much, its an easy to use querying engine which automatically creates objects that you can use within your ASP.NET project. You can use LINQ querying if you like, or you can use the SubSonic preferred way as demonstrated below;

Want to bind a gridview?

var categories = category.All();
gvList.DataSource = categories;
gvList.DataBind();

Boom. Done.

<pre lang="csharp" line="1">
int iLineID = 1;
category delCat = category.SingleOrDefault(x => x.id == iLineID);
delCat.Delete();

Too easy right?

What about adding a new record?

category newCat = new category();
newCat.name = "Dummy category name";
newCat.Add();

How easy is that? Go grab SubSonic now!

« Previous Entries Next Entries »