Skip to content

Instantly share code, notes, and snippets.

View fdeitelhoff's full-sized avatar

Fabian Deitelhoff fdeitelhoff

View GitHub Profile
@fdeitelhoff
fdeitelhoff / Ticketverlosung Herbstcampus 2013.sql
Created August 11, 2013 14:21
Ziehung des Gewinners für die Herbstcampus 2013-Ticketverlosung.
SELECT
distinct comment_author, comment_author_email
FROM
wp_comments
INNER JOIN
wp_posts
ON
comment_post_ID = id
WHERE
post_title = 'Herbstcampus 2013: Teilnahme und Ticketverlosung'
@fdeitelhoff
fdeitelhoff / CombineWithRepetition.cs
Created February 27, 2013 22:53
C# implementation for a combination with repetition. Implemented as an extension method for IEnumerable<char>.
public static IEnumerable<IList<char>> CombineWithRepetitions(this IEnumerable<char> input, int take)
{
ICollection<IList<char>> output = new Collection<IList<char>>();
IList<char> item = new char[take];
CombineWithRepetitions(output, input, item, 0);
return output;
}
@fdeitelhoff
fdeitelhoff / BHeap.cs
Created February 27, 2013 22:35
An C# implementation for the B-heap. It generates all permutations for a given number.
public static IEnumerable<IEnumerable<T>> Permute<T>(this IList<T> v)
{
ICollection<IList<T>> result = new List<IList<T>>();
Permute(v, v.Count, result);
return result;
}
private static void Permute<T>(IList<T> v, int n, ICollection<IList<T>> result)
@fdeitelhoff
fdeitelhoff / AppSettings.cs
Created February 20, 2013 16:50
Extension method for the generic access to application settings.
public static T AppSetting<T>(this string key)
{
var value = default(T);
if (ConfigurationManager.AppSettings[key] != null)
{
var converter = TypeDescriptor.GetConverter(typeof (T));
value = (T)converter.ConvertFrom(ConfigurationManager.AppSettings[key]);
}
@fdeitelhoff
fdeitelhoff / Program.cs
Created February 14, 2013 14:57
Simple console application to identify cultures with different capitalization rules.
static void Main()
{
const string lowerCharacters = "abcdefghijklmnopqrstuvwxyz";
const string upperCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (var culture in cultures)
{
var upper = lowerCharacters.ToUpper(culture);
var lower = upperCharacters.ToLower(culture);
@fdeitelhoff
fdeitelhoff / LocalizationTests.cs
Created February 14, 2013 14:09
Compare upper and lower case letters with the Turkish culture.
[TestMethod]
public void TestTurkishStringCompare()
{
const string lowerCharacters = "abcdefghijklmnopqrstuvwxyz";
const string upperCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var turkishCulture = CultureInfo.GetCultureInfo("tr-TR");
var upper = lowerCharacters.ToUpper(turkishCulture);
var lower = upperCharacters.ToLower(turkishCulture);