Showing posts from July, 2011

simple text formatter as jquery plugin

from about two months I created an account on the biggest questions & answers web site in the world at least in my view, stackoverflow of course any programmer met it in his search. I asked my questions and answered some other questions but the interesting thing was the formatting of questions and answers. They uses Markdown for that purpose.

I am not javascript expert but I tried to build my simple formatter to use it in my work, and with jquery I create my first jquery plugin, MiroDown is the name of it (narcissism I know).

Now I will provide MiroDown code and how to use it in your web page, let's start.

first thing your page should contains <textarea> to write and <div> to preview.
<textarea id="mytext" cols="70" rows="10"></textarea> <div id="preview"></div> but before going into more code I want to explore some sample of my formatter
*text*             ==>            text **text**           ==>…

Sort any Collection by a certain property using Insertion Sort Algorithm in VB.Net

This post is a just a Vb.Net Version of the code explained in this POST
<Extension()> _ Public Sub SortCollection(Of T)(ByRef items As List(Of T), ByVal propertyName As String, Optional ByVal sortDirection As String = "asc") Dim tmpItem As Object Dim value As New Object Dim value2 As New Object Dim j As Integer Dim insertItem As Boolean Select Case sortDirection.ToLower Case "asc" Try If items.Count > 1 Then Dim itemType As String = items(0).GetType().GetProperty(propertyName).GetValue(items(0), Nothing).GetType().ToString() For i As Integer = 1 To items.Count - 1 j = i - 1 insertItem = False tmpItem = items(i) value = items(i).GetType().GetProperty(propertyName).GetValue(items(i), Nothing) Do Until insertItem va…

Sort any Collection by a certain property using Insertion Sort Algorithm in C#

Sorting is a big topic to talk about , but in IT industry you need it many time every day. My leader asked me to sort a huge collection of very complicated items.My first try take about 2 mins this is catastrophe but I kept try and try till I found a nice sorting algorithm (of course for my case) which made the sorting time became about 2 secs. Insertion Sort algorithm you can find more about it here so I will give you a sample implementation for it using C#. you can find VB.Net version here.

first, I made it for a specific datatype and a specific property which I will order by but here it is the generic version using reflection and I used this keyword to call it as extension method of my collection..
public static void SortCollection<T>(this List<T> items, String propertyName, String sortDirection = "asc") { Object tmpItem; Object value = new Object(); Object value2 = new Object(); int j; Boolean insertItem; switch (sortDirection.ToLower(…