Skip to content

Instantly share code, notes, and snippets.

@umair-me
umair-me / mock.cs
Last active July 7, 2022 03:00
Mock Configuration.GetSection
Mock<IConfiguration> configuration = new Mock<IConfiguration>();
configuration.Setup(c => c.GetSection(It.IsAny<String>())).Returns(new Mock<IConfigurationSection>().Object);
@umair-me
umair-me / gist:fceeaa222558547c2bff9b587d31d46a
Created July 3, 2019 14:01
GIT merge one repo to another
cd path/to/project-b
git remote add project-a path/to/project-a
git fetch project-a
git merge --allow-unrelated-histories project-a/master # or whichever branch you want to merge
git remote remove project-a
@umair-me
umair-me / HostedService.cs
Created May 24, 2019 08:48 — forked from davidfowl/HostedService.cs
A base class that allows writing a long running background task in ASP.NET Core 2.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
namespace WebApplication24
{
public abstract class HostedService : IHostedService
@umair-me
umair-me / delete _old_records.sql
Created April 11, 2019 12:46
Delete older records by date
--This assumes 24 hours to the minute:
DELETE
MyTableWhere
WHERE
MyColumn < DATEADD(day, -1, GETDATE())
--This assumes yesterday midnight:
DELETE
@umair-me
umair-me / drop_all.sql
Created April 4, 2019 08:55
drop all SP - functions - views - constraints - tables
/* Drop all non-system stored procs */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])
WHILE @name is not null
BEGIN
SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']'
EXEC (@SQL)
ngrok http -host-header=localhost 5000
@umair-me
umair-me / enum_as_string.cs
Created March 30, 2019 12:52
EF Core save enum as string
[Column(TypeName = "nvarchar(24)")]
public SomeEnum Name { get; set; }
@umair-me
umair-me / current_domain_url.cs
Last active March 29, 2019 16:07
Get current domain url
String strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
String strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/");
// OR
Request.Url.GetLeftPart(UriPartial.Authority)
// https://stackoverflow.com/a/10337955/1158845
// OR
@umair-me
umair-me / context.cs
Last active May 21, 2024 15:15
EF Core Set all foreign keys to delete restrict
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
relationship.DeleteBehavior = DeleteBehavior.Restrict;
}
@umair-me
umair-me / javascript_app.js
Last active February 15, 2019 09:56
Creating a javascript file to use in other places
// More details: https://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript
// https://stackoverflow.com/a/7513721
var JsApp = (function() {
function callback() {
alert("done");
};
return {
callbackAlert: callback