Skip to content

Instantly share code, notes, and snippets.

@DevJonny
DevJonny / appsettings.json
Created December 18, 2022 14:24
Serilog Message Filtering
{
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Expressions" ],
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "StartsWith(@m, 'Some log message')"
}
}
@DevJonny
DevJonny / UnderscoreNamingStrategy.cs
Last active November 5, 2022 08:33
UnderscoreNamingStrategy example for JSON.NET
using System.Text.RegularExpressions;
using Newtonsoft.Json.Serialization;
using Xunit;
namespace CustomJsonPropertyNamePolicy;
internal class UnderscoreNamingStrategy : NamingStrategy
{
private static readonly Regex CapitalLetterGroup = new Regex("([A-Z])");
@DevJonny
DevJonny / UnderscoreNamingPolicy.cs
Last active November 5, 2022 08:33
UnderscoreNamingPolicy example for System.Text.Json
using System.Text.Json;
using System.Text.RegularExpressions;
using Xunit;
namespace CustomJsonPropertyNamePolicy;
internal class UnderscoreNamingPolicy : JsonNamingPolicy
{
private static readonly Regex CapitalLetterGroup = new Regex("([A-Z])");
@DevJonny
DevJonny / AppConfigurationDemo.cs
Last active August 13, 2022 10:43
Bind Azure App Configuration To Dictionary
using ConfigTesting;
using Microsoft.Extensions.Configuration;
var builder = new ConfigurationBuilder();
builder.AddAzureAppConfiguration(
"Endpoint=https://<config_name>.azconfig.io;Id=<ID>;Secret=<Secret>");
var config = builder.Build();
/**
@DevJonny
DevJonny / BrigterDocs.md
Last active February 10, 2020 08:50
Brighter Docs

Brighter Docs Proof reading

Event Driven Collaboration

At Event Driven Collaboration section the text on the first diagram has a type a topic on tbe broke.

Event Carried State Transfer

In the Caching section it says stale (post our GET a subsequent POST... It might just be me but that doesn't entirely make sense in my head.

@DevJonny
DevJonny / gist:01ec09fba52dd610253429da29cb716a
Last active September 5, 2019 11:42
Useful Linux commands
# List folders with file size in MB
ls -la --block-size=M <directory>
# Find total file sizes for a directory
du -h -c <directory> | tail -1
# Find all directories with name with wildcard
find -iname '<directory>*' -maxdepth 10 -mindepth 1 -type d
# Delete all directories with name with wildcard
@DevJonny
DevJonny / app.py
Last active April 8, 2019 18:33
Python multiprocessing.Process with terminating on timeout
import time
from multiprocessing import Process
def sleeper(time_to_sleep):
time.sleep(time_to_sleep)
if __name__ == '__main__':
timeout = 5
@DevJonny
DevJonny / CustomPortlet.java
Created November 12, 2012 17:23
Liferay portlet: Passing attributes to JSP
public class CustomPortlet extends MVCPortlet {
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) {
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
User currentUser = themeDisplay.getUser();
renderRequest.setAttribute("currentFirstName", currentUser.getFirstName());
// Add attributes as required
@DevJonny
DevJonny / gist:3731666
Created September 16, 2012 08:58
Android how to get HTTP 401 response
final HttpGet loginDetailsGet = new HttpGet("{your URL to pass login details to}");
loginDetailsGet.addHeader("accept", "application/json");
final HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 5 * 1000);
final Credentials credentials = new UsernamePasswordCredentials(username, password);
final DefaultHttpClient defaultHttpClient = new DefaultHttpClient(httpParameters);
defaultHttpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), credentials);
@DevJonny
DevJonny / DateTest
Created March 17, 2012 09:04
Comparing two dates with different times to check for the same day.
package com.mysmallcornerstudios.test;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTest {
public static void main(String[] args) throws InterruptedException {
Long time1 = System.currentTimeMillis();