Skip to content

Instantly share code, notes, and snippets.

View victorjonsson's full-sized avatar
🎯
Focusing

Victor Jonsson victorjonsson

🎯
Focusing
View GitHub Profile
public SomethingController([FromBody] MyDataModel model) {
try {
DoTheStuff(model);
} catch (SpecificExceptionIKnowCanHappen exc) {
return BadRequest(new { errorCode = ErrorCode });
}
// all other exceptions will let the app crash, exception info will be sen to log and app returns status 500 to the client
return Ok();
}
// Turn our form data into a JSON string
const data ={
...
data: {
...
integrations: [
{type: 'integrationX' ... },
{type: 'integrationY' ... }
]
}
var decision = new NavetDecisionBasis()
{
Person = new NavetPerson()
{
Contact = new NavetPersonContact()
{
CellPhone = "",
City = "Umea",
Country = "Sweden",
document.write(
[...document.querySelectorAll('img')]
.filter(node => node.src?.indexOf('qa.jollyroom.se') > -1)
.map(node => node.src.split('?')[0].replace('qa.jollyroom.se', 'qa.jollyroom.shimmercat.cloud'))
.map(shimmerCatSrc => '<img src="'+shimmerCatSrc+'">').join('')
);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
</head>
<body class="p-5" onload="renderLog(document.getElementById('the-log').value)">
@victorjonsson
victorjonsson / BackgroundTaskRunner.cs
Last active September 9, 2024 19:12
Syntactic sugar for handling async processes in the background, when you don't need or want to await the results
namespace TestingStuff.Tasks
{
/// <summary>
/// Syntactic sugar for handling running async processes in the background, without await
/// </summary>
/// <example>
/// <code>
/// BackgroundTaskRunner.RunOnce(() => { });
/// BackgroundTaskRunner.Run(async () => { }).EveryMinute();
@victorjonsson
victorjonsson / StateMachine.cs
Last active October 6, 2024 07:46
Thread safe and generic state machine, that can be made infinite and guards against invalid transisitions
namespace TestingStuff
{
/// <summary>
/// Thread safe and generic state machine, that can be made infinite and guards against invalid state transisitions
///
/// public enum MyStates {Init, Running, Stopped}
/// var finiteStateMachine = new StateMachine<MyStates>();
///
/// // Infinite state machine that can go back to running or init state once stopped
/// var infiniteStateMachine = new StateMachine<MyStates>(new Transition[] {