Skip to content

Instantly share code, notes, and snippets.

View gabrielgreen's full-sized avatar

Aaron Anodide gabrielgreen

  • Direct Agents
  • New York
View GitHub Profile
@gabrielgreen
gabrielgreen / RadioButtonPanel.cs
Created August 24, 2012 20:10
RadioButtonPanel
public class RadioButtonPanel<T> : FlowLayoutPanel
{
public RadioButtonPanel()
{
var graphics = this.CreateGraphics();
var zeroPadding = new Padding(0);
var initialPadding = new Padding(10, 0, 0, 0);
int radioButtonCircleWidth = 30;
graphics.MeasureString("a", RadioButton.DefaultFont);
bool first = true;
@gabrielgreen
gabrielgreen / ILogger.cs
Created August 17, 2012 19:05
Mixin Demo
namespace MixinDemo
{
public interface ILogger
{
}
}
@gabrielgreen
gabrielgreen / gist:3013620
Created June 28, 2012 20:10
Quick way to display a grid of key/value pairs using LINQ to Objects and WinForms
if (EomAppCommon.Settings.DebugEomDatabase)
{
var form = new System.Windows.Forms.Form();
var grid = new System.Windows.Forms.DataGridView {
AutoGenerateColumns = true,
Dock = System.Windows.Forms.DockStyle.Fill,
DataSource =
(from c in new [] {
Tuple.Create("DADatabaseR1ConnectionString", this.DADatabaseR1ConnectionString),
Tuple.Create("StatsYear", this.StatsYear.ToString()),
@gabrielgreen
gabrielgreen / LadderDepthFirst.cs
Created June 12, 2012 01:39
ladder depth first
void Main()
{
//Store the root node in Container
//While (there are nodes in Container)
// N = Get the "next" node from Container
// Store all the children of N in Container
// Do some work on N
var paths = new List<int[]>();
int N = 10;
var stack = new Stack();
void Main()
{
var N = 5;
Node.Graph.Add(new Node());
bool canExpand = true;
while (canExpand)
{
Func<int, IEnumerable<Move>> addNodes = steps => from c in Node.Graph
@gabrielgreen
gabrielgreen / textpretempl.cs
Created May 26, 2012 23:05
textpretemplate
namespace CodeGenExperiement
{
using System;
#line 1 "c:\users\music\documents\visual studio 2010\Projects\CodeGenExperiement\CodeGenExperiement\PreTextTemplate1.tt"
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "10.0.0.0")]
public partial class PreTextTemplate1 : PreTextTemplate1Base
{
public virtual string TransformText()
@gabrielgreen
gabrielgreen / ReflectionExtensions.cs
Created May 18, 2012 21:31
Reflection Extensions
public static class ReflectionExtensions
{
public static Type UnderlyingType(this MemberInfo member)
{
Type type;
switch (member.MemberType)
{
case MemberTypes.Field:
type = ((FieldInfo)member).FieldType;
break;
@gabrielgreen
gabrielgreen / ObjectSetExtensions.cs
Created May 18, 2012 21:25
ObjectSet Extensions
public static class ObjectSetExtensions
{
public static int IdByName<T>(this ObjectSet<T> set, string name) where T : class
{
int id = set.ToList()
.Where(c => c.MemberValue<string>("name") == name)
.Select(c => c.MemberValue<int>("id"))
.FirstOrDefault();
if (id != default(int))
@gabrielgreen
gabrielgreen / AddThing.cs
Created May 6, 2012 22:08
entity framework code first quick start
using System;
using System.Data.Entity;
namespace EFCodeFirst
{
public class Thing
{
public int Id { get; set; }
public string Name { get; set; }
}
@gabrielgreen
gabrielgreen / gist:2597414
Created May 4, 2012 20:11
powershell script to delete old files and log what gets deleted
$d = "C:\db\backup"
$today = get-date -uformat "%Y_%m_%d"
$log = "C:\db\backup\" + "Purge_" + $today + ".log"
$a = Get-ChildItem $d -recurse
foreach($x in $a)
{
$y = ((Get-Date) - $x.CreationTime).Days
if ($y -gt 3 -and $x.PsISContainer -ne $True)
{
$deleted = "Deleting - " + $x.fullname + " - Last Write Time - " + $x.LastWriteTime