Archive for the ‘Uncategorized’ category

Cake is Unable to Connect to Database on Snow Leopard – MySQL

September 6th, 2010

Playing around with CakePHP today.  Ran into a problem where I know – absolutely – that my database.php was correct in Cake.  However, I kept getting this error:

Cake is NOT able to connect to the database.

Keep in mind, I’m using the Apache out of the box with Snow Leopard.

The fix was easy, but man, what a pain!

So I’m writing this to help anyone else that finds this problem…

1. Goto /private/etc/php.ini  (use TextWrangler or vi)
2. Search for ‘mysql.default_socket’ – should be under the [MySQL] section.  For me it was line 1227
3. Modify to look like the following:

;mysql.default_socket = /var/mysql/mysql.sock         <== this is what it was
mysql.default_socket = /private/tmp/mysql.sock
Save it – and restart Apache.
Good luck!

ASP.NET MVC with jTemplates – Part I

May 20th, 2010

One of my goals in web development is to continue to look to use json to transmit data vs. using partial views.  Obviously by transmitting json data, the payload is going to be much more efficient.

I’m going to break this out into two parts :

Part I is going to cover the basics to using jTemplate with jQuery within an asp.net mvc environment.

Part II is going to take this concept and apply it to a nice looking jQuery plugin ‘grid control’ called  DataTables

Let’s look at what the final result will be:

image

Let’s address the server side pieces first:

I’m going to create a new Model class ‘Person’:

public class Person
    {
        public string ID { get; set; }
        public string FirstName { get; set; }
        public string Email { get; set; }
    }

Using the default asp.net mvc created project type, I’ll just a hook into the the Home controller to display the table in the index page.  To do this, I’ll need to add another action with some sample data that will be called from the page via ajax:

 

 [HttpPost]
 public JsonResult GetData()
 {
      IList<Person> people = new List<Person>
        {
          new Person {ID = "1", FirstName = "Anne", Email = "anne@domain.com"},
          new Person {ID = "2", FirstName = "Amelie", Email = "amelie@domain.com"},
          new Person {ID = "3", FirstName = "Polly", Email = "polly@domain.com"},
          new Person {ID = "4", FirstName = "Alice", Email = "alice@domain.com"},
          new Person {ID = "5", FirstName = "Martha", Email = "martha@domain.com"}
        };
      return Json(people);
}

The ‘return Json(people)’ will return the list in json format – which you can see in the above Firebug screenshot ‘response’. 

So that is basically it for the server side.

The first step in the views is to add the references to the javascript files.  Since I’m using the site.master I’ll add it there, so that it’s available to other views as well:

image 

(For production, you will want to use the compressed/min files instead)

I also add a new ContentPlaceHolder in the head of the site.master:

<asp:ContentPlaceHolder ID="HeadContent" runat="server" />

This way on the views, I can put any scripts in the head tags as well.

In the Index.aspx page we can finish this functionality:

1. add the scripts to the head of the view:

<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
        $.ajax({
                type:"POST",
                url: "<%= Url.Action("GetData") %>",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data){
                    $("#jTemplateDemo").setTemplate($("#templateHolder").html());
                    $("#jTemplateDemo").processTemplate(data);
                }
            });
        });
    </script>
</asp:Content>

To review this (we could use a $.getJSON as well) – on the page ready function I’m going to make an ajax call back to the ‘GetData’ action.  This is defined in the ‘url:’ parameter.

In this case there are no parameters being passed so the data is left blank (this is best practice to include “{}” when blank).  It is possible to use a REST url as well with parameters.

We define out contentType (using $.getJSON) would do this automatically.

Lastly, we provide an ‘onSuccess’ function – the ‘data’ will contain the returning Json from our action call.  The next two calls use the jTemplate API to merge the Json data to the templated html, as shown below.

2. add the template to the view:

