Monday, February 20, 2012

Image upload with CKEditor.

Image upload with CKEditor.

My latest issue was how to integrate CKFinder for image upload in CKEditor. Here the solution.

1. Download CKEditor and extract in your web folder root.

2. Download CKFinder and extract withing ckeditor folder.

3. Then add references to the CKEditor, CKFinder and put
 <CKEditor:CKEditorControl ID="CKEditorControl1" runat="server"></CKEditor:CKEditorControl>
 to your aspx page.

4. In code behind page OnLoad event add this code snippet

protected override void OnLoad(EventArgs e)
{
CKFinder.FileBrowser _FileBrowser = new CKFinder.FileBrowser();
_FileBrowser.BasePath = "ckeditor/ckfinder/";
_FileBrowser.SetupCKEditor(CKEditorControl1);
}

5. Edit Confic.ascx file.

public override bool CheckAuthentication()
{
return true;
}

// Perform additional checks for image files.
SecureImageUploads = true;

Thanks

Tuesday, December 6, 2011

Search Algorithm


public class FuzzySearch
    {
        public static int LevenshteinDistance(string src, string dest)
        {
            int[,] d = new int[src.Length + 1, dest.Length + 1];
            int i, j, cost;
            char[] str1 = src.ToCharArray();
            char[] str2 = dest.ToCharArray();

            for (i = 0; i <= str1.Length; i++)
            {
                d[i, 0] = i;
            }
            for (j = 0; j <= str2.Length; j++)
            {
                d[0, j] = j;
            }
            for (i = 1; i <= str1.Length; i++)
            {
                for (j = 1; j <= str2.Length; j++)
                {

                    if (str1[i - 1] == str2[j - 1])
                        cost = 0;
                    else
                        cost = 1;

                    d[i, j] =
                        Math.Min(
                            d[i - 1, j] + 1,     // Deletion
                            Math.Min(
                                d[i, j - 1] + 1,    // Insertion
                                d[i - 1, j - 1] + cost));  // Substitution

                    if ((i > 1) && (j > 1) && (str1[i - 1] == str2[j - 2]) && (str1[i - 2] == str2[j - 1]))
                    {
                        d[i, j] = Math.Min(d[i, j], d[i - 2, j - 2] + cost);
                    }
                }
            }

            return d[str1.Length, str2.Length];
        }


        public static List<string> Search(string word, List<string> wordList, double fuzzyness)
        {
            
            //List<string> foundWords = new List<string>();

            //foreach (string s in wordList)
            //{
            //    // Calculate the Levenshtein-distance:
            //    int levenshteinDistance =
            //        LevenshteinDistance(word, s);

            //    // Length of the longer string:
            //    int length = Math.Max(word.Length, s.Length);

            //    // Calculate the score:
            //    double score = 1.0 - (double)levenshteinDistance / length;

            //    // Match?
            //    if (score > fuzzyness)
            //        foundWords.Add(s);
            //}

   // Tests have prove that the !LINQ-variant is about 3 times
   // faster!
   List<string> foundWords =(from s in wordList
     let levenshteinDistance = LevenshteinDistance(word, s)
     let length = Math.Max(s.Length, word.Length)
     let score = 1.0 - (double)levenshteinDistance / length
     where score > fuzzyness
     select s
    ).ToList();

            return foundWords;
        }

    }
 

Tuesday, October 4, 2011

I Built a New Kind of Number Puzzle Game (And You Can Play It Free)

 For a long time, I wanted to play a mobile puzzle game that felt genuinely strategic—something that required real brainpower, skipped the a...