Skip to content

Instantly share code, notes, and snippets.

View josephwambura's full-sized avatar
👨‍💻
I may be slow to respond.

Joseph Wambura josephwambura

👨‍💻
I may be slow to respond.
View GitHub Profile
@josephwambura
josephwambura / SqlDateBetween.sql
Created February 10, 2023 10:26
Sql Date Between
declare @startDate nvarchar(10);
declare @endDate nvarchar(10);
declare @daysFromNowToStart Int
declare @daysFromEndToNow Int
set @startDate = '2022-10-01';
set @endDate = '2023-02-10';
set @daysFromNowToStart = DATEDIFF(DAY, GETUTCDATE(), @startDate);
set @daysFromEndToNow = DATEDIFF(DAY, @endDate, GETUTCDATE());
POST https://auth.example.com/connect/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 82
client_id=Bazu&scope=PyPay_api
###
GET https://sandboxapi.example.com/v1/transactionroutes/assignedroutes HTTP/1.1
Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjY5QzFDNjNCQ0Q0QjU4OEFDOUVFRjlBNDc5RDg1ODUxIiwidHlwIjoiYXQrand0In0.eyJuYmYiOjE2NzUwODQ1MzEsImV4cCI6MTY3NTA4ODEzMSwiaXNzIjoiaHR0cHM6Ly9hdXRoLnphbXVwYXkuY29tIiwiYXVkIjoiUHlQYXlfYXBpIiwiY2xpZW50X2lkIjoiQmF6dSIsImNsaWVudF9jdXN0b21lcl9pZCI6IjNhMjYwNTNhLWUxOWEtZWQxMS1hZDFlLTBlZTAwZTg5N2Y1MiIsImNsaWVudF9jdXN0b21lcl90eXBlIjoiTWVyY2hhbnQiLCJjbGllbnRfY3VzdG9tZXJfY2F0ZWdvcnkiOiJTeXN0ZW1NYW5hZ2VkIiwiY2xpZW50X3dlYnNpdGUiOiJiYXp1LmNvbSIsImp0aSI6IjQwRjlCMDVGQTM3RjMzOENFNkVFNjlCQUQ4RUIyQUQwIiwiaWF0IjoxNjc1MDg0NTMxLCJzY29wZSI6WyJQeVBheV9hcGkiXX0.i3qBOKFiD2afDIQ41pO-ZHQASYDbKGNZSft9VfoN-GtH1OV9mcSu1qe4f4JTrGc7WZwVgd3U_E46kYRTj0GhjkVDRfGwNj5MQomKjKetcCnezjNka43hmghH6cEKjh8umHp9wtLdOEM9Cwv1LDjG71uHbTFpADBhftOMpMdHqM7r37j3P3LepIrOFIAC715VrBFCpePL
WITH weeks
AS (
SELECT 1 AS n
UNION ALL
SELECT n + 1 FROM weeks WHERE n < 10
),
venues AS (
SELECT 1 AS v
UNION ALL
@josephwambura
josephwambura / dynamic-sql-like-linq-orderby-extension.md
Last active January 6, 2023 11:46
Dynamic SQL-like Linq OrderBy Extension

Dynamic SQL-like Linq OrderBy Extension

public static class OrderByHelper
{
    public static IEnumerable<T> OrderBy<T>(this IEnumerable<T> enumerable, string orderBy)
    {
        return enumerable.AsQueryable().OrderBy(orderBy).AsEnumerable();
    }
@josephwambura
josephwambura / Navbar Item IsSelected.md
Last active November 25, 2022 17:46
.Net helper to mark Navigation navbar li item as active (MVC and Pages)

How to set navbar item as active when user selects it, in C#

public static class HtmlHelpers
{
    public static string IsSelected(this IHtmlHelper html, string? controller = null, string? action = null, string? page = null, string? pageController = null, string? cssClass = null)
    {
        if (string.IsNullOrWhiteSpace(cssClass))
            cssClass = "active";

// MVC controllers and actions

@josephwambura
josephwambura / Javascript 101.md
Last active November 9, 2022 10:25
Javascript 101

JavaScript 101 QAs

  1. What method returns a promise after a group of promises have either been fulfilled or rejected?

     Promise.allSettled()
    
  2. Which function correctly demonstrates the use of the rest parameter (foo), allowing the function to accept an infinite number of arguments, beyond the required parameters a and b?

     function bar(a, b, ...foo) {
    

foo.map(() => ())

@josephwambura
josephwambura / CSharpInterviewQA.md
Last active June 18, 2024 07:30
C# interview questions and answers

10 advanced C# interview questions and answers for 2022

Do you wish to become a successful senior C# developer? Or, do you want to get the best C# senior developer on your team? My carefully curated list of advanced C# interview questions and answers should serve you as a very reliable guide.

C# interview questions and answers

  1. How do you do Exception Handling in C#?
@josephwambura
josephwambura / HelpfulSqlScripts.md
Last active November 2, 2022 19:10
Helpful Sql Scripts
select count(*) as [Count], Avg(Amount) as [Average], Sum(Amount)/2 as [Sum divided by 2] from dbo_OrderLineItems where OrderId in 
(
	select Id from dbo_Orders where CustomerId in 
	(
	'GUIDGUID-GUID-GUID-GUID-GUIDGUID',
	'GUIDGUID-GUID-GUID-GUID-GUIDGUID',
	'GUIDGUID-GUID-GUID-GUID-GUIDGUID'
	) and (Cast(CreatedDate as date) between '01 June 2022' and '31 July 2022')
)
@josephwambura
josephwambura / EasilyCleanBinObjFolders.md
Last active December 16, 2023 21:43
Easily Clean Bin/Obj Folders from Visual Studio solution using Powershell

Boot up powershell in admin mode and **_navigate to the root of your repos.

THIS IS VERY IMPORTANT: DO NOT RUN THIS COMMAND IN A SYSTEM FOLDER OR TERRIBLE THINGS WILL HAPPEN.

I am serious about this, make sure you do this in a sub folder. Mine is F:\source\repos

Then run this command:

Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }