Skip to content

Instantly share code, notes, and snippets.

View rsingh85's full-sized avatar

Ravi Singh rsingh85

View GitHub Profile
private TextBlock CreateCellTextBlock(Cell cell)
{
TextBlock cellTextBlock = new TextBlock();
cellTextBlock.DataContext = cell;
cellTextBlock.InputBindings.Add(CreateMouseClickInputBinding(cell));
cellTextBlock.SetBinding(
TextBlock.BackgroundProperty,
CreateCellAliveBinding()
);
USE MyDatabase
GO
CREATE ASSEMBLY SqlLibrary from 'C:\SqlLibrary.dll' WITH PERMISSION_SET = SAFE
GO
CREATE FUNCTION GetTextSimilarity(@inputOne [nvarchar](4000), @inputTwo [nvarchar](4000))
RETURNS [float] WITH EXECUTE AS CALLER, RETURNS NULL ON NULL INPUT
AS
EXTERNAL NAME [SqlLibrary].[SqlLibrary.Text.StringCompare].[GetTextSimilarity]
using System;
using Microsoft.SqlServer.Server;
namespace SqlLibrary.Text
{
public class StringCompare
{
[SqlProcedure]
public static double GetTextSimilarity(
string inputOne, string inputTwo
@rsingh85
rsingh85 / ExplicitMyClass.cs
Last active August 29, 2015 14:26
Implicit vs. Explicit Interface Implementation
public class MyClass : IDoSomething
{
void IDoSomething.DoIt()
{
throw new NotImplementedException();
}
}
@rsingh85
rsingh85 / ShortCircuitByPassAND
Created November 23, 2014 12:06
Bypassing Short-circuit Boolean Evaluation of logical AND
void Main()
{
if (MethodOne() & MethodTwo())
{
}
}
bool MethodOne()
{
Console.WriteLine("MethodOne: I got evaluated!");
@rsingh85
rsingh85 / ShortCircuitAnd
Created November 23, 2014 12:05
Short-circuit Boolean Evaluation of logical AND
void Main()
{
if (MethodOne() && MethodTwo())
{
}
}
bool MethodOne()
{
Console.WriteLine("MethodOne: I got evaluated!");
@rsingh85
rsingh85 / CsvStringParseExtension
Last active August 29, 2015 14:06
A useful extension method to System.String. Given a comma-seperated list in a string, it'll return a generic List of type string, with each value occupying its own index.
public static List<string> ParseCsvToList(this string source)
{
var valuesArray = source.Split(new char[] {','});
return valuesArray.Select(value => value.Trim()).ToList();
}
@rsingh85
rsingh85 / ArrayForEachExtension
Created September 25, 2014 19:45
Array ForEach method using Action delegate - performs an action on each element of an array.
public static void ForEach<T>(this T[] sourceArray, Action<T> action)
{
foreach (T obj in sourceArray)
action(obj);
}
@rsingh85
rsingh85 / InBaseExtension
Created September 25, 2014 19:42
Convert Int32 to Base 2, 8, 10 or 16 using this extension method.
public static string InBase(this int number, int @base)
{
return Convert.ToString(number, @base);
}
@rsingh85
rsingh85 / Money
Created September 21, 2014 14:34
C# conversion operators example.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConversionOperators
{
public class Money
{
public string Currency { get; set; }