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 / 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()
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 / 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();
@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 / ILogger.cs
Created August 17, 2012 19:05
Mixin Demo
namespace MixinDemo
{
public interface ILogger
{
}
}
@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 / CopyProperties.cs
Created August 28, 2012 21:06
CopyProperties
static void CopyProperties(object sourceObject, object targetObject, bool deepCopy = true)
{
if (sourceObject != null && targetObject != null)
{
(from sourceProperty in sourceObject.GetType().GetProperties().AsEnumerable()
from targetProperty in targetObject.GetType().GetProperties().AsEnumerable()
where sourceProperty.Name.ToUpper() == targetProperty.Name.ToUpper()
let sourceValue = sourceProperty.GetValue(sourceObject, null)
where sourceValue != null
select CopyProperty(targetProperty, targetObject, sourceValue, deepCopy))
@gabrielgreen
gabrielgreen / SqlUtility.cs
Created September 6, 2012 05:00
SqlUtility
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Collections;
public static class SqlUtility
{
public static T ExecuteScalar<T>(string connStr, string query, params object[] queryParams)
{
using (var con = new SqlConnection(connStr))
using (var cmd = new SqlCommand(query, con))
@gabrielgreen
gabrielgreen / EmailUtility.cs
Created September 7, 2012 07:35
EmailUtility
using System;
using System.Net.Mail;
public static class EmailUtility
{
public static void SendEmail(string from, string[] to, string[] cc, string subject, string body, bool isHTML)
{
MailMessage message = new MailMessage
{
Subject = subject,
@gabrielgreen
gabrielgreen / CampaignsApiController.cs
Created September 25, 2012 22:52
ApiController vs Controller
using System.Linq;
using System.Web.Http;
using DirectAgents.Domain.Concrete;
using EomToolWeb.Models;
namespace EomToolWeb.Controllers
{
public class CampaignsApiController : ApiController
{
private EFDbContext db = new EFDbContext();