Skip to content

Instantly share code, notes, and snippets.

@arielmoraes
arielmoraes / SkyStrategy.cs
Last active April 24, 2021 03:15
SkyStrategy
private void UpdateStrategy()
{
var newChange = (CurrentPrice - EnterPrice) / EnterPrice;
CurrentPercentChange = newChange * 100;
if (CurrentPercentChange >= MinWinPercentage)
{
if (CurrentPercentChange > MaxWinPercentChange)
{
MaxWinPercentChange = CurrentPercentChange;
@arielmoraes
arielmoraes / DocumentRetriever.cs
Last active March 19, 2019 13:08
Jwt Document Retriever
var authConfig = configuration.GetSection("AuthConfiguration").Get<AuthConfiguration>();
var metadataAddress = authConfig.Authority;
if (!metadataAddress.EndsWith("/", StringComparison.Ordinal))
{
metadataAddress += "/";
}
metadataAddress += ".well-known/openid-configuration";
@arielmoraes
arielmoraes / QueueConsumer.cs
Created January 2, 2019 21:33
Basic Queue Consumer with Threads
public class QueueConsumer<T>
{
readonly BlockingCollection<QueueConsumerItem<T>> queue;
readonly int numberOfThreads;
public QueueConsumer(int numberOfThreads, int capacity)
{
queue = new BlockingCollection<QueueConsumerItem<T>>(capacity);
this.numberOfThreads = numberOfThreads;
}
@arielmoraes
arielmoraes / CustomTypeNameJsonSerializer.cs
Created July 27, 2018 15:26
Rebus Custom Json Serializer for supporting arbitrary names to type mappings
using Newtonsoft.Json;
using Rebus.Messages;
using Rebus.Serialization;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Rebus.Extensions;
using System.Linq;
using System.Collections.Concurrent;
@arielmoraes
arielmoraes / ActionContextExtensions.cs
Last active November 22, 2017 21:37
Validate null complex type models when query string is empty
public static class ActionContextExtensions
{
public static void ValidateNullModel(this HttpActionContext actionContext)
{
var notNullParametersDescriptors = actionContext.ActionDescriptor.GetParameters()
.Where(p => p.GetCustomAttributes<NotNullAttribute>().Count > 0);
foreach (var pd in notNullParametersDescriptors)
{
var model = actionContext.ActionArguments[pd.ParameterName];
@arielmoraes
arielmoraes / Helper.cs
Last active August 29, 2015 14:15
Bootstrap ASP.NET MVC Switch
public static MvcHtmlString SwitchFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string trueString, string falseString)
{
if (expression == null)
throw new ArgumentNullException("expression");
var body = expression.Body as MemberExpression;
if (body == null)
throw new ArgumentNullException("expression");
bool truthValue = (bool)ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData).Model;
@arielmoraes
arielmoraes / desafio001.c
Last active August 29, 2015 14:13
Desafio001 do Ciência da Computação depressão - Cifra de César
// Ariel Moraes
// https://www.linkedin.com/in/arielmoraes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int mathmod(int a, int b) {
return (abs(a * b) + a) % b;