Skip to content

Instantly share code, notes, and snippets.

View ThomasArdal's full-sized avatar
🎢

Thomas Ardal ThomasArdal

🎢
View GitHub Profile
@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: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: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)
)
using System;
using System.Threading;
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
using System.Web;
using System.Web.Mvc;
using StatsdClient;
using Stopwatch = System.Diagnostics.Stopwatch;
namespace MvcApplication1.Controllers
{
public class StatsdActionFilter : ActionFilterAttribute
{
private const string StopwatchKey = "stopwatch";
var metricsConfig = new MetricsConfig
{
StatsdServerName = "localhost",
Prefix = "myMvcApp"
};
Metrics.Configure(metricsConfig);
GlobalFilters.Filters.Add(new StatsdActionFilter());
@ThomasArdal
ThomasArdal / Send mails from PowerShell
Created January 14, 2014 07:09
Script to send a secure mail from PowerShell.
$subject = $args[0]
$message = $args[1]
$from = $args[2]
$to = $args[3]
$smtpserver = "<smtp server>"
$smtpport = 465
$username = "<smtp username>"
$password = "<smtp port>"
$credentials = New-Object System.Net.NetworkCredential($username, $password)
$smtp = New-Object Net.Mail.SmtpClient($smtpserver, $smtpport)
@ThomasArdal
ThomasArdal / Elasticsearch VagrantFile
Created May 5, 2014 11:10
VagrantFile for running Elasticsearch on Linux
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.network :forwarded_port, guest: 9200, host: 9200
end
#!/bin/sh
#
# This is a script to run syntax check (via `sh -n $filename`) but it
# supports recursive checking and --quiet
QUIET=0
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in