Skip to content

Instantly share code, notes, and snippets.

View ThomasArdal's full-sized avatar
🎢

Thomas Ardal ThomasArdal

🎢
View GitHub Profile
@ThomasArdal
ThomasArdal / gist:ce32939ef1a5a079fed5
Created June 16, 2014 06:20
Create a new versioned Elasticsearch index
var connectionSettings = new ConnectionSettings(new Uri("http://localhost:9200/"));
connectionSettings.SetDefaultIndex("customers");
var elasticClient = new ElasticClient(connectionSettings);
elasticClient.CreateIndex("customers-v1");
elasticClient.Alias(x => x.Add(a => a.Alias("customers").Index("customers-v1")));
elasticClient.Map<Customer>(d =>
d.Properties(p => p.Number(n => n.Name(name => name.Zipcode).Index(NonStringIndexOption.not_analyzed))));
@ThomasArdal
ThomasArdal / Customer.cs
Created June 12, 2014 18:33
Elasticsearch migration c# example
namespace ConsoleApplication1
{
public class Customer
{
public int Zipcode { get; set; }
}
}
@ThomasArdal
ThomasArdal / Vagrant up output
Created May 5, 2014 11:49
Output from Vagrant when installing Elasticsearch
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise32'...
...
[default] Machine booted and ready!
...
Setting up openjdk-7-jre-headless (7u55-2.4.7-1ubuntu1~0.12.04.2) ...
...
--2014-05-05 07:50:35-- https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.1.deb
...
sudo /etc/init.d/elasticsearch start
@ThomasArdal
ThomasArdal / Elasticsearch install script
Created May 5, 2014 11:46
Script to setup Elasticsearch on Linux
#!/usr/bin/env bash
# update apt
sudo apt-get update
# install java
sudo apt-get install openjdk-7-jre-headless -y
# install elasticsearch
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.1.deb
#!/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
@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
@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)
GlobalFilters.Filters.Add(new StatsdActionFilter());
var metricsConfig = new MetricsConfig
{
StatsdServerName = "localhost",
Prefix = "myMvcApp"
};
Metrics.Configure(metricsConfig);
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";