Skip to content

Instantly share code, notes, and snippets.

@ungood
ungood / gist:946554
Created April 28, 2011 15:21
Calculate Moon Landing Equinox
function calcEquinox(midpoint) {
midpoint = midpoint || new Date();
var moonLanding = new Date("7/20/1969 20:17:40 UTC");
console.log(moonLanding);
var equinox = (2 * midpoint.getTime()) - moonLanding.getTime();
return new Date(equinox);
}
@ungood
ungood / gist:957278
Created May 5, 2011 15:45
reg v. wire example
module add(a, b, out);
input [4:0] a, b;
output [4:0] out;
wire a, b;
reg out;
always @(a or b)
out = a + b;
endmodule;
@ungood
ungood / gist:979632
Created May 18, 2011 21:42
Example of using IEnumerable as a property
public class Order
{
private List<OrderItem> items = new List<OrderItems>();
public IEnumerable<OrderItem> Items
{
get { return items.Take(int.MaxValue); }
}
}
@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.
@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;
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 / 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>
@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 / 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: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);