Skip to content

Instantly share code, notes, and snippets.

View damonjmurray's full-sized avatar

Damon J. Murray damonjmurray

View GitHub Profile
@damonjmurray
damonjmurray / FizzBuzz
Last active December 23, 2015 17:39
A standard FizzBuzz solution
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
namespace FizzBuzzKata
{
public class Program
{
@damonjmurray
damonjmurray / FizzBuzz Golf
Created March 22, 2014 23:21
A 'golf' attempt at FizzBuzz using the ternary operator with some code formatting left in-tact...
using c=System.Console;
class P
{
static void Main()
{for(int i=1;i<101;i++)c.WriteLine(i%15==0?"FizzBuzz":i%5==0?"Buzz":i%3==0?"Fizz":i+"");c.ReadKey();}
}
@damonjmurray
damonjmurray / FizzBuzz with No Selection Construct
Created March 23, 2014 21:34
A FizzBuzz solution with no if statements or ternary operators
using System;
namespace FizzBuzzNoSelection
{
public class Program
{
public static void Main(string[] args)
{
for (int i = 1; i <= 100; i++)
{
@damonjmurray
damonjmurray / FizzBuzz with Custom Numeric Format Specifiers
Created March 23, 2014 21:46
A FizzBuzz solution that uses a Custom Numeric Format string to produce the desired output
using System;
namespace FizzBuzzCustomNumericFormatter
{
public class Program
{
public static void Main(string[] args)
{
const string format = "{0:#;}{1:;;Fizz}{2:;;Buzz}";
@damonjmurray
damonjmurray / FizzBuzz with string.Join over an array
Last active August 29, 2015 13:57
A FizzBuzz solution that collapses a string array using string.Join to produce the desired output
using System;
using System.Linq;
namespace FizzBuzzCollapsedStringArray
{
public class Program
{
public static void Main(string[] args)
{
Enumerable.Range(1, 100).Select(i => string.Join(string.Empty, new[]
@damonjmurray
damonjmurray / ActiveDirectoryService - Original
Created April 4, 2014 15:28
The ActiveDirectoryService class in its original state, before refactoring.
public class ActiveDirectoryService
{
private const string GroupNotFoundMessage = "The directory group, '{0}', could not be found.";
private const string UserNotFoundMessage = "The user account, '{0}', could not be found ";
private readonly string _adDomain;
public ActiveDirectoryService(string domain)
{
_adDomain = domain;
@damonjmurray
damonjmurray / ActiveDirectoryService - Refactored.cs
Last active March 18, 2016 04:35
The ActiveDirectoryService class after "fudging" generic delegates to eliminate code duplication
public class ActiveDirectoryService
{
private const string GroupNotFoundMessage = "The directory group, '{0}', could not be found.";
private const string UserNotFoundMessage = "The user account, '{0}', could not be found ";
private readonly string _adDomain;
public ActiveDirectoryService(string domain)
{
_adDomain = domain;
using System;
using System.Collections.Generic;
using System.Linq;
using FizzBuzzMap = System.Func<int, string>;
namespace FizzBuzz
{
public class Program
{
public static void Main()
@damonjmurray
damonjmurray / gist:a5d551d4733222ef3b0e
Last active August 29, 2015 14:20
Slightly read-friendlier version of integers_to_ranges method... perhaps?
# receive an array of ints, compact it, order the elements, and group them into ranges
# original:
def get_ranges_in(values_array)
return [] if values_array.nil?
values_array.compact.sort.uniq.inject([]) do |r,x|
r.empty? || r.last.last.succ != x ? r << (x..x) : r[0..-2] << (r.last.first..x)
end
@damonjmurray
damonjmurray / elixir_evens_and_odds.exs
Created January 26, 2016 22:25
Basic Elixir pattern matching for multiple assignment example
{evens, odds} = (1..10) |> Enum.partition(fn(x) -> Integer.is_even(x) end)