Skip to content

Instantly share code, notes, and snippets.

@rschiefer
rschiefer / CMake Output
Last active April 7, 2022 20:19
SO:FetchContent causes errors: cannot find -lpthreads
[main] Building folder: PROJECT
[build] Starting build
[proc] Executing command: /usr/local/bin/cmake --build /home/username/source/REPO/build --config Debug --target all --
[build] [1/6 16% :: 0.390] Performing update step for 'azure-ctest'
[build] HEAD is now at 5b9bcbf Build with VS2022 (#112)
[build] [2/6 33% :: 0.398] No patch step for 'azure-ctest'
[build] [3/6 50% :: 0.452] Performing configure step for 'azure-ctest'
[build] -- target architecture: x86_64
[build] -- Configuring done
[build] -- Generating done
@rschiefer
rschiefer / HttpClientRequestMessage.cs
Created August 14, 2020 15:58
Retry OData Client calls with Polly in .NET 4.5
public class HttpClientRequestMessage : DataServiceClientRequestMessage
{
private HttpRequestMessage requestMessage;
private readonly HttpClient client;
private readonly HttpClientHandler handler;
private readonly MemoryStream messageStream;
private readonly Dictionary<string, string> contentHeaderValueCache;
private readonly RetryPolicy<HttpResponseMessage> pollyPolicy;
public HttpClientRequestMessage(string actualMethod, RetryPolicy<HttpResponseMessage> pollyPolicy)
@rschiefer
rschiefer / node-app.service
Last active February 8, 2020 01:42
SystemD service file for running node app
Description=My Node app which runs on restart.
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/node /etc/node-app/index.js
Restart=on-failure
RestartSec=10
@rschiefer
rschiefer / CustomSerializer.cs
Created October 18, 2019 13:32
ASP.NET Core WebAPI ODATA - Add Custom Metadata Annotation to Feed
public class CustomSerializerProvider : DefaultODataSerializerProvider
{
public CustomSerializerProvider(IServiceProvider rootContainer)
: base(rootContainer)
{
}
public override ODataEdmTypeSerializer GetEdmTypeSerializer(IEdmTypeReference edmType)
{
if (edmType.IsCollection() && edmType.AsCollection().ElementType().IsEntity())
{
@rschiefer
rschiefer / DST.cs
Last active September 3, 2019 14:04
.NET Date/Time Basics
Console.WriteLine(new DateTimeOffset(new DateTime(2019, 11, 3, 0, 30, 0)));
Console.WriteLine(new DateTimeOffset(new DateTime(2019, 11, 3, 1, 30, 0)));
//> 11/3/2019 12:30:00 AM -05:00
//> 11/3/2019 1:30:00 AM -06:00
Console.WriteLine(new DateTimeOffset(new DateTime(2019, 3, 10, 0, 30, 0)));
Console.WriteLine(new DateTimeOffset(new DateTime(2019, 3, 10, 3, 30, 0)));
//> 3/10/2019 12:30:00 AM -06:00
void Main()
{
var p = new Person { FirstName = "Bill", LastName= "Gates", MiddleName = string.Empty, Age = 62};
Console.WriteLine(Extensions.GetName(() => p.FirstName));
Console.WriteLine(Extensions.GetName(() => p.LastName));
Console.WriteLine(Extensions.GetName(() => p.Age));
Console.WriteLine(Extensions.GetName(() => p.Birthdate));
Console.WriteLine(Extensions.GetName(() => p.Parents));
public static string GetName<T>(this Expression<Func<T>> action)
{
return GetNameFromMemberExpression(action.Body);
}
static string GetNameFromMemberExpression(Expression expression) {
if (expression is MemberExpression) {
return (expression as MemberExpression).Member.Name;
}
else if (expression is UnaryExpression) {
protected JsonResult RemoteJsonResponseForProperty(string property = null)
{
object response;
if (string.IsNullOrWhiteSpace(property))
{
property = System.Web.HttpContext.Current.Request.QueryString.Keys[0];
}
if (ModelState.ContainsKey(property) && ModelState[property].Errors.Any())
[RemoteModelValidator(typeof(MyModel), "ValidateModelFields", "MyController")]
public string State { get; set; }
public class RemoteModelValidatorAttribute : RemoteAttribute
{
public RemoteModelValidatorAttribute(Type modelType, string action, string controller) :base(action, controller)
{
AdditionalFields = string.Join(",", modelType.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).Select(p => p.Name));
}
}