Skip to content

Instantly share code, notes, and snippets.

View ddikman's full-sized avatar

David Dikman ddikman

View GitHub Profile
@ddikman
ddikman / run-logstash.sh
Created January 28, 2016 14:09
Shell command to run logstash with config
docker run -d -p 9300:9300 -v /home/ec2-user/:/var/logstash/ logstash logstash -f /var/logstash/logstash.conf
@ddikman
ddikman / configuration.dev.json
Created February 1, 2016 10:19
Example of a serilog configuration in json
{
"Logging": [
{
"key": "minimum-level",
"value": "Debug"
},
{
"key": "using:RollingFile",
"value": "Serilog.Sinks.RollingFile"
},
@ddikman
ddikman / LoggerSettings.cs
Created February 1, 2016 10:20
Serilog Json configuration reader
public class LoggerSettings : ILoggerSettings
{
private readonly IConfigurationSection _configuration;
public LoggerSettings(IConfigurationSection configuration)
{
_configuration = configuration;
}
public IEnumerable<KeyValuePair<string, string>> Configurations
@ddikman
ddikman / Startup.cs
Created February 1, 2016 10:22
Example of how to read serilog configuration and add into Asp Net 5
public class Startup
{
public Startup(IHostingEnvironment env)
{
string configFile = $"config.{env.EnvironmentName}.json".ToLower();
var configBuilder = new ConfigurationBuilder().AddJsonFile(configFile);
Configuration = configBuilder.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Settings(new LoggerSettings(Configuration.GetSection("Logging")))
@ddikman
ddikman / alias.bat
Created February 3, 2016 09:25
Simple command line script for aliasing commands
@ECHO off
IF "%1" == "" goto failUsage
WHERE alias.cmd > tmpPathFile
SET /p currdir= < tmpPathFile
del tmpPathFile
SET currdir=%currdir:alias.cmd=%
@ddikman
ddikman / filebeat-example.yml
Created January 28, 2016 14:00
Example of a filebeat config
filebeat:
prospectors:
-
paths:
# - C:\Users\David\AppData\Local\Temp\UMS-logs\um-log*.log
- /var/log/um-log-*.log
encoding: plain
input_type: log
force_close_files: false
public static class EnumerableExtensions
{
public static bool TryGetFirst<T>(this IEnumerable<T> source, Func<T, bool> predicate, out T result)
{
result = source.FirstOrDefault(predicate);
if (default(T) == null)
return result != null;
return default(T).Equals(result);
@ddikman
ddikman / ExceptionFormatterExtension.cs
Created September 6, 2016 13:04
C# extension to dump the entire stack trace and hierarchy of an exception
public static class ExceptionFormatterExtension
{
public static string GetDump(this Exception e)
{
var exceptions = new Stack<Exception>();
while (e != null)
{
exceptions.Push(e);
e = e.InnerException;
}
@ddikman
ddikman / list-http-status.sh
Created September 10, 2016 13:42
Running command over multiple inputs
cat pages.txt | xargs -n1 curl -I
@ddikman
ddikman / SampleCollectionExtension.cs
Created September 14, 2016 04:14
Extension methods for sampling items in generic collections.
using System;
using System.Collections.Generic;
using System.Linq;
namespace System.Collections.Generic
{
public static class SampleCollectionExtension
{
private static readonly Random Random = new Random();