Skip to content

Instantly share code, notes, and snippets.

View mariusschulz's full-sized avatar
🤓

Marius Schulz mariusschulz

🤓
View GitHub Profile
@mariusschulz
mariusschulz / Digits.cs
Last active November 4, 2015 16:28
A list of characters that the regular expression pattern \d matches in .NET.
var digitRegex = new Regex(@"\d");
IEnumerable<char> digitCharacters = Enumerable
.Range(1, Char.MaxValue)
.Select(Convert.ToChar)
.Where(c => digitRegex.IsMatch(c.ToString()));
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace IndentedTextWriterDemo
{
public class TodoItem
{
const string placeholderPattern = @"
\[
\[
([^\]]+) # Description of whatever is in here
\]
\[
([^\]]+) # Description of whatever is in here
\]
\]";
isPrime = (n) ->
return true if n is 2 or n is 3
return false if n % 2 is 0
for i in [3..Math.sqrt n]
return false if n % i is 0
true
primesUnder100 = (n for n in [1..100] when isPrime n)
private static bool BinarySearch(int[] sortedHaystack, int needle)
{
int leftBoundary = 0;
int rightBoundary = sortedHaystack.Length - 1;
while (leftBoundary <= rightBoundary)
{
int pivotIndex = (int)(((long)leftBoundary + rightBoundary) / 2);
int pivotValue = sortedHaystack[pivotIndex];