Skip to content

Instantly share code, notes, and snippets.

View romeshniriella's full-sized avatar
🎯
Building blockchain infrastructure

Romesh Niriella romeshniriella

🎯
Building blockchain infrastructure
  • Melbourne, VIC, AU
View GitHub Profile
@romeshniriella
romeshniriella / BasicExceptionFilter.cs
Created June 7, 2021 03:17
a very basic .net core `IExceptionFilter` implementation
public class ExceptionFilter : IExceptionFilter
{
private readonly ILogger<ExceptionFilter> _logger;
public ExceptionFilter(ILogger<ExceptionFilter> logger)
{
_logger = logger;
internal static class StringExtensions
{
public static string TruncateTo(this string val, int maxLength, bool ellipsis = true)
{
if (val == null || val.Length <= maxLength)
{
return val;
}
ellipsis = ellipsis && maxLength >= 3;
@romeshniriella
romeshniriella / PlanetConfiguration.cs
Created September 24, 2020 09:26
.Net Core DI - Register a complex object with an array of more objects
public class PlanetConfiguration
{
public List<Planet> Planets { get; set; }
public class Planet
{
public string Code { get; set; }
public int Id { get; set; }
@romeshniriella
romeshniriella / RegisterDecoratedHttpClient.cs
Created April 1, 2019 05:09
Register a Decorated HttpClient Dependency
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddAdapterApiTestClient(this IServiceCollection services, string apiUri, ConcurrentBag<DaResponse> receivedResponses)
{
services.AddHttpClient<ApiClient>(client => client.BaseAddress = new Uri(apiUri));
services
.AddSingleton<IAdapterApiClient, ApiClientSpy>(provider =>
new ApiClientSpy(provider.GetRequiredService<ApiClient>(), receivedResponses));
@romeshniriella
romeshniriella / es_aggr_full_data_18-03-10.query.json
Created July 26, 2018 06:51
An elastic search aggregation query to group users by the date and return the date and unique user IDs for that given date
{
"size": 0,
"query": {
"bool": {
"must": [{
"range": {
"Data.Attributes.Time": {
"gt": "2018-03-10T00:00:00"
}
}
@romeshniriella
romeshniriella / FunctionGetBlobContainers.cs
Created February 14, 2018 01:34
Azure function to get all the blob storage containers in my storage account
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
namespace AzBlobFuncApp
@romeshniriella
romeshniriella / Chunki.cs
Created November 10, 2017 10:17
Break a list of items into (N) number of lists with the last list containing all the items that weren't in the 1st.
/// <summary>
/// given the list of items [1,2,3] and the count 2,
/// break the list into 2 lists containing 1 in 1st list and 2,3 in 2nd list and so on.
/// </summary>
/// <typeparam name="T">type</typeparam>
/// <param name="items">item list</param>
/// <param name="listCount">no of lists to produce</param>
/// <returns>listCount no of lists containing the items. last list contains the rest</returns>
public static List<List<T>> ToChunks<T>(this IEnumerable<T> items, int listCount)
{
@romeshniriella
romeshniriella / EventHandlerBase.cs
Created August 28, 2017 12:43
simple event handler base class for Rx with masstransit
using System;
using MassTransit;
using Core.Runtime.Events;
using Core.Runtime.Events.Tracking.Contracts;
using Core.Runtime.Logging;
using Core.Utils.Extensions;
namespace Oklo.Shared.Runtime
{
public abstract class EventHandlerBase
@romeshniriella
romeshniriella / Log4NetTraceListener.cs
Created August 11, 2017 07:15
A Log4Net based trace listener for system.diagnostics.tracing
using DinkLabs.Runtime.Logging;
namespace DinkLabs.Web.Core.Logging
{
public class Log4NetTraceListener : System.Diagnostics.TraceListener
{
private readonly ILog _log;
public Log4NetTraceListener(string provider)
{
@romeshniriella
romeshniriella / restart my fucking router if connection drops.py
Created May 23, 2017 11:45
i have a really bad ADSL connection with really bad SNR. restarting the router helps most of the time. and it lasts for 15 mins tops. so automate the process.
import re
import getpass
import sys
import telnetlib
import time, threading
from subprocess import check_output
def routerTelnet():
print (time.ctime())