Skip to content

Instantly share code, notes, and snippets.

View mikeminutillo's full-sized avatar
🏠
Working from home

Mike Minutillo mikeminutillo

🏠
Working from home
View GitHub Profile
@mikeminutillo
mikeminutillo / EngineerSamurai
Created December 17, 2010 05:01
Simple Gr1d.org warrior to enter the Arena. The actual actions and strategies are secret sauce :p
public void Tick(IAgentUpdateInfo agentUpdate)
{
if (agentUpdate.Node.OpposingAgents.Any()) FightOrFlight(agentUpdate);
else SeekEnemiesAndBuffUp(agentUpdate);
}
private void FightOrFlight(IAgentInfo agentInfo)
{
if (IsOutnumbered(agentInfo) || IsOutgunned(agentInfo)) Move(agentInfo, FleeStrategy);
else Fight(agentInfo);
}
@mikeminutillo
mikeminutillo / EngineerSamurai.cs
Created December 17, 2010 09:52
The core of my Engineer Samurai. Need to store self as internal state so that I can clean it up a bit
if (EnemiesOf(self).Any())
if (!IsConfident(self) && CanMove(self)) Move(self, Fleeing);
else Fight(EnemiesOf(self));
else if (IsInjured(self)) Heal();
else if (IsBuffed(self) && CanMove(self)) Move(self, Hunting);
else Buff();
using System;
using System.Threading;
namespace MagicUI.Framework
{
public static class Execute
{
[ThreadStatic]
private static bool _isUiThread;
interface IUpdaterUI {
void UpdateStatus(int? progress = null, string message = null);
void SoftwareUpdateComplete();
void DataUpdateComplete();
}
class MyForm : IUpdaterUI {
public void UpdateStatus(int? progress = null, string message = null) {
if(progress.HasValue) SetProgress(progress.Value);
if(message != null) MessageLabel.Do(ctl => ctl.Text = message);
@mikeminutillo
mikeminutillo / Sequencer.cs
Created March 30, 2011 03:27
A reusable component designed to allow only the most recent requests to update the UI
public interface ISequencerToken
{
bool IsCurrent { get; }
}
public class Sequencer
{
private long _currentToken = 0;
private long Bump()
@mikeminutillo
mikeminutillo / Config.cs
Created April 15, 2011 13:40
For AppHarbor use, this will use the config file by default but fall back to the corresponding environment variable if you use the value {ENV}
public interface IConfig
{
string Get(string key);
}
public class Config : IConfig
{
public string Get(string key)
{
var fromConfig = ConfigurationManager.AppSettings[key];
@mikeminutillo
mikeminutillo / gist:949535
Created April 30, 2011 08:41
Quick Tool to update the postName for each entry in my converted BlogML Blogger export file
var inputFile = @"whatever.xml";
var outputFile = @"whatever.updated.xml";
BlogMLBlog blog;
using (var reader = new StreamReader(inputFile))
blog = BlogMLSerializer.Deserialize(reader);
var usedNames = new List<string>();
foreach(var post in blog.Posts.OrderBy(p => p.DateCreated))
{
@mikeminutillo
mikeminutillo / Permute.cs
Created October 27, 2011 12:57
Permutations - writing LISP in C#
public static class Extensions
{
public static IEnumerable<IEnumerable<T>> Permute<T>(this IEnumerable<T> items)
{
var isEmpty = true;
foreach (var item in items)
{
isEmpty = false;
foreach (var p in items.Except(item.Yield()).Permute())
yield return item.Yield().Concat(p);
@mikeminutillo
mikeminutillo / rxhelper.cs
Created February 20, 2012 06:15
Extnesion method for Rx-ification
public static class Async
{
public static Func<Task<T>> Make<T>(Action<TaskCompletionSource<T>> action)
{
var completionSource = new TaskCompletionSource<T>();
action(completionSource);
return completionSource.Task;
}
@mikeminutillo
mikeminutillo / extract.xml
Created March 21, 2012 06:09
Simple DSL for defining Document structures from Relational Data
<?xml version="1.0" encoding="UTF-8"?>
<Extract>
<Orders>
<Order DateCreated="2012-03-21" CustomerNumber="1234">
<OrderLine Qty="2" UnitPrice="15.00" ProductCode="TAC123" />
<OrderLine Qty="45" UnitPrice="0.15" ProductCode="TAC321" />
</Order>
<Order DateCreated="2012-03-21" CustomerNumber="5678">
<OrderLine Qty="9" UnitPrice="27.00" ProductCode="TAC987" />
</Order>