This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class EnumExtensions | |
{ | |
public static bool IsObsolete(this Enum value) | |
{ | |
var enumType = value.GetType(); | |
var enumName = enumType.GetEnumName(value); | |
var fieldInfo = enumType.GetField(enumName); | |
return Attribute.IsDefined(fieldInfo, typeof(ObsoleteAttribute)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
void Foo(string[] args) | |
{ | |
using var _ = this.MeasureTimeCurrentMethod(); | |
// lot of operations | |
// prints "Programg.Foo was xxx ms" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createRandomObj(fieldCount, allowNested) { | |
var generatedObj = {}; | |
for(var i = 0; i < fieldCount; i++) { | |
var generatedObjField; | |
switch(randomInt(allowNested ? 6 : 5)) { | |
case 0: | |
generatedObjField = randomInt(1000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CreateRequest | |
{ | |
public string Name { get; set; } | |
public string CreatedBy { get; set; } | |
public JObject Schema { get; set; } | |
} | |
public class CreateRequestValidator : AbstractValidator<CreateRequest> | |
{ | |
private readonly Regex _indexer = new Regex(@"\[\d+\]", RegexOptions.Compiled); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://fiis.com.br/${ticker}11/ | |
var dys = [...document.querySelectorAll("#last-revenues--table tbody tr")] | |
.map(x => x.cells[3].innerHTML.replace("%", '').replace(",",'.')) | |
.map(x => parseFloat(x)); | |
dys.reduce((a, b) => a + b) / dys.length; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Concurrent; | |
using System.Threading.Tasks; | |
using System.Timers; | |
public class CustomCache | |
{ | |
private readonly ConcurrentDictionary<string, Task<(object result, DateTime expirationDate)>> dic = new(); | |
private readonly TimeSpan _threshold; | |
private readonly Timer _timer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open PuppeteerSharp | |
open System.Threading.Tasks | |
open System.Text.Json | |
type Position = { Ticker: string; Qtd: int } | |
let getTaskResult (task: Task<'T>) = task.GetAwaiter().GetResult() | |
let positions = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// controller | |
public async Task DownloadFile([FromQuery] DownloadFileQueryRequest request, CancellationToken cancellationToken) | |
{ | |
var responseObj = await process(request, cancellationToken); | |
HttpContext.Response.ContentType = MediaTypeNames.Application.Octet; | |
HttpContext.Response.StatusCode = StatusCodes.Status200OK; | |
HttpContext.Response.Headers["Access-Control-Expose-Headers"] = "Content-Disposition"; | |
HttpContext.Response.Headers["Content-Disposition"] = new ContentDispositionHeaderValue("attachment") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Buffers; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.Reflection.Emit; | |
using System.Text.Json; | |
using static MoreLinq.Extensions.DistinctByExtension; | |
// adapted from https://gist.github.com/AlbertoMonteiro/f6aa8c92a7d93c9b32b4c2ab19a67def |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Jobs; | |
using System.Buffers; | |
using System.Text; | |
public class Program | |
{ | |
public static async Task Main(string[] args) | |
{ | |
#if DEBUG |