Parallel Computations in C#

by Juan 2. October 2008 17:51
Share on Facebook

Andrew Kirillov presents an easy to use framework to perform parallel computations in c#, very interesting...

Here's the article

Tags: , , ,

Programming

Creating arrays with variable lower bounds in C#

by Juan 19. September 2008 10:37
Share on Facebook

I've been working in creating some excel reports, using Interop.

The problems I had, and how horrible I found it to be is a subject for another post... in this one, I'll address a specific issue I had when setting values to a range.

A lot of the properties are object arrays (which you have to guess, because they are actually all objects, you have to cast them manually).

So far so good, the real issue is that all those arrays are not zero-based, but one-based. That is, the first index is 1 instead of 0. This in itself wouldn't be a big problem, but added to the fact that you cannot modify the values directly, it becomes an annoyance (you need to set the entire array for it to work, you can't access item 3 for example and change its value)

I did a little research (and incidentally tested stack overflow for a real answer) , and I confirmed that in c# you can't syntactically create dynamically lowered-bound arrays (like you can in VB.NET), you can, however, create it using the Array class.

I tested it quickly, and it works like a charm.

I ended up creating a wrapper class, which you can download below. It's very simple, nothing you can't do yourself in 10 seconds.

The most important part is this

public T[,] ToBidimensionalArray()

{

    return (T[,])Array.CreateInstance(typeof(T), Lengths , LowerBounds );

}

 

Stay tuned for future articles about my experience with Excel Interop, you won't believe some of the things I found...

DynamicBoundsArray.cs (871.00 bytes)

Tags: , , ,

Programming

Happy Programmer's Day!

by Juan 12. September 2008 09:45
Share on Facebook

Today is the 256th day of the year, because this year is a leap year, programmer day is on the 12th instead of the 13th.

So... happy programmer's day!

    while (true) // Started in january

        if (DateTime.Now.DayOfYear == 256)

        { 

            Console.WriteLine("Hello world!... I mean... Happy Programmer's Day!");

            break;

        }

And as a nice treat, Iceberg is buying pizzas for us all today, isn't that cool? =)

Tags:

Programming | Random Stuff

CodeCamp 2008

by Juan 11. September 2008 14:24
Share on Facebook

Ya pasó un año desde el ultimo CodeCamp, así que es hora de hacer otro.

Para anotarse, vayan a esta página, van a haber charlas muy interesantes. Espero verlos por ahí.

Tags: , ,

Programming | Events

Stackoverflow to public beta

by Juan 11. September 2008 10:39
Share on Facebook

Preparing for the big launch on monday, September 15th, StackOverflow has now switched from private to public beta.

If you want in before it goes public, head over to http://beta.stackoverflow.com and enter twitter@twitter.com (password "falkensmaze" without the quotes) when prompted. Note this is not an account, it's simple for the beta access, you still need to create an account (if you want, it's not really required... but encouraged if you want the site to track your reputation)

When you are there, you can check my user page to see my reputation, badges earned, and questions/answers I participated in.

I hope you like it as much as I do, I've been a member for a month now and it's helped me solve some problems, even with the limited number of users in the private beta.

Tags: , ,

Programming

Stack Overflow

by Juan 22. August 2008 20:21
Share on Facebook

No, this is not a post about that old problem with the same name, this is about a new Website

I've been beta testing for a few days Jeff Atwood's new venture, and I must say, it's promising. It is a site made and maintained by programmers, for programmers... kind of like a wikipedia meets experts-exchange, but free.

The beta is supposed to end at the end of the month, so that means that it will open to the general public (at least that's the current rumor) next month.

In the meantime, here are some screenshots

image

 

image

Tags: , ,

General | Programming

Dynamic SiteMap for ASP.NET Websites

by Juan 20. August 2008 10:56
Share on Facebook

I wanted some easy way to add modules to a website of mine, and have it automatically generate the menu, so I thought I'd compile some existing ideas and code I found into something useful for that end.

In short, what I wanted to do is have a Sitemap generated based on the folders in the application.

First, armed with what I learned about HttpHandlers, I created one to do just that: search folders and .aspx files and create the sitemap as needed by the XmlSiteMapProvider. It hooks to sitemap.axd and outputs the xml.
You can download that code at the end of this article, just drop it in the App_Code folder.

The target format is this

<siteMap>
  <siteMapNode title="RootNode" description="This is the root node of the site map. There can be only one root node." url="Page1.aspx" >
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page2.aspx">
      <siteMapNode title="ChildOfChildNode" description="SiteMapNode objects can be nested to any level." url="Page3.aspx"/>
    </siteMapNode>
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page4.aspx"/>
  </siteMapNode>
</siteMap>

The first problem I run into was that the .NET provider didn't like two things, the extension (.axd) and the fact that the file doesn't really exists, as can be seen quickly using Reflector.

image
(...)
image

After thinking for a bit, I decided to implement my own SiteMapProvider, luckily one already existed.

I used Stefan Sedich's code, removed the dynamic node part, and modified the way it looks for the file (which was to map the physical path, but as I said earlier, the file doesn't exist) like this:

   siteMapXML = XDocument.Load(GetUrlPath(HttpContext.Current.Request.Url.AbsoluteUri) + "/~/" +this.siteMapFile);

