Skip to content

Instantly share code, notes, and snippets.


mark mr5z

View GitHub Profile
mr5z / date_format.cpp
Last active Jul 1, 2021
Various ways to print date time
View date_format.cpp
static std::string date_format(boost::posix_time::ptime const& datetime) {
using namespace boost;
std::ostringstream ss;
auto output_facet = new boost::posix_time::time_facet();
ss.imbue(std::locale(std::locale::classic(), output_facet));
output_facet->format("%Y-%m-%d %H:%M:%s%Q");
View MonitorController.cs
public class MonitorController : Controller
private readonly IActionDescriptorCollectionProvider _provider;
public MonitorController(IActionDescriptorCollectionProvider provider)
_provider = provider;
mr5z / Observable.cs
Last active May 9, 2021
Property event to observable.
View Observable.cs
class Observable
private object actionCollection = null!;
private MethodInfo? methodInfo;
public ActionCollection<TModel> From<TModel>(TModel target) where TModel : INotifyPropertyChanged
return BuildActionCollection<TModel>();
View LoggingInterceptor.cs
class LoggingInterceptor : HttpClientHandler
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Debug.Log("Request {0}", request.RequestUri.PathAndQuery);
if (request.Content != null)
var contentRequest = await request.Content.ReadAsStringAsync();
mr5z / Configuration.cs
Last active Apr 26, 2021
Scheduled closing of config file
View Configuration.cs
public class Configuration : IConfiguration
private readonly string assemblyResourceFile;
private AutoDisposeJsonDocument? smartJsonDocument;
public Configuration(string assemblyResourceFile)
this.assemblyResourceFile = assemblyResourceFile;
mr5z / AutoDisposeJsonDocument.cs
Created Apr 26, 2021
Scheduled disposable objects to be registered in an IoC container where IDisposable is disallowed.
View AutoDisposeJsonDocument.cs
private void ScheduleDisposeResourceStreams()
_ = Task.Factory.StartNew(async () =>
await Task.Delay(TimeSpan.FromMinutes(1));
// `stream` creation happens right after the invocation of this
// They are in the same thread so no lock needed
jsonStream = null;
mr5z / PleaseHelp.cs
Created Apr 24, 2021
JSON Path to Object
View PleaseHelp.cs
public async Task<T?> GetValue<T>(string path, JsonSerializerOptions? options, CancellationToken cancellationToken)
using var stream = GetStream();
using var jsonDocument = await JsonDocument.ParseAsync(stream, cancellationToken: cancellationToken);
var root = jsonDocument.RootElement;
var jsonPath = JsonPath.Parse(path);
var pathResult = jsonPath.Evaluate(root);
if (pathResult.Error != null)
throw new InvalidOperationException(pathResult.Error);
mr5z / RateLimiter.cs
Last active Apr 21, 2021
View RateLimiter.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
// the rest
public void ConfigureServices(IServiceCollection services)
View productrest.cs
IProductGet : IGet<List<Product>>
IProductPost : IPost<Product, Product>
IProductDelete : IDelete<Product, long>
class ProductRest :
public async Task<List<Product>> Get(CancellationToken cancellationToken)
mr5z / neil.php
Last active Mar 26, 2021
1k lang
View neil.php
#customers {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
#customers td, #customers th {