Landan
Landan
CC#
Created by Hackswell [SIGS3GV] on 4/25/2024 in #help
Modernizing double loops in C#?
Generate vectors with a generator:
public static IEnumerable<Vector2> ToAreaVectorSetByRadius(this int radius){
Vector2 x1Vector= new (1, 0)
Vector2 y1Vector= new (0,1)
Vector2 theVector = new Vector(-radius, -radius);
for (int dx = -radius; dx < radius; dx++){
for (int dy = -radius; dy <= radius; dy++){
yield return theVector;
theVector = theVector + y1Vector;
}
theVector = theVector + x1Vector;
}
}

//{ ...
Dictionary<Vector2, object> theDictionary = new (){
{ new (){X=2, Y=3}, "what"},
{ new (){X=3, Y=3}, "nothing"}};

IEnumerable<Vector2> theVectorsByRadius = 5.ToAreaVectorSetByRadius();

var theNewSet = theVectors.AsParallel().Where(v => theDictionary.TryGetValue(v, out var item) && item is {}).ToArray();

Console.WriteLine(string.Join(',', theNewSet.AsEnumerable()));

// instead of mutating your object list, I made a separate collection. You can do with it as you wish.
//}
public static IEnumerable<Vector2> ToAreaVectorSetByRadius(this int radius){
Vector2 x1Vector= new (1, 0)
Vector2 y1Vector= new (0,1)
Vector2 theVector = new Vector(-radius, -radius);
for (int dx = -radius; dx < radius; dx++){
for (int dy = -radius; dy <= radius; dy++){
yield return theVector;
theVector = theVector + y1Vector;
}
theVector = theVector + x1Vector;
}
}

//{ ...
Dictionary<Vector2, object> theDictionary = new (){
{ new (){X=2, Y=3}, "what"},
{ new (){X=3, Y=3}, "nothing"}};

IEnumerable<Vector2> theVectorsByRadius = 5.ToAreaVectorSetByRadius();

var theNewSet = theVectors.AsParallel().Where(v => theDictionary.TryGetValue(v, out var item) && item is {}).ToArray();

Console.WriteLine(string.Join(',', theNewSet.AsEnumerable()));

// instead of mutating your object list, I made a separate collection. You can do with it as you wish.
//}
There you go. Linq Golfing.
18 replies
CC#
Created by vl4do on 5/13/2023 in #help
BlackJack method
switch(variableToCheck)
{
case {Card1: "A", Card2:"F"} or {Card1: "F", Card2: "A"}: break;
default: //check other scenarios...
break;
}
switch(variableToCheck)
{
case {Card1: "A", Card2:"F"} or {Card1: "F", Card2: "A"}: break;
default: //check other scenarios...
break;
}
could be
case Pattern<TypeArg> BlackJackCase { Card1: "A", Card2: "F" } or {Card1: "F", Card2: "A"};

switch(variableToCheck)
{
case BlackJackCase: break;
default : break;
}
case Pattern<TypeArg> BlackJackCase { Card1: "A", Card2: "F" } or {Card1: "F", Card2: "A"};

switch(variableToCheck)
{
case BlackJackCase: break;
default : break;
}
73 replies
CC#
Created by vl4do on 5/13/2023 in #help
BlackJack method
Great case for a feature release of variable pattern matches. If only 🥺
73 replies
CC#
Created by ezoll on 3/28/2023 in #help
✅ How can I make VSCode auto add semicolons to statements on save?
Ooh ooh, unterminated lines should be a certain tinge of color!
10 replies
CC#
Created by ezoll on 3/28/2023 in #help
✅ How can I make VSCode auto add semicolons to statements on save?
Imagine hitting enter, and if the end of the line lacks a semicolon, it deletes the line 💀
10 replies
CC#
Created by maria 🌟 on 2/26/2023 in #help
❔ Net 7 How to output one exe without dlls
I used chatgpt to create a bash script to pipe tar archives without persisting them on the filesystem, and then grabbed the artifact I wanted out of it. Maybe you could try that (I dont have the code available to me atm)
174 replies
CC#
Created by antimatter8189 on 2/26/2023 in #help
❔ How to use the Azure function I built to retrieve the connection string? cant puzzle the pieces.
https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-aspnet-core-app?tabs=core6x It has code examples on setting up your startup.cs. I dont remember if I used DI in my azure functions so I cant give an azure function example.
4 replies
CC#
Created by shadi on 12/11/2022 in #help
❔ Social media profiles hidden information?
Model.CouldBe(emailSource=>emailSource as emailSourceDTO);
Model.CouldBe(emailSource=>emailSource as emailSourceDTO);
Model.CouldBe<emailSourceDTO>();
Model.CouldBe<emailSourceDTO>();
Model.CouldBe(typeof(emailSourceDTO));
Model.CouldBe(typeof(emailSourceDTO));
14 replies
CC#
Created by shadi on 12/11/2022 in #help
❔ Social media profiles hidden information?
You could setup a pattern for your dto validation like:
Model.CouldBe(emailSource=>emailSource.tryGetValue(emailSourceKey, out var emailSourceObject) ? emailSourceObject as emailSourceDTO : default)
.CouldBe(addressSource...)
.CouldBe(infoSource...)
Model.CouldBe(emailSource=>emailSource.tryGetValue(emailSourceKey, out var emailSourceObject) ? emailSourceObject as emailSourceDTO : default)
.CouldBe(addressSource...)
.CouldBe(infoSource...)
Your parameter for the Func would be an IDictionary, or you might be able to use, as, to try casting it to your dto Make a special attribute for model validation, and voila
14 replies
CC#
Created by Gladiator on 11/10/2022 in #help
❔ Using concurrent collections to add or remove elements for in-memory collections (server)?
It would be an out of band sort of system, not confined to your single dotnet process.
13 replies
CC#
Created by Gladiator on 11/10/2022 in #help
❔ Using concurrent collections to add or remove elements for in-memory collections (server)?
No, CQRS.
13 replies
CC#
Created by Gladiator on 11/10/2022 in #help
❔ Using concurrent collections to add or remove elements for in-memory collections (server)?
In-memory may indicate they have an implementation for quick lookups or something for low latency solutions
13 replies
CC#
Created by Gladiator on 11/10/2022 in #help
❔ Using concurrent collections to add or remove elements for in-memory collections (server)?
If your usecase is open to allow for more than in-memory context, you might look into using an external source of truth behind an event queue to handle operations which could execute out of sync, then pull the absolute context where you need it.
13 replies
CC#
Created by Gladiator on 11/10/2022 in #help
❔ Using concurrent collections to add or remove elements for in-memory collections (server)?
You can use a hashset. Or a concurrent bag
13 replies