Skip to content

Instantly share code, notes, and snippets.

View damonjmurray's full-sized avatar

Damon J. Murray damonjmurray

View GitHub Profile
@damonjmurray
damonjmurray / macbook-setup-script.sh
Last active February 26, 2024 04:36
Ready, Aim, FI-YAAAAAAR!!!
#!/bin/sh
# Set up a fresh MacBook for software development with my personal preferences.
#
# Inspiration taken from the following:
# - Mathias Bynen's popular config: https://github.com/mathiasbynens/dotfiles
# - Thoughtbot's dev-centric script: https://github.com/thoughtbot/laptop
# - The legendary Jessie Frazelle: https://github.com/jessfraz
# - Defaults-Write: https://www.defaults-write.com/
#
@damonjmurray
damonjmurray / state_machine_sandpit.rb
Last active July 20, 2016 06:17
after_transition on: vs. after_transition to:
require 'state_machine'
module Sandpit
class Foo
state_machine :state, initial: :created do
event :start do
transition created: :running
transition running: same
end
event :stop do
@damonjmurray
damonjmurray / Rspec_subject_behaviour_question.rb
Created February 10, 2016 02:53
RSpec subject behaviour question
require 'spec_helper'
class Foo
def self.bar(first, second, third)
err_msg = '%s cannot be nil'
raise ArgumentError, err_msg % 'first' unless first
raise ArgumentError, err_msg % 'second' unless second
raise ArgumentError, err_msg % 'third' unless third
"#{first} #{second} #{third}"
@damonjmurray
damonjmurray / ruby_evens_and_odds.rb
Created January 26, 2016 22:26
Basic example of multiple assignment in Ruby
evens, odds = (1..10).partition(&:even?)
@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)
@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
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 / 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;
@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 / 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[]