Sasha Sydoruk

Building a better mousetrap with XHTML, AJAX and RSS

Archive for the 'development' Category

FormsAuthentication.SetAuthCookie does not work the same way in ASP.NET 2.0

Obviously I missed the boat somewhere along the line. I realized today that I’ve never used FormsAuthentication in an ASP.NET v2.0 application before. As it turns out, it doesn’t work the same as it used to.

The full post is here.

No comments

Master feed of Neudesic Blogs - Subscribed!

We have a bunch of Neudesic contractors working at my company and they all look like really bright guys. So, I finally subscribed to the master feed of all the bloggers at their mothership.

Here is the link - Neudesic Blogs.

No comments

C# vs Ruby Smackdown!

Finally I get to write a “smackdown” post. I had this post written for a while now, but just never got to publish it.

Here is my completely non-scientific comparison of C# and Ruby. I will come up with a simple task and will attempt to implement it in both languages. The results will be shown, but no analysis will be available; I don’t want to pick sides because I really like both languages and want to stay on good terms with both of them.

Enough of disclaimers, here is the task. Create a Day class and populate a collection of instances of class Day to represent a week. Display the week in the original order, reverse the order of the days, display the new order, restore the original order, show only the work day and show only the weekends.

Here is the expected output:

Regular Order
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday

Reversed Order
Sunday, Saturday, Friday, Thursday, Wednesday, Tuesday, Monday

Regular Order
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday

Work Week
Monday, Tuesday, Wednesday, Thursday, Friday

Weekend
Saturday, Sunday

Here is how I did it in C#:

   1:  using System;
   2:  using System.Collections;
   3:  using System.Collections.Generic;
   4:  
   5:  namespace RubyCsExample
   6:  {
   7:      internal class Example
   8:      {
   9:          public static void Main()
  10:          {
  11:              List<Day> daysOfWeek = Day.CreateWeek();
  12:              DisplayDays(daysOfWeek, "Regular Order");
  13:  
  14:              //Reverse the order of the days
  15:              daysOfWeek.Sort(delegate(Day one, Day two)
  16:                                  {
  17:                                      return
  18:                                          (Comparer.Default.Compare(one.Ordinal,
  19:                                                                    two.Ordinal)*-1);
  20:                                  });
  21:              DisplayDays(daysOfWeek, "Reversed Order");
  22:  
  23:              //Restore the order
  24:              daysOfWeek.Sort();
  25:              DisplayDays(daysOfWeek, "Regular Order");
  26:  
  27:              //Show work week
  28:              DisplayDays(daysOfWeek.FindAll(delegate(Day d)
  29:                                                 {
  30:                                                     return !d.IsWeekend;
  31:                                                 }), "Work Week");
  32:  
  33:              //Show weekends
  34:              DisplayDays(daysOfWeek.FindAll(delegate(Day d)
  35:                                                 {
  36:                                                     return d.IsWeekend;
  37:                                                 }), "Weekend");
  38:  
  39:  
  40:              Console.ReadKey();
  41:          }
  42:  
  43:          public static void DisplayDays(List<Day> days, string message)
  44:          {
  45:              if (!string.IsNullOrEmpty(message))
  46:              {
  47:                  Console.WriteLine(message);
  48:              }
  49:              List<string> names = days.ConvertAll(new Converter<Day, string>(delegate(Day d)
  50:                                                                                  {
  51:                                                                                      return d.Name;
  52:                                                                                  }));
  53:              Console.WriteLine(string.Join(", ", names.ToArray()) + "nn");
  54:          }
  55:      }
  56:  
  57:      internal class Day : IComparable<Day>, IComparable
  58:      {
  59:          private string name;
  60:          private int ordinal;
  61:          private bool isWeekend;
  62:  
  63:          public Day(string name, int ordinal, bool isWeekend)
  64:          {
  65:              this.name = name;
  66:              this.ordinal = ordinal;
  67:              this.isWeekend = isWeekend;
  68:          }
  69:  
  70:          public string Name
  71:          {
  72:              get { return name; }
  73:              set { name = value; }
  74:          }
  75:  
  76:          public int Ordinal
  77:          {
  78:              get { return ordinal; }
  79:              set { ordinal = value; }
  80:          }
  81:  
  82:          public bool IsWeekend
  83:          {
  84:              get { return isWeekend; }
  85:              set { isWeekend = value; }
  86:          }
  87:  
  88:          public static List<Day> CreateWeek()
  89:          {
  90:              List<Day> days = new List<Day>(7);
  91:  
  92:              days.Add(new Day("Monday", 1, false));
  93:              days.Add(new Day("Tuesday", 2, false));
  94:              days.Add(new Day("Wednesday", 3, false));
  95:              days.Add(new Day("Thursday", 4, false));
  96:              days.Add(new Day("Friday", 5, false));
  97:              days.Add(new Day("Saturday", 6, true));
  98:              days.Add(new Day("Sunday", 7, true));
  99:  
 100:              return days;
 101:          }
 102:  
 103:          public int CompareTo(Day other)
 104:          {
 105:              return Comparer.Default.Compare(Ordinal, other.Ordinal);
 106:          }
 107:  
 108:          public int CompareTo(object obj)
 109:          {
 110:              return Comparer.Default.Compare(Ordinal, ((Day) obj).Ordinal);
 111:          }
 112:      }
 113:  }

As you can see, it took me 113 lines to achieve the required result. I am using Generics and some fancy stuff from List<>. You will need C# 2.0 to achieve similar results.

And here is the Ruby way of doing things:

   1:  class Day
   2:    attr_accessor :name, :ordinal, :is_weekend
   3:  
   4:    def initialize(name = :NotSet, ordinal = -1, is_weekend = false)
   5:      self.name, self.ordinal, self.is_weekend = name, ordinal, is_weekend
   6:    end
   7:  
   8:    def to_s
   9:      name
  10:    end
  11:  
  12:    def <=>(other_day)
  13:      self.ordinal <=> other_day.ordinal
  14:    end
  15:  
  16:    def Day.create_week
  17:      days = Array.new
  18:  
  19:      days << Day.new(:Monday, 1, false)
  20:      days << Day.new(:Tuesday, 2, false)
  21:      days << Day.new(:Wednesday, 3, false)
  22:      days << Day.new(:Thursday, 4, false)
  23:      days << Day.new(:Friday, 5, false)
  24:      days << Day.new(:Saturday, 6, true)
  25:      days << Day.new(:Sunday, 7, true)
  26:  
  27:      return days
  28:    end
  29:  
  30:  end
  31:  
  32:  def self.display_days(days, message = nil)
  33:    puts "#{message}n" if message
  34:    puts days.map{|day| day.name}.join(', ')
  35:    puts "nn"
  36:  end
  37:  
  38:  days_of_week = Day.create_week
  39:  
  40:  display_days(days_of_week, 'Regular Order')
  41:  
  42:  #Reverse the order of the days
  43:  days_of_week.sort!{ |a, b| (a <=> b) * -1 }
  44:  
  45:  display_days(days_of_week, 'Reversed Order')
  46:  
  47:  #Restore the order
  48:  days_of_week.sort!
  49:  
  50:  display_days(days_of_week, 'Regular Order')
  51:  
  52:  #Show work week
  53:  display_days(days_of_week.find_all{|day| !day.is_weekend}, 'Work Week')
  54:  
  55:  #Show weekends
  56:  display_days(days_of_week.find_all{|day| day.is_weekend}, 'Weekend')

As you can Ruby implementation took only 56 lines to achieve the required result.

Conclusion? I had a lot of fun playing with both languages. Give both languages a try!

13 comments

Prototype 1.5 was released. And now it has documentation and a brand new site!

Wow, what a day… New Rails and new Prototype are out. The new website for Prototype looks really nice. I can’t wait to dive into the documentation and see what’s new!

It also looks like new Script.aculo.us is on the way too.

Future looks bright!

No comments

Ruby On Rails 1.2 is out! Yay!

Get out your party balloons and funny hats because we’re there, baby. Yes, sire, Rails 1.2 is finally available in all it’s glory. It took a little longer than we initially anticipated to get everything lined up (and even then we had a tiny snag that bumped us straight from 1.2.0 to 1.2.1 before this announcement even had time to be written).

Rails 1.2: REST admiration, HTTP lovefest, and UTF-8 celebrations

No comments

Ruby In Steel Developer Announced

SapphireSteel Software today formally announced Ruby In Steel Developer – the only professional Ruby programming environment for Microsoft’s Visual Studio 2005.

Ruby In Steel Developer provides a full suite of editing and debugging tools for Ruby and Ruby On Rails (‘Rails’) developers. Product highlights include:

Editing
- Ruby and Rails (RHTML) code coloring
- Ruby and Rails code folding/collapsing
- Smart Indenting and code formatting
- Ruby auto-expand snippets

Debugging
- Ultra-fast integrated debugger
- Step-Into/Step-Over/Step-Out tracing
- ‘Drill-down’ watch variables
- Interactive ‘run and debug’ console

IntelliSense
- Accurate (by class and scope) member completion
- Parameter completion tooltips
- Class and method documentation in tooltips
- Code navigation drop-down combos over the editor

Ruby On Rails
- Import Existing Ruby On Rails Projects
- Rails Toolbar and script-runner dialogs
- RHTML / HTML switchable editor
- One-click Rails Debugger

A complete feature list can be found on the SapphireSteel web site:
Feature List

No comments

Scott Hanselman’s - “Language Extensibility” podcast

So, just as I was about to complain about how Scott Hanselman got me hooked on his I-can-stop-listening-to-this-podcast-any-time-I-want-I-just-don’t-want-to-right-now aka Hanselminutes and then left for his vacation and left me high and dry, desperately craving the sweet embrace of the new Hanselminutes, I noticed the new entry on my RSS reader in uTorrent.

There is no way – I thought to myself. He just came back from Africa. He did have enough time to come up with a new podcast. Must be something not very good…

But good it was. In fact, it was awesome. In his new podcast “Language Extensibility”, Scott talks about the future of IronPython and ASP.NET. This subject interested for quite a long time now. My interest was initially sparked by this white paper and this blog post. I tried to look for more information but came up with nothing.

Before you start with the “Language Extensibility”, I would strongly recommend listening to “Dynamic vs Compiled Languages” first, because it provides a lot of useful information that feeds nicely into the following podcast.

Once again, Scott proved that he knows his stuff and if you want to know what is happening in .Net world, his podcast is the podcast to listen to.

Thank you Scott!

1 comment

XSS through PDF files

This is just great. You can now hack websites with XSS in PDF files. Adobe Reader will executed any JavaScript passed to it through a query string. Here is a working example:

http://www.example.com/document.pdf#whatever_name_you_want=javascript:alert(document.cookie);

If you replace www.example.com and document.pdf with valid samples and click on the link, the browser will pop up, load the specified file from the specified site and show you your cookies for that site.

Adobe Reader v8.0 is not affected. Also, this does not work on some Win XP SP2 + IE 7.0 systems.

Found via Alek Levin.

No comments

Infragistics NetAdvantage - I really don’t like it…

Just to vent some of my frustration. Infragistics is a real piece of crap. If you even think about using it for your web project please stop right now. Get yourself Telerik controls and meet your deadlines, go home happy and proud of your work, kiss your wife and hug your kids.

But, if you enjoy debugging weird errors in somebody else’s code, horrible documentation, emailing to a non-existent support and reading support forums devoid of any helpful answers, go ahead and get Infragistics. And you know, while you are at it, sign up for an AOL account as well.

Just to make sure my message is clear – I hate Infragistics with passion. Infragistics is the Visual Source Safe of web controls for asp.net.

UPDATE:

Downgraded the ranting level to YELLOW.

8 comments

New Year’s Resolutions

New Year is coming and it is time to make new plans. Here is the list of the things I would like to learn more about in 2007.

1. 70-528: TS: Microsoft .NET Framework 2.0—Web-Based Client Development
2. Ruby On Rails
3. ASP.NET AJAX
4. JavaScript
5. Scrum

No comments

« Previous PageNext Page »