Skip to content

Instantly share code, notes, and snippets.

public class MinmalisticHashSet<T>
{
private readonly Dictionary<T, object> _dictionary = new Dictionary<T, object>();
public bool Add(T item)
{
if (_dictionary.ContainsKey(item)) return false;
_dictionary[item] = null;
return true;
}
private static IEnumerable<string> Something()
{
yield return "Something() One";
yield return "Something() Two";
yield return "Something() Three";
}
// When the compiler encounters an iterator block it emits a nested type for the state machine similar to this:
@AlexArchive
AlexArchive / gist:99b2f8f0f5510a6b350d
Created June 20, 2014 15:30
Implementing enumerators manually is painful.
public class DemonstrationList<T> : IEnumerable<T>
{
private const int defaultCapacity = 10;
private T[] items = new T[defaultCapacity];
private int count = 0;
public void Add(T item)
{
if (count == items.Length)
{
var sequence = new[] { 5, 4, 3, 2, 1 };
var varSum = sequence.Aggregate((sum, number) => sum + number);
var varCount = sequence.Aggregate(0, (count, number) => count + 1);
var varMin = sequence.Aggregate((min, number) => number < min ? number : min);
var varMax = sequence.Aggregate((max, number) => number > max ? number : max);
var varAverage = varSum / varCount;
var varAverageAlt = sequence.Aggregate(new { sum = 0, count = 0 },
(anonObj, number) => new { sum = anonObj.sum + number, count = anonObj.count + 1 },
anonObj => anonObj.sum / anonObj.count);
public class ProfileModule : ModuleBase
{
public ProfileModule()
{
Get["/profile/{gamertag}"] = context =>
{
Profile profile = XboxClient.Profile.GetProfile(context.Gamertag);
if (profile == null)
return this.ErrorMessage(HttpStatusCode.BadRequest, "Profile does not exist.");
@AlexArchive
AlexArchive / git cheat sheet
Last active August 29, 2015 14:02
Git Cheat Sheet
git remote -v #output remotes
git remote rm REMOTENAME #remove remote
git diff #diff for unstaged files
git diff --staged #diff for staged files
git diff --cached #diff for staged files
rm -rf .git #delete Git directory
Closures
Covariance and Contravaraince
Defered Execution
Method Group
Implicit Conversions
Extension Methods
Properties
Events
Law of Demeter
USE Musical;
CREATE TABLE dbo.Customer(
CustomerID INT PRIMARY KEY NOT NULL,
Title NVARCHAR(8),
FirstName NVARCHAR(50) NOT NULL,
LastName NVARCHAR(50) NOT NULL,
);
CREATE TABLE dbo.CustomerAddress(
{
"Data": {
"Friends": [{
"GamerTag": "AA doomroka",
"GamerTileUrl": "https://avatar-ssl.xboxlive.com/avatar/AA%20doomroka/avatarpic-s.png",
"LargeGamerTileUrl": "https://avatar-ssl.xboxlive.com/avatar/AA%20doomroka/avatarpic-l.png",
"GamerScore": 61090,
"IsOnline": false,
"LastSeen": "\/Date(1041379200000)\/",
"Presence": "Offline",
namespace Code
{
public class XboxLogin
{
private static void Do()
{
var cookieContainer = new CookieContainer();
var handler = new HttpClientHandler();
handler.AllowAutoRedirect = true;
handler.CookieContainer = cookieContainer;