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
private static readonly StringBuilder Sb = new StringBuilder();
private static void ShowResults()
{
const string outputFile = "output.txt";
File.WriteAllText(outputFile, Sb.ToString());
Process.Start("notepad", outputFile);
}
@gabrielgreen
gabrielgreen / Example.xsd
Created July 16, 2011 10:42
Example XSD
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Lead">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="TName" />
<xs:element name="Interested" type="TBool" />
</xs:sequence>
</xs:complexType>
</xs:element>
@gabrielgreen
gabrielgreen / gist:1158596
Created August 20, 2011 03:13
ef tdd attempt
using EomApp1.Formss.AB2.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
namespace TestProject6
{
/// <summary>
@gabrielgreen
gabrielgreen / Extend decimal type to return a formatted currency string
Created March 16, 2012 19:25
Extend decimal type to return a formatted currency string
public static string ToCurrencyString(this decimal amount, string currency)
{
var map = new Dictionary<string, string>
{
{"USD", "en-us"},
{"GBP", "en-gb"},
{"EUR", "de-de"},
{"AUD", "en-AU"},
{"CAD", "en-us"}
};
using System;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;
using DirectTrack;
using System.Linq;
namespace AOP
{
/// <summary>
@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
@gabrielgreen
gabrielgreen / gist:2597413
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
@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 / 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 / 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;