Skip to content

Instantly share code, notes, and snippets.

View handcraftsman's full-sized avatar

Cℓinton Sheppard handcraftsman

View GitHub Profile
@handcraftsman
handcraftsman / Railway.cs
Created May 16, 2017 15:09
c# Railway oriented Programming
/// <summary>
/// partial implementation of Railway oriented Programming in C#.
/// based on: https://www.slideshare.net/ScottWlaschin/railway-oriented-programming?ref=http://fsharpforfunandprofit.com/rop/
/// Notification<T> is defined in https://github.com/mvbalaw/MvbaCore/blob/master/src/MvbaCore/Notification.cs
///
/// Unfortunately I couldn't find very many functions in my code where this could even be applied.
/// Reasons include the function having multiple inputs, throwing an exception, triggering an async action, etc.,
/// all of which would require additional growth in this infrastructure and at least in my opinion do not make
/// the code easier to understand, debug or maintain.
/// </summary>
@handcraftsman
handcraftsman / genetic.py
Created June 26, 2016 20:23
Hello World! genetic algorithm in python
# File: genetic.py
# from chapter 1 of _Genetic Algorithms with Python_, an ebook
# available for purchase at http://leanpub.com/genetic_algorithms_with_python
#
# Author: Clinton Sheppard <[email protected]>
# Repository: https://drive.google.com/open?id=0B2tHXnhOFnVkRU95SC12alNkU2M
# Copyright (c) 2016 Clinton Sheppard
#
# Licensed under the Apache License, Version 2.0 (the "License").
[package]
name = "genetic"
version = "0.0.1"
authors = ["Clinton <[email protected]>"]
[dependencies]
rand = "*"
time = "*"
@handcraftsman
handcraftsman / gist:71feb1ce3e3b4e5b0261
Last active August 29, 2015 14:19
Determining Cheryl's birthday logically with LINQ
// for the problem description see: http://www.cnn.com/2015/04/15/living/feat-cheryl-birthday-math-problem-goes-viral/
public class Birthday
{
public Birthday(string monthName, int dayOfMonth)
{
MonthName = monthName;
DayOfMonth = dayOfMonth;
}
@handcraftsman
handcraftsman / battleship
Last active December 29, 2015 18:09
These instructions for recreating a battleship from quadrangles were generated with a genetic algorithm, see my video: https://www.youtube.com/watch?v=JYu5DcICNOk
quadrangle: {X=231,Y=44} {X=56,Y=12} {X=171,Y=228} {X=15,Y=229} color: [A=145, R=202, G=163, B=140]
quadrangle: {X=0,Y=385} {X=60,Y=204} {X=189,Y=206} {X=384,Y=386} color: [A=239, R=16, G=0, B=25]
quadrangle: {X=3,Y=9} {X=0,Y=359} {X=399,Y=373} {X=399,Y=104} color: [A=206, R=132, G=87, B=65]
quadrangle: {X=3,Y=359} {X=9,Y=226} {X=392,Y=135} {X=331,Y=371} color: [A=218, R=64, G=30, B=63]
quadrangle: {X=78,Y=174} {X=82,Y=377} {X=401,Y=379} {X=400,Y=169} color: [A=122, R=24, G=64, B=30]
quadrangle: {X=392,Y=3} {X=397,Y=231} {X=375,Y=178} {X=33,Y=17} color: [A=80, R=239, G=203, B=119]
quadrangle: {X=400,Y=4} {X=400,Y=181} {X=251,Y=160} {X=122,Y=6} color: [A=224, R=252, G=225, B=180]
quadrangle: {X=301,Y=2} {X=397,Y=172} {X=240,Y=161} {X=173,Y=56} color: [A=138, R=253, G=246, B=203]
quadrangle: {X=181,Y=7} {X=157,Y=235} {X=176,Y=268} {X=197,Y=277} color: [A=8, R=47, G=47, B=36]
quadrangle: {X=367,Y=374} {X=326,Y=128} {X=234,Y=236} {X=224,Y=369} color: [A=174, R=29, G=4, B=38]
@handcraftsman
handcraftsman / Breaker.cs
Created October 18, 2012 18:01
sample code breaker
// this breaker was used on @scichelli's
// collection comparer
// https://gist.github.com/3836918/
[Test]
public void Breaker()
{
var legal = GetIntLegals();
for (int i = 0; i < 1000000; i++)
{
@handcraftsman
handcraftsman / Terrain generation demo
Created July 6, 2011 15:10
fills a 1000x1000 grid with 300 randomly shaped terrains based on 14 terrain types, inspired by http://stackoverflow.com/questions/6586338/randomly-and-efficiently-filling-space-with-shapes/6588235#6588235
// * **********************************************************************************
// * Copyright (c) Clinton Sheppard
// * This source code is subject to terms and conditions of the MIT License.
// * By using this source code in any fashion, you are agreeing to be bound by
// * the terms of the MIT License.
// * You must not remove this notice from this software.
// * **********************************************************************************
using System;
using System.Collections.Generic;
@handcraftsman
handcraftsman / CalculatorTests.cs
Created December 13, 2010 19:38
composable pieces make tests easier to maintain
// * **************************************************************************
// * Copyright (c) McCreary, Veselka, Bragg & Allen, P.C.
// * This source code is subject to terms and conditions of the MIT License.
// * By using this source code in any fashion, you are agreeing to be bound by
// * the terms of the MIT License.
// * You must not remove this notice from this software.
// * **************************************************************************
using System.Collections.Generic;
public static IEnumerable<T> AllButLast<T>(this IEnumerable<T> input)
{
var next = input.First();
foreach(var item in input.Skip(1))
{
yield return next;
next = item;
}
}
for /F "skip=6 tokens=1" %%i in ('WHOAMI /PRIV') do SET %%i=1
if not defined SeImpersonatePrivilege (
echo This script must be run as an administrator
exit /b
)