Skip to content

Instantly share code, notes, and snippets.

View ThomasArdal's full-sized avatar
🎢

Thomas Ardal ThomasArdal

🎢
View GitHub Profile
@ThomasArdal
ThomasArdal / Movie.cs
Created September 24, 2014 12:55
Movie class with constructor
public class Movie
{
public string Title { get; private set; }
public List<string> Genres { get; private set; }
public Movie(string title, List<string> genres)
{
Title = title;
Genres = genres;
@ThomasArdal
ThomasArdal / Movie.cs
Last active August 29, 2015 14:06
Class containing auto-properties with default values through initializers (decompiled)
public class Movie
{
private readonly string <Title>k__BackingField
private readonly List<string> <Genres>k__BackingField;
public string Title
{
get { return this.<Title>k__BackingField; }
}
@ThomasArdal
ThomasArdal / Movie.cs
Last active August 29, 2015 14:06
Class containing auto-properties with default values through initializers
public class Movie
{
public string Title { get; } = "The Big Lebowski";
public List<string> Genres { get; } = new List<string> { "Comedy", "Crime" };
}
@ThomasArdal
ThomasArdal / Movie.cs
Last active August 29, 2015 14:06
Class containing auto-properties with default values
public class Movie
{
public string Title { get; private set; }
public List<string> Genres { get; private set; }
public Movie()
{
Title = "The Big Lebowski";
Genres = new List<string> { "Comedy", "Crime" };
@ThomasArdal
ThomasArdal / project.csproj
Last active August 29, 2015 14:06
Debug Property Group With Experimental
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>Experimental</LangVersion>
@ThomasArdal
ThomasArdal / project.csproj
Last active August 29, 2015 14:06
Debug property group
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@ThomasArdal
ThomasArdal / gist:edb530911d051dae8ceb
Last active August 29, 2015 14:06
Example of doing aggregated search using Elasticsearch and NEST
var result = elasticClient.Search<ErrorDocument>(search => search
.SearchType(SearchType.Count)
.Query(q => q
.Range(range => range
.OnField(field => field.Time)
.GreaterOrEquals(DateTime.UtcNow.AddHours(-24))
.LowerOrEquals(DateTime.UtcNow)
)
)
.Aggregations(a => a
@ThomasArdal
ThomasArdal / gist:9f8b039637e9bb826f53
Created June 16, 2014 06:22
Delete Elasticsearch index and create alias
elasticClient.DeleteIndex(d => d.Index("customers-v1"));
elasticClient.Alias(x => x.Add(a => a.Alias("customers").Index("customers-v2")));
@ThomasArdal
ThomasArdal / gist:7f8c77306550948277ec
Created June 16, 2014 06:21
Reindex versioned Elasticsearch index
var reindex =
elasticClient.Reindex<Customer>(r =>
r.FromIndex("customers-v1")
.ToIndex("customers-v2")
.Query(q => q.MatchAll())
.Scroll("10s")
.CreateIndex(i =>
i.AddMapping<Customer>(m =>
m.Properties(p =>
p.String(n => n.Name(name => name.Zipcode).Index(FieldIndexOption.not_analyzed))))));
@ThomasArdal
ThomasArdal / gist:ee68ca8bf6638beeaac7
Created June 16, 2014 06:21
Index a new customer using Elasticsearch
elasticClient.Index(new Customer { Zipcode = 8000 });