Select Multiple Properties using Linq - Fun C# Code #3
C#'s Linq is an simply amazing. However, as far as I know, there is no built-in ability to select multiple fields (of the same type) and return them, so here you go
My Notes on Software
C#'s Linq is an simply amazing. However, as far as I know, there is no built-in ability to select multiple fields (of the same type) and return them, so here you go
Google has developed a tool called PageSpeed. It highlighted couple of quick wins I could do to improve website's loading time. Website loading times are one of the most deceptive metrics to measure during development. Website development is frequently done on a local machine when download times are neligiable. It is only once the website ... Read more ASP.NET Core - Optimisation Hacks
Recently, I was asked to write a 'real-time' calculator and the output value was to be stored in Redis. For legacy reasons, it also had to be stored in the database though, only the latest value had to be kept. As the calculator was spewing values, they were stored in a ConcurrentDictionary. When the timer ... Read more ConcurrentDictionary - Get Snapshot and Clear - Fun C# Code #2
I came across this code when reading 'Concurrency in C# Cookbook' by Stephen Cleary. Did you know you can have an infinite Task.Delay without loops?
1 |
await Task.Delay(Timeout.InfiniteTimeSpan, ...) |
Obviously, there isn't much point in spinning a task that litterally will do nothing. You can use a CancellationToken to cancel the task.
1 2 |
using var cts = new CancellationTokenSource(); await Task.Delay(Timeout.InfiniteTimeSpan, cts.Token); |
No point. It's just one ... Read more Fun C# Code #1 - Infinite Delay (until cancelled)
Semantic UI appears to be no longer under active development. However, thanks to the Open Source community it is still getting deveoped by under a different name - Fomantic UI. I never had the need customise Semantic-UI. I only ever used it within internal apps and it worked well. Recently, I decided to use it ... Read more Customise Semantic-UI
Servers US tend to be considerably cheaper in US than in Europe. This has its drawbacks, not least of all, your application will be reporting wired times for various events. However, this is something that can be easily fixed on Ubuntu servers. Our goal is to change date from EST to GMT:
1 2 3 4 5 6 |
#from root@Polaris:~# date Mon Dec 31 06:15:21 EST 2018 #to root@Polaris:~# date Mon Dec 31 11:18:36 GMT 2018 |
I am ... Read more How to change time-zone on Ubuntu servers?
There are numerous ways in which one can add active class to a link. One way is to use if statements to do so. Modern JS frameworks such as Angular, React and VueJS support route-linkĀ designed to manage routes in the application. The same effect can also be achieved with jQuery. It is certainly a ... Read more How to select the active links using jQuery
Using TeamCity, Bitbucket and msdeploy, I have been able to develop a satisfactory CI process for my web apps. However, I found that whenever an application was deployed to production, the user sessions would expire. Initially, it was not a big issue, but as the number of users grew so did the issue. We want ... Read more Maintaining user session on msdeploy in ASP.NET Core (in SQL Server)
Recently, I have been building a large database for the new House-Buddy project. The site uses a huge collection of data to identify the sweet-spots around a particular location. The site is hosted on a shared hosting which in theory had unlimited DB storage, but after they noticed the size of the database has grown ... Read more Dealing with SQL Server Space - Part 1
This is a ready made example of how to add a scheduled job to your ASP.NET core web application:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
public class YourJob : IJob { public static async void Start() { IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler(); await scheduler.Start(); IJobDetail job = JobBuilder.Create<YourJob>().Build(); ITrigger trigger = TriggerBuilder.Create() .WithDailyTimeIntervalSchedule(s =>s.WithIntervalInSeconds(10)) .StartNow() .Build(); await scheduler.ScheduleJob(job, trigger); } Task IJob.Execute(IJobExecutionContext context) { return Task.Run(() => { Program.Counter++; }); } } |
In your Program.cs
1 2 3 4 5 6 7 8 9 |
public static int Counter = 0; public static void Main(string[] args) { var host = BuildWebHost(args); YourJob.Start(); host.Run(); } |