This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Init vector of ints | |
static const int values[] = {6,2,7,9,5,8,1,4,3,0}; | |
vector<int> v (values, values + sizeof(values) / sizeof(values[0]) ); | |
// Convert to string | |
std::stringstream ss; | |
for (int n : v) | |
ss << n; | |
string str = ss.str(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach (var item in yourList.Select((Value, Index) => new { Value, Index })) | |
{ | |
Console.WriteLine("Value=" + item.Value + ", Index=" + item.Index); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using System; | |
using System.Collections.Generic; | |
namespace SimpleStratagyFactory | |
{ | |
#region Classes | |
/// <summary> | |
/// Enumeration of different types of products to create |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq.Expressions; | |
namespace PropertyComparer | |
{ | |
#region PropertyComparer Class | |
public class PropertyComparer<T> : IEqualityComparer<T> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq.Expressions; | |
namespace SinglePropertyComparer | |
{ | |
#region SinglePropertyComparer | |
public class SinglePropertyComparer<T> : IEqualityComparer<T> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Data.Entity; | |
using System.Data.SqlClient; | |
namespace CustomDatabaseInitializer | |
{ | |
/// <summary> | |
/// This class duplicates the functionality of the built in DropCreateDatabaseAlways database | |
/// initializer but it alters the new database to enable allow snapshot isolation. | |
/// </summary> | |
public abstract class AlwaysCreateDatabaseWithTransactionIsolationContextInitializer<TContext> : IDatabaseInitializer<TContext> where TContext : System.Data.Entity.DbContext |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- List the snapshot isolation and read committed snapshot isolation level of all databases. | |
SELECT name, snapshot_isolation_state_desc AS 'Snapshot Isolation Enabled', is_read_committed_snapshot_on AS 'Read Commited Snapshot' | |
FROM sys.databases | |
-- Change the read committed transaction level behavior to use snapshot isolation for reads. | |
-- Reader gets last committed data and will not block / Writer will wait until lock is released. | |
ALTER DATABASE [Foo] SET READ_COMMITTED_SNAPSHOT ON |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
/// <summary> | |
/// Compile time (Sigil) types. (Or how to abuse static typing) | |
/// </summary> | |
public interface ISides { } // Base interface | |
public interface IZero : ISides { } // Interface that indicates zero sides | |
public interface IOnePlus<TLen> : ISides where TLen : ISides { } // Interface that gets layered on top as sides are added to the polygon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
public class NaiveFibonacciSequenceGenerator : IEnumerable | |
{ | |
private readonly int sequenceSize; | |
public NaiveFibonacciSequenceGenerator(int sequenceSize) | |
{ | |
this.sequenceSize = sequenceSize; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Prototype pattern allows objects to be created | |
// based on a template of an existing object using cloning. | |
var Dragon = { | |
name: "TROGDOR" | |
}; | |
//Object.create takes its first argument and applies it to the prototype of your new object. | |
var myDragon = Object.create(Dragon); |