Skip to content

Instantly share code, notes, and snippets.

View richardkundl's full-sized avatar

Richard Kundl richardkundl

View GitHub Profile
@richardkundl
richardkundl / Rating.cs
Last active August 11, 2018 20:26
Lower bound of Wilson score confidence interval for a Bernoulli parameter(fix: 0.9604)
using System;
namespace Rating
{
class Program
{
/// <summary >
/// Ratings
/// (Lower bound of Wilson score confidence interval for a Bernoulli parameter)
/// </summary>
@richardkundl
richardkundl / PageHelper.cs
Created February 13, 2013 21:13
Find custom controls in aspx page any depth
/// <summary>
/// Extension method for the "Page" class
/// </summary>
public static class PageHelper
{
/// <summary>
/// Find control in the page
/// </summary>
/// <typeparam name="T">return control type(eg. TextBox)</typeparam>
/// <param name="page">Actual Page</param>
@richardkundl
richardkundl / GenericEvaulatingOrderBy.cs
Last active December 15, 2015 11:29
Extending linq order by method.
namespace Common.Extension
{
using System.Linq;
using System.Linq.Expressions;
public static class GenericEvaulatingOrderBy
{
private static IOrderedQueryable<T> OrderingHelper<T>(IQueryable<T> source, string propertyName, bool descending, bool anotherLevel)
{
var param = Expression.Parameter(typeof(T), "p");
@richardkundl
richardkundl / jquery-rval.js
Created March 27, 2013 14:19
JQuery read textbox placeholder member, if the textbox value is empty. Thats wrong. This rVal return empty value, never return placeholder value.
jQuery.fn.rVal = function () {
if (this[0]) {
var ele = $(this[0]);
if (ele.attr('placeholder') != '' && ele.val() == ele.attr('placeholder')) {
return '';
} else {
return ele.val();
}
}
return undefined;
@richardkundl
richardkundl / simpleajaxcache.js
Created November 1, 2013 17:56
Simple way to caching AJAX request result
// define cache
var cache = {};
// ...
// within the AJAX callback
cache[url] = data;
// ...
// within callback that would set forth a request
if(cache[url]) {
@richardkundl
richardkundl / Sift3Distance.cs
Created November 14, 2013 15:15
Get Sift3 distance from two words. Simmilar to the Levenshtein distance, but it's four time faster. Verifying that(http://norvig.com/ngrams/) data sets.
/// <summary>
/// Get Sift3 distance from two words.
/// (eg: spell checking)
/// </summary>
/// <param name="source"> source string </param>
/// <param name="actual"> actual string </param>
/// <param name="maxOffset"> max offset </param>
/// <returns> The distance of the two words. </returns>
public static float GetSift3Distance(string source, string actual, int maxOffset)
{
@richardkundl
richardkundl / LevenshteinDistance.cs
Last active December 28, 2015 08:08
Computate Levenshtein distance, not a normal returns format. It returns the percentage difference: 0 == perfect match; 100 == totaly different
/// <summary>
/// Computate Levenshtein distance, not a normal returns format.
/// It returns the percentage difference.
/// </summary>
/// <param name="expected"> expected word </param>
/// <param name="actual"> actual word </param>
/// <returns> Value between 0 - 100
/// 0==perfect match 100==totaly different </returns>
public static byte GetLevenshteinDistance(string expected, string actual)
{
@richardkundl
richardkundl / RecursionStackoverflow.cs
Created November 26, 2013 10:49
Ensures that the remaining stack space is large enough to execute the average .NET Framework function.
try
{
RuntimeHelpers.EnsureSufficientExecutionStack();
// call recursion
}
catch (InsufficientExecutionStackException)
{
// catch recursion stackoverflow exception
}
catch
@richardkundl
richardkundl / setInterval.js
Created November 27, 2013 10:42
An alternative to Javascript's evil setInterval: - Doesn't care whether the callback is still running or not - Ignores errors - Isn't that flexible Thanks: http://www.thecodeship.com/web-development/alternative-to-javascript-evil-setinterval/
function interval(func, wait, times){
var interv = function(w, t){
return function(){
if(typeof t === "undefined" || t-- > 0){
setTimeout(interv, w);
try{
func.call(null);
}
catch(e){
t = 0;
@richardkundl
richardkundl / BloomFilter.cs
Created January 7, 2014 14:29
Bloom filter implementation in c#.
namespace BloomFilter
{
using System;
using System.Collections;
/// <summary>
/// Bloom filter.
/// </summary>
/// <typeparam name="T">Item type </typeparam>
public class Filter<T>