Skip to content

Instantly share code, notes, and snippets.

View ThomasArdal's full-sized avatar
🎢

Thomas Ardal ThomasArdal

🎢
View GitHub Profile
using System;
using System.Threading;
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
@ThomasArdal
ThomasArdal / gist:6791576
Created October 2, 2013 10:11
Example of doing faceted search using ElasticSearch and NEST
var result = elasticClient.Search<ErrorDocument>(s => s
.FacetDateHistogram(fd => fd
.OnField(p => p.Time)
.Interval(DateInterval.Day)
.Global()
.FacetFilter(ff => ff
.Range(rf => rf
.From(DateTime.UtcNow.AddDays(-14))
.To(DateTime.UtcNow)
)
@ThomasArdal
ThomasArdal / gist:6763252
Last active December 24, 2015 07:19
Basic example using Handlebars.js template engine.
<h1>Comments</h1>
<div id="comments">
{{#each comments}}
<h2><a href="/posts/#{{id}}">{{title}}</a></h2>
<div>{{body}}</div>
{{/each}}
</div>
@ThomasArdal
ThomasArdal / gist:6763225
Last active December 24, 2015 07:19
Basic example using Knockout template engine.
<h1>Comments</h1>
<div id="comments" data-bind="foreach: comments">
<h2><a data-bind="attr: { href: '/posts/#' + id }, text: title"></a></h2>
<div data-bind="text: body"></div>
</div>
@ThomasArdal
ThomasArdal / gist:6761640
Created September 30, 2013 09:53
hello-node http server copied from http://howtonode.org/hello-node
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, { "Content-Type": "text/plain" });
response.end("Hello World\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
public class IISExpressTest
{
[Test]
public void IISExpressIsNeverDisabled()
{
XNamespace @namespace = "http://schemas.microsoft.com/developer/msbuild/2003";
var document = XDocument.Load("path to your web project (csproj)");
var element =
document.Descendants(@namespace + "Project")
.First()
var links =
LinkCheck
.On(x => x.Url(new Uri(context.Url)))
.AsBot(bot => bot.Google())
.Start();
.Where(x => (int) x.StatusCode >= 400)
.Select(x => new ValidationIssue
{
Severity = SeverityEnum.Error,
Title = "The following link returned status code " +
var result =
LinkCheck
.On(x => x.Url(new Uri("http://www.hippovalidator.com")))
.AsBot(x => x.Google())
.OnRequest(req => ...)
.OnResponse(resp => ...)
.Start();
using System;
using System.Collections;
using System.Configuration;
using System.Globalization;
using Nest;
namespace Elmah.ElasticSearch
{
public class ElasticSearchLog : ErrorLog
{
@ThomasArdal
ThomasArdal / gist:5132711
Created March 11, 2013 08:10
Remote creation of IIS websites.
$username = "insert_username_here"
$password = ConvertTo-SecureString "insert_password_here" -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
$session = New-PSSession "insert_hostname_here" -Credential $credential
Invoke-Command -Session $session -ScriptBlock {
Set-ExecutionPolicy RemoteSigned
Import-Module WebAdministration
New-Item iis:\Sites\%teamcity.build.branch%.insert_local_name_here -bindings @{protocol="http";bindingInformation=":80:%teamcity.build.branch%.insert_local_name_here"} -physicalPath c:\inetpub\wwwroot\%teamcity.build.branch%.insert_local_name_here
Set-ItemProperty 'IIS:\Sites\%teamcity.build.branch%.insert_local_name_here' ApplicationPool "ASP.NET v4.0"