<script type="text/html" id="templateHolder">
    <table border="1">
    <tr>
        <th>
            First Name
        </th>
        <th>
            Email
        </th>
    </tr>
    {#foreach $T as record}
        <tr>
            <td>
                {$T.record.FirstName}
            </td>
            <td>
                {$T.record.Email}
            </td>
        </tr>
    {#/for}
</table>
</script>

<div id="jTemplateDemo">
</div>

 

One thing to keep in mind is to put this html in the script tag.  Alternatively you could load this template from another file as well.

With this approach we have created a very lightweight approach to passing data from the server to the client – the binding to the template occurs on the client.  If we used partial views, the binding process would occur on the server and transmit the payload with the html, increasing it’s size.  The lightweight json approach is critical especially in our ajax calls

Next post we’ll take this table and convert it into a ‘DataTable’.

I have included this code for your review – download here

WebHost4Life

May 7th, 2010

I’m a truly dedicated WebHost4Life fan.  Been using them for something like 8 years now ? They were always responsive to any request, and they even allowed me to make some exceptions (I had a program I needed to be able to run on the server).

The control panel, although not the prettiest thing, got the job done.

Let me step back one moment and say they were advertising and telling me about how they were upgrading their system and all the improvements and ease of use and performance it would bring. I was looking forward to it.  It was delayed I noticed when I’d come to the site, but it would say they are ‘testing everything’.  That made me feel better about it all as well.

Well… I felt that way until 3 weeks ago. 3 weeks ago, without warning they flipped the switch.

Day 1: the forum I used for my community (MYSQL) was practically unusable.  Extremely slow. So badly I couldn’t even post to the community that there was a problem.  I entered a ticket, it took escalating the ticket 3 times.  5 days later it was working.  It’s still much slower than before.  5 days.

When I would chat or get a ticket I started noticing a trend… every single correspondance was ‘I’m sorry for the inconvenience this has caused you…’.  Like it was the scripted response to everything.

But ok, that was fine until I went to my .net main site that uses MSSQL. Hmmm, I track and store data and noticed the last data entry was a month ago.  One month behind.  All the data for the last month was gone.  What???  Another ticket.  Another 5 days. I never got a response.  They literally never answered.  They had no backup to offer me.  Data was gone, forever.

The best answer I got was ‘I’m sorry for the inconvenience this has caused you’.

But wait, it gets better. Remember how they were so good to work with on running my program I need ?  Despite everything I said, they flat out refused ‘it’s against our policy’.  I’m like ‘I’ve been running this safely for 8 years ???’.  Didn’t matter.  I asked to talk to manager.  They said ‘ok’. Ticket sat in the queue for 3 more days.

Three days later, I responded, asking what the status is.  Same response – ‘it’s against our policy’ – it wasn’t from a manager either.

Let’s talk about the control panel.. it’s pretty.  Pretty slow.  Pretty useless.  I need to backup my database (since they can’t migrate it properly), but the tool throws some .net exception on the webpage.  Customer support said ‘try Firefox’. Same error.

This is twice in 3 weeks I had to open a ticket for a buggy control panel that throws exceptions.

Lastly, I have a requirement to upload files.  So I have to set permissions.  They said ‘add a new user’.  I said ‘no this is the internet user’ .  The old ‘ugly’ control panel handled all this fine and perfectly.  The new tool… timed out.  The final ticket response was ‘use your FTP program to change permissions’.

I should add, I have lost 80% of my community. They were all very disapointed to find out the data was gone.  The forum they meet and talk and plan events was unusable.  The program I run can’t be run so the events can’t run.  I have to re-code the app now (it was given to me, no source code).

I’m writing this because as a consumer, I really feel I’ve been thrown and tossed around by a company that doesn’t respect a loyal customer.  Who must be too big now to value guys like me.  Back ‘in the day’ I suspect they worked well with me because they were a good company.  Something has changed.

I highly suggest – don’t use Webhost4life.  You will regret it.

So, needless to say, I’m looking for a new host.  One of the things I liked about Webhost4life was that I could run my mysql blog and forum as well as my .net site.  It ‘was’ easy to manage.  Secondly they don’t charge for bandwith usage.  I don’t use too much, but I had confort knowing the bill would always be the same amount.

Quite disapointing to me in a time where companies are susposedly struggling with the economy. I would think a shift would occur where they valued their customers.  Instead, I’m just another ‘policy’ to them that pays a year in advance…

Powered by Qumana

ASP.NET MVC and Rails

April 28th, 2010

Not big post here, just a chance to recommend reading this blog post:

http://anders.janmyr.com/2010/04/aspnet-mvc-vs-rails3.html

I think he does a great job comparing the two in a positive way.

Windows 7 Series

April 20th, 2010

I listened to a good podcast today of Petzold discussing Silverlight for the upcoming Windows phone.

I must say, after listening to him talk I had some encouragement for the phone and the dev environment.

I do think it was a fantastic decision to take the route of managed code with SL as the option.

I can see great opportunities for companies to build phone enabled apps for their internal as well as outward facing clients.

I do think the market is saturated with iPhone, blackberry, android, etc phones – and I’m (sight unseen here) hoping that it does better than the Zune has.

With the latest iPhone announcements that are blocking devs from using anything outside of objective-c, c++, and c I was a bit discouraged (I want to see Monotouch succeed)

IPodding

April 9th, 2010

So this is my first iPod touch enabled blog post.

Figured Id try out the app. So bear with me while I experiment. :)

Blogging Break

January 23rd, 2010

Anybody that actually pays attention to this blog, will realize I haven’t posted in awhile.  Basically I’m taking a break for a bit.  I’m extremely busy, starting a new project, maintaining an existing few as well.

I’ve been using Patterns and practices WSSF and really enjoying the setup actually.  Additionally, I’m expanding more into a Silverlight based project, and would like to utilize something like P&P Prism setup.

I’d like to write up more on my WSSF experience at some point and write back about how the Silverlight development goes.

I’ll be helping to architect and lead a larger project for at least the next 3 to 6 months.  And who knows where it will go from there  :)

Just wanted to give an update.   I’ve had some responses to other blog posts, mostly around asp.net mvc posts, so that is great to see.  I hope to respond better to those questions.

Saturday Splash

November 21st, 2009

To continue from the Super Tuesday post – here are some more highlights from this week:

First off, let’s get things started right… today is the best football game of the year – Ohio State vs. Michigan

buckeye-pride

OH!  IO!   Go Bucks  :)

Value Objects Presentation

Dan Bergh Johnsson gives an enlightening presentation on ‘value objects’.  Sounds… boring… ?  Not at all.  This is a real eye opener.  I had to sigh a few times as he spoke thinking ‘I need to go start refactoring some code!’.

Give your programming career a favor and watch his presentation over at InfoQ.

Dan Bergh Johnsson refreshes the listeners’ memory on using value objects showing by example how their good use can revolutionize a program’s architecture, simplifying it, making it more readable and testable, in a word, better.

Chrome OS:

Been following the news on Chrome OS ??? Well, it’s all very interesting!  Here are some favorite links:

Help Build Chrome OS: http://blog.chromium.org/2009/11/hello-open-source-developers-would-you.html

Demo: http://www.youtube.com/watch?v=ANMrzw7JFzA&feature=channel

Google OS Concept Video :http://www.youtube.com/watch?v=hJ57xzo287U

http://googleblog.blogspot.com/2009/11/releasing-chromium-os-open-source.html

My take on this new Operating System:

1. “Just” Chrome… hmmm… not sure about this value.

2. Android + Chrome ?  Now we’re talking.  This is the way they should proceed IMO.  Android would add value.

 

UPDATE: Looks like my #2 is right on target….read about ..converge…  :)  

Google’s co-founder, Sergey Brin…said "Android and Chrome are likely to converge over time."

 
ASP.NET MVC 2 Beta Released:

http://haacked.com/archive/2009/11/17/asp.net-mvc-2-beta-released.aspx

My favorite .NET web framework has been updated to version 2 beta. From Phil Haack’s link above:

Here are some highlights of what’s new in ASP.NET MVC 2.

  • RenderAction (and Action)
  • AsyncController
  • Expression Based Helpers (TextBoxFor, TextAreaFor, etc.)
  • Client Validation Improvements (validation summary)
  • Add Area Dialog
  • Empty Project Template
  • And More!
Go Live

ASP.NET MVC 2 Beta also includes an explicit go-live clause within the EULA.

To go along with this release is a good write up custom validation in asp.net mvc 2.  A snippet of what this post covers:

cover building a custom validation attribute using the base classes available in System.ComponentModel.DataAnnotations. ASP.NET MVC 2 has built-in support for data annotation validation attributes for doing validation on a server. For details on how data annotations work with ASP.NET MVC 2, check out Brad’s blog post.

Great stuff Phil! This is a 3rd part of Phil Haack’s series on asp.net mvc beta 2.  This team continues to impress me on their progress.  As David Hayden has said ‘"hopefully you have spent the past year learning and mastering the ASP.NET MVC Framework, because Webforms is officially dead"’  :)   (LOL)

P&P Web Client Developer Guidance

I’m going to start following the Web Client guidance project from the Patterns and Practices team.  Some of their ‘anticipated benefits’ (from CodePlex site) include:

      • Provides infrastructure for developing and maintaining ASP.NET and AJAX applications
      • Provides guidance on MVC 2, jQuery, and AJAX library
      • Unit testing for ASP.NET and JavaScript client applications
      • Responsive applications
      • Flexible architecture that allows change
      • Separated presentation including unit testing view logic
      • Application modules are developed, tested and deployed separately
      • User Interface components are dynamically composed
      • Guidance on how to improve Web client security
      • Allows incremental adoption of the components

This is a bold list, but a good list of future features.  I’m going to urge this team to make these a reality.  As some know from my past post, I consider ‘Grails’ to be the defacto standard right now for a web application framework.  That said, personally I’d like to see this team start to take on their model of convention over configuration, etc… and provide guidance that implements practices – such as IoC for injecting services into the controllers, a loosely coupled architecture, testing structures created – build/test routines, ease of switching back and forth from test/dev/production in builds – simplified setups for developers with consistent project layouts.  I think their list again, is bold, but good.  I look forward to seeing this progress.

 

Chrome Frame:

http://code.google.com/chrome/chromeframe/

Yes… I actually used this – and it worked out well.  We enjoy the benefits of Chrome, and a customer that uses IE.  Where it helped was we are using Reporting Services in certain pages.  These pages did not include the frame to get the printing functionality of IE.  Meanwhile, the rest of the application enjoyed the Chrome features, all looking as if it’s in IE.  (Note: this was an intranet web app)

 

Davey Brion’s Introducing the ‘Agatha’ Project

http://davybrion.com/blog/2009/11/introducing-the-agatha-project/

What is Agatha ?  Agatha is a new ‘Response/Request Service Layer’  RRSL.   http://davybrion.com/blog/2009/11/requestresponse-service-layer-series/

These are the posts that this series consists of:

  1. Requests And Responses
  2. Processing Requests
  3. Handling Requests
  4. Exposing The Service Layer Through WCF
  5. Synchronous Client-Side Usage
  6. Testing Synchronous Client-Side Usage
  7. Asynchronous Client-Side Usage
  8. Testing Asynchronous Client-Side Usage
  9. Conclusions

This is an open source project.  He summarized a list of items in his concluding post. 

 

Udi Dahan (NServiceBus) on Search and Messaging:

http://www.udidahan.com/2009/11/01/search-and-messaging/

One question that I get asked about quite a bit with relation to messaging is about search. Isn’t search inherently request/response? Doesn’t it have to return immediately? Wouldn’t messaging in this case hurt our performance?

Learn more about Search and Messaging – as I lean toward SOA/EDM/ESB architecture, these are critical pieces to understand, in particular the Command/Query pattern:

See Udi’s post on ‘Command Query Separation and SOA’.

Steve Sanderson on ‘Selective Unit Testing – Costs and Benefits’

Steve Sanderson, author of my favorite ASP.NET MVC Framework book has a good article on ‘selective-unit costs & benefits.

Here is a snippet to get you started:

So why am I writing this? Two reasons:

  1. Because I think we can go further and understand the underlying forces that make unit testing worthwhile (or not) for any given unit of code.
  2. Because a minority of developers still believes that they should aim for 100% unit test coverage, and that if they don’t follow the TDD code-first process, then they’ve failed as a professional. I’m not satisfied with that view.

Dan North Presentation… Pimp My Architecture

November 12th, 2009

Thoroughly enjoyed this presentation ‘Pimp My Architecture’ over at InfoQ…given by Dan North of ThoughtWork.

Check it out if you get a chance  (sounds like 95% of the places I’ve been too…lol)

At the very least, unless I’m just too much of a geek, you have to get a laugh out of his standup meeting part  :)

And ‘we never called it pairing… just a lot of helping going on’   :)

Bulk Data Operations with NHibernate

November 11th, 2009

…using ‘Stateless session’ :

http://nhforge.org/blogs/nhibernate/archive/2008/10/30/bulk-data-operations-with-nhibernate-s-stateless-sessions.aspx

The key here is that an IStatelessSession does not use the first-level cache.  Basically by default, every object that is saved or loaded through a session is cached in the first level cache.  In normal operations you want this functionality, but if you are, ie. looping through items to save, it’s better to use the stateless session