Skip to content

Instantly share code, notes, and snippets.

View rofr's full-sized avatar

Robert Friberg rofr

View GitHub Profile
@rofr
rofr / polymorphism.cs
Created November 17, 2022 09:28
Polymorphic method invocation using dynamic
abstract class MyBase {}
class A : MyBase {}
class B : MyBase {}
void Handle(Mybase m)
{
//todo: deal with recursion that happens for types that lack a handler
Handle((dynamic)m);
}
@rofr
rofr / wtf.cs
Created September 11, 2020 21:39
How is your day going?
private Expression<Func<ActivityHistory, bool>> GetSearchActivityExpression(ActivityHistorySearchParameters searchParameters, ActivityHistorySearchIdLists idLists)
{
return x => ((!searchParameters.DateFrom.HasValue || (DbFunctions.TruncateTime(x.CreatedDate) >= DbFunctions.TruncateTime(searchParameters.DateFrom.Value)))
&& (!searchParameters.DateTo.HasValue || (DbFunctions.TruncateTime(x.CreatedDate) <= DbFunctions.TruncateTime(searchParameters.DateTo.Value)))) &&
((searchParameters.ActionByCustomerId.HasValue && x.ActionByCustomerId.HasValue && searchParameters.ActionByCustomerId.Value == x.ActionByCustomerId.Value) || !searchParameters.ActionByCustomerId.HasValue) && // SystemAdmin are the only one without a CustomerId, they can see everything
((searchParameters.ActionByDepartmentId.HasValue && x.ActionByDepartmentId.HasValue && searchParameters.ActionByDepartmentId.Value == x.ActionByDepartmentId.Value)
@rofr
rofr / tests.cs
Created September 2, 2020 08:49
Programming is hard
[TestMethod]
public void Can_Handle_InTimeSpan()
{
var testtime = DateTime.Now;
var start = testtime.AddHours(-3);
var end = testtime.AddHours(3);
Assert.IsTrue(testtime.InTimeSpan(start, end));
}
@rofr
rofr / AtomicAssignment.cs
Created August 13, 2020 09:29
Is object assignment in .NET atomic?
class AtomicAssignment
{
static object o;
static AtomicAssignment() => o = new object();
public static Update()
{
//is the assignment atomic? or is something like Interlocked.Exchange necessary?
o = new object();
@rofr
rofr / origodb-q-and-a.txt
Created December 15, 2019 18:44
Conversation about OrigoDb
I had an email conversation about OrigoDB with Laura Bressler, a Computer Science 2020 student at Carnegie Melon University. I'm sharing the conversation (with permission) so we can have a public link to cite but also in case anyone else finds the information useful.
December 2019
Robert Friberg
----
My name is Laura, and I'm a student at Carnegie Mellon University. As part of a project for a databases course, I'm updating the dbib.io page for OrigoDB (dbdb.io/db/origodb). However, I wasn't able to find some information in the online documentation. Would you be willing to answer a few questions to ensure that the information in the article is as accurate as possible?
----
@rofr
rofr / day2.js
Created December 2, 2019 23:23
AOC 2019 Day2
function op(mem, ip) {
if (mem[ip] == 99) return -1
let lv = mem[mem[ip+1]]
let rv = mem[mem[ip+2]]
if (mem[ip] == 1) mem[mem[ip+3]] = lv + rv
else if (mem[ip] == 2) mem[mem[ip+3]] = lv * rv
else throw "Invalid op code"
return ip + 4
}
public class MyRegistry : Registry
{
public PosifonIntegrationServicesRegistry()
{
For<DateTimeProvider>().Use(() => DateTimeProvider.Default);
For<DeviceMessageHandler>().Use<DeviceMessageHandler>();
var connectionString = ConfigurationManager
.ConnectionStrings["redacted"]
@rofr
rofr / eventAggregation.cs
Created March 22, 2019 20:47
Event Aggregator DP example
interface IMessageSource
{
event MessageHandler MessagePublished;
}
public delegate void MessageHandler(string message);
class MessageAggregator
{
public event MessageHandler MessagePublished;
<!DOCTYPE html>
<html><head></head>
<body><h1>Privacy Policy for FSQ</h1>
<p>At FSQ Forum, accessible from https://forum.fsq.se, one of our main priorities is the privacy of our visitors. This Privacy Policy document contains types of information that is collected and recorded by FSQ Forum and how we use it.</p>
<p>If you have additional questions or require more information about our Privacy Policy, do not hesitate to contact us through email at robert@devrex.se</p>
<h2>General Data Protection Regulation (GDPR)</h2>
<p>We are a Data Controller of your information.</p>
@rofr
rofr / tutorial.md
Last active April 20, 2018 11:58
Memstate tutorial proposal

Workshop - Memstate tutorial

In this coding intensive workshop we will build an asp.net core mvc application using a memstate backend. Focus will be on memstate specifics such as domain modeling, testing, configuration and integrating with the web application. Bring your Linux, Mac or Windows laptop and code along or sit back and enjoy the ride as Robert talks you through. The materials will be available online so you can continue later at your own pace.

Memstate introduces a radically different approach to managing state. Traditional applications pull in some data from the database, translate to internal types and structures, manipulate, translate back and save any changes made to the database. In a memstate application the data and code exist together in the same process all defined in whatever high-level .NET language you prefer. The memstate runtime will provide transparent persistence and strong consistency guarantees and lets you focus on what matters most.

Contents

  • Introduction - A quick i