This way, the HttpHandler takes the request, and outputs the sitemap xml.

The result is that for this sample web site:

image

This xml is generated:

image

There's also configuration entry in the web.config file to exclude specific folders in the search, nothing too fancy:

   <add key="SiteMap_ExcludeFolders" value="App_Code;App_Themes;Bin;MasterPages"/>

So with this, whenever I add a subfolder in my application, it will automatically appear in the Menu, SiteMapPath, or whatever control that uses the sitemap.

I hope this is useful to someone

Downloads
SiteMap.cs (4.28 kb)

Tags: , , , ,

Programming

Live semantic errors

by Juan 15. August 2008 10:11
Share on Facebook

One of the new features that came with Visual Studio .NET 2008 SP1, is the real-time compiler errors (feature I read VB developers have had for a long time).

So if you type something wrong, you see it without having to compile

image

I've been working with it for two days, and I definitely don't like it, it distracts me to have errors appearing and disappearing all the time, it doesn't even let you finish writing the line, it shows an error when there isn't one (I just need to finish the line please!). I found myself trying to type faster to avoid seeing the "error".

I'm sure they had good intentions.

Luckily, almost anything can be turned off, you just need to find it.

If you go to Tools > Options > Text Editor > C# > Advanced, and uncheck "Show live semantic errors", it works like before, only showing hints

image

I will go back to the old ways with this one...

Tags: , ,

Programming | Tips

Visual Studio 2008 and .NET 3.5 SP1 Released

by Juan 12. August 2008 11:56
Share on Facebook

You can download the Visual Studio 2008 SP1 from here (which includes the .NET 3.5 SP1)

Following those links you have the information regarding what fixes and new features they bring

The ASP.NET new features include

  • Enabling high-productivity data scenarios by using ASP.NET Dynamic Data.
  • Supporting the browser navigation in ASP.NET AJAX applications by using ASP.NET AJAX browser history.
  • Increasing the download speed for ASP.NET applications by using ASP.NET AJAX script combining.
  • Enjoy!

    Tags: , , ,

    Programming

    Weak References

    by Juan 30. July 2008 15:01
    Share on Facebook

    The internal framework we are developing here at Iceberg includes a Lock Manager.

    All it does is keep a record of the status of objects (that generally represent records in a table), so you can know if it can be modified (i.e. it's not locked).

    The basic design includes a Lock(obj) method and an UnLock(obj) method. However, the possibility exists for the application to end abruptly, or even for the programmer to forget to call UnLock to free the object's exclusive lock.

    The first approach to solve this was to have the object register itself to a Ping event in the Lock Manager, so it can tell it it's still alive. The problem was that since it's registered in the Lock Manager's event, it was never garbage collected, ergo, it was always alive.

    After a few more ideas that ranged from looking for some reference count (and finding it doesn't exist) to considering manipulating the memory through unsafe code, I found the most beautiful class in the world: WeakReference

    A weak reference allows the garbage collector to collect an object while still allowing an application to access the object. If you need the object, you can still obtain a strong reference to it and prevent it from being collected. For more information about how to use short and long weak references, see Weak References.

    With 2 lines of code you can solve the problem:

    MyClass c = new MyClass();

    WeakReference w = new WeakReference(c);

    // (...)

    bool wasGarbageCollected = w.IsAlive == false;

    It's magic!

    Currently the Lock Manager creates a Weak Reference in the Lock method and ads it to a list, it has an internal timer where it iterates through the list, and it unlocks every object that was garbage collected.

    You should've seen the test application go... this is by far the best class in the .NET Framework.

    Tags: , ,

    Programming

    Powered by BlogEngine.NET 1.4.5.15
    Theme by Mads Kristensen Modified by Juan Manuel Formoso

    About the Author

    Juan Manuel
    Networking
    View my LinkedIn profile View my Facebook profile View my Twitter feed View my StackOverflow CV

    Juan Manuel Formoso
    There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something more bizarrely inexplicable.

    There is another theory which states that this has already happened.

    E-mail me Send mail

    Hosting is not Free

    Google Reader Picks

    Most comments

    Cristian Cristian
    1 comments
    co Colombia

    Calendar

    <<  September 2010  >>
    MoTuWeThFrSaSu
    303112345
    6789101112
    13141516171819
    20212223242526
    27282930123
    45678910

    View posts in large calendar

    Recent comments

    Comment RSS

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in  anyway.

    © Copyright 2008