Skip to content

Instantly share code, notes, and snippets.

View fdeitelhoff's full-sized avatar
🏠
Working from home

Fabian Deitelhoff fdeitelhoff

🏠
Working from home
View GitHub Profile
@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);
@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 / 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 / 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 / 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 / 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 / ExcelLifeBookFormatting.cs
Created November 8, 2013 10:07
Format a 170 x 170 cell area in Excel 2013 with a gray background and a black border.
private void ApplyFormatting(int rows, int columns)
{
// Complete surrounding borders of the gray box.
Range[Cells[1, 1], Cells[rows, columns]].Interior.Color = Color.LightGray;
Range[Cells[1, 1], Cells[rows, columns]].Borders[XlBordersIndex.xlEdgeTop].LineStyle = XlLineStyle.xlContinuous;
Range[Cells[1, 1], Cells[rows, columns]].Borders[XlBordersIndex.xlEdgeLeft].LineStyle = XlLineStyle.xlContinuous;
Range[Cells[1, 1], Cells[rows, columns]].Borders[XlBordersIndex.xlEdgeBottom].LineStyle = XlLineStyle.xlContinuous;
Range[Cells[1, 1], Cells[rows, columns]].Borders[XlBordersIndex.xlEdgeRight].LineStyle = XlLineStyle.xlContinuous;
// Set all column width to 2.14. That's a nice looking width.
@fdeitelhoff
fdeitelhoff / ExcelLifeBookBirthdays.cs
Created November 8, 2013 13:39
Calculate birthdays and visualize them in the 170 x 170 area of the Excel 2013 workbook.
private void CalculateBirthdays(int rows, int columns)
{
var days = 1;
var years = 1;
for (var row = 1; row <= rows; row++)
{
for (var column = 1; column <= columns; column++)
{
var cell = Cells[row, column] as Range;
@fdeitelhoff
fdeitelhoff / ExcelLifeBookRanges.cs
Created November 8, 2013 14:15
Mark ranges between two years in the Excel 2013 workbook.
private void MarkKinderkarden(int fromYear, int toYear)
{
MarkRange(fromYear, toYear, Color.SteelBlue);
}
private void MarkRange(int fromYear, int toYear, Color color)
{
var dayStart = fromYear*365;
var dayEnd = toYear*365;
@fdeitelhoff
fdeitelhoff / git-config.txt
Created November 11, 2013 16:31
Git configuration to use the diff-doc JavaScript diff script.
[diff]
tool = wdiff
[difftool "wdiff"]
cmd="wscript.exe \"c:\\Program Files\\TortoiseGit\\Diff-Scripts\\diff-doc.js\" \"$LOCAL\" \"`pwd`/$REMOTE\""