Skip to content

Instantly share code, notes, and snippets.

View plaurin's full-sized avatar

Pascal Laurin plaurin

View GitHub Profile
@plaurin
plaurin / Test.json
Created August 29, 2012 02:26
Test Json highlighter
{
"Id": 1001,
"Date": "2012-09-12",
"Customer": "Guy Barette",
"ShippingAddress":
{
"Address": "2000 McGill College, 4e étage, Montréal, QC",
"PostalCode": "H3A 3H3",
"Country": "Canada"
},
@plaurin
plaurin / MemoryAppenderUT.cs
Created September 1, 2012 02:56
TryCache exemple
[SetUp]
public void SetUp()
{
this.memoryAppender = new MemoryAppender();
BasicConfigurator.Configure(this.memoryAppender);
...
}
[Test]
@plaurin
plaurin / SelfCompile
Created October 7, 2012 21:00
Self Compiling LinqPad query
void Main()
{
Environment.CurrentDirectory = Path.GetDirectoryName(Util.CurrentQueryPath);
Compiler.CompileFiles(Options.CreateOnDiskDll(
@namespace: "LinqPad.QueriesCompiler",
outputFile: "LinqPad.QueriesCompiler.dll")
.AddCodeFile(CodeType.LinqProgramTypes, Util.CurrentQueryPath))
.Dump("Successfully created assembly at " + DateTime.Now.ToLocalTime());
}
@plaurin
plaurin / MiniProfiler.cs
Last active December 12, 2015 02:59
Example using MiniProfiler
MiniProfilerEF.Initialize_EF42(); // When using Code First
ConsoleProfiling.Start();
using (StackExchange.Profiling.MiniProfiler.Current.Step("StepName"))
{
using (var context = new Context())
{
var result = context.Entities
.Where(p => p.Property.StartsWith("Value"))
.ToList();
var connectionString="...";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
var client = storageAccount.CreateCloudTableClient();
var table = client.GetTableReference("Demo");
table.CreateIfNotExists();
// dynamic keyword to use a dynamic entity
dynamic entity = new ElasticTableEntity();
entity.PartitionKey = "Partition123";
@plaurin
plaurin / ElasticTableEntity.cs
Created March 13, 2013 01:09
ElasticTableEntity is a reusable dynamic entity used for the Azure Table Storage Service
public class ElasticTableEntity : DynamicObject, ITableEntity,
ICustomMemberProvider // For LinqPad's Dump
{
public ElasticTableEntity()
{
this.Properties = new Dictionary<string, EntityProperty>();
}
public IDictionary<string, EntityProperty> Properties { get; private set; }
@plaurin
plaurin / DocumentStoreRepository.cs
Last active December 15, 2015 12:28
Document store implementation for Windows Azure Table Storage service using the ElasticTableEntity class
public class ProjectRepository
{
private CloudTable table;
public ProjectRepository()
{
var connectionString = "...";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
var client = storageAccount.CreateCloudTableClient();
@plaurin
plaurin / DocumentStoreRepositoryUsage.cs
Last active December 15, 2015 12:28
Document store implementation usages
public class Project
{
public Guid Owner { get; set; }
public Guid Id { get; set; }
public string Name { get; set; }
public DateTime StartDate { get; set; }
public int Status { get; set; }
public List<Task> Tasks { get; set; }
}
@plaurin
plaurin / DocumentStoreBlobRepo.cs
Last active December 17, 2015 02:39
DocumentStore Repository using Blob storage
public class ProjectRepository
{
private CloudTable table;
private CloudBlobContainer container;
public ProjectRepository()
{
var connectionString = "...";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
public Slice<T> GetSlice<T>(IEnumerable<Element<T>> elements, double totalSize, double sliceWidth)
{
if (!elements.Any()) return null;
if (elements.Count() == 1) return new Slice<T> { Elements = elements, Size = totalSize };
var sliceResult = GetElementsForSlice(elements, sliceWidth);
return new Slice<T>
{
Elements = elements,