Skip to content

Instantly share code, notes, and snippets.

View rmaclean's full-sized avatar
:shipit:

Robert MacLean rmaclean

:shipit:
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
namespace ConsoleApplication2
{
public class ListPerformance
using System;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnostics.Windows;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Running;
namespace ConsoleApplication1
@rmaclean
rmaclean / gist:1eee91021e273a9b681d
Created July 29, 2014 14:12
Job Security - Validate a South African ID Number checkbit in two lines of code
// don't actually use this - it is horrid to manage. Rather use: https://gist.github.com/rmaclean/c62ce41e92df7f7f504d
var checkbit = Convert.ToInt32((parts.Where((value, index) => index % 2 == 0 && index < 11).Sum()) + ((parts.Skip(1).Where((value, index) => index % 2 == 0 && index < 12).Sum() * 2).ToString(CultureInfo.InvariantCulture).Select(_ => Convert.ToInt32(_)).Sum()).ToString(CultureInfo.InvariantCulture).Last());
return checkbit == 0 ? 0 : 10 - checkbit;
@rmaclean
rmaclean / gist:c62ce41e92df7f7f504d
Created July 29, 2014 14:12
Validate South African ID Number checkbit
private static int CheckBitCalculator(int[] parts)
{
var checkPart1 = 0;
var checkPart2 = string.Empty;
var checkPart3 = string.Empty;
var checkPart4 = 0;
var checkPart5 = string.Empty;
var checkPart6 = 0;
var checkPart7 = 0;