Skip to content

Instantly share code, notes, and snippets.

View souzagustavo's full-sized avatar
🎯
Focusing

Gustavo Souza souzagustavo

🎯
Focusing
  • Superdigital
  • São Paulo, BR
View GitHub Profile
@souzagustavo
souzagustavo / TolerantStringEnumConverter.cs
Created December 1, 2021 14:52
Used for custom serialization and deserialization of enum type fields, tolerating parse errors
public class TolerantStringEnumConverter<TEnum> : JsonConverter<TEnum>
{
const string DefaultIndex = "0";
const string DefaultEnumNone = "None";
public override TEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
bool isNullable = IsNullableType(typeToConvert);
Type enumType = GetEnumType(typeToConvert);
public static class StringExtension
{
public static bool IsBase64(this string value)
{
string pattern = @"^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$";
Regex rg = new Regex(pattern);
return rg.IsMatch(value);
}
public static string Base64Decode(this string value, bool returnSameValueIsNotBase64 = false)
@souzagustavo
souzagustavo / SetApiMaxContentLengthUpload.xml
Created August 31, 2018 14:43 — forked from lfgrando/SetApiMaxContentLengthUpload.xml
API Upload Limit Size to 1gb at Web.config. It seems it doesn't work at all IIS's. Looks like not working at IIS Express.
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
using Microsoft.ServiceBus.Messaging;
using System;
using System.Configuration;
namespace RecoverDeadLetterQueuesGeneric
{
class Program
{
static void Main(string[] args)
{
@souzagustavo
souzagustavo / XmlSerializerFromClass.cs
Last active August 31, 2018 15:16
C# - XmlSerialize from class and remove default namespaces
XmlSerializer serializer = new XmlSerializer(typeof(MetadataFile));
MemoryStream memoryStream = new MemoryStream();
//Configuration remove tag omit-xml-declaration
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
XmlWriter writer = XmlWriter.Create(memoryStream, settings);
//Remove namespace
StringWriter stringWriter = new StringWriter();
@souzagustavo
souzagustavo / update_document_in_array.js
Last active August 31, 2018 14:42
MongoDB - Updating document values ​​in a array list
db.movement.insert({
"lot": "00467",
"production": true,
"files": [{
"extension": ".txt",
"name": "test1",
"size": 5811
},
{
"extension": ".csv",