import requests
import urllib3
# suppress the HTTPS warnings in terminal
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# BEGIN
session = requests.Session()
session.verify = False
url = "https://some.url.com?param1=something¶m2=something"
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
# call the HTTP endpoint
httpResult = session.get(url, headers=headers)
print(httpResult.text)
# some extra details
elapsedSeconds = httpResult.elapsed.total_seconds()
statusCode = httpResult.status_code
Clear NuGet cache
#Clear local nuget cache
C:\tools\nuget.exe locals all -clear
Get user credentials securely in PowerShell
#Get user credentials securely
Try {
$credentials = Get-Credential "$env:username"
}
Catch {
$log += "`n- " + $_.Exception.Message
Output-Result
}
#Get current domain to use for authentication. ADSI = Active Directory
$currentDomain = "LDAP://" + ([ADSI]"").distinguishedName
#Authenticate
$activeDirectoryEntry = New-Object System.DirectoryServices.DirectoryEntry($currentDomain,$credentials.GetNetworkCredential().UserName,$credentials.GetNetworkCredential().Password)
if ($activeDirectoryEntry.name -eq $null)
{
$log += "`n- Failed to authenticate that username and password."
Output-Result
} else {
$log += "`n- Authentication was successful."
}
#Display Results
$log = "Results:"
function Output-Result {
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") > null
$oReturn=[System.Windows.Forms.Messagebox]::Show($log)
Break
}
Add dll to GAC
gacutil.exe -i -f C:\pathtodll\my.dll
Startup.cs example for .NET Core API w/ Swagger
using Swashbuckle.AspNetCore.Swagger;
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore().AddApiExplorer();
services.AddSwaggerGen();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
});
services.AddTransient<ISomeInterface, SomeDependency>();
}
// -----------------
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API");
});
}
app.UseMvc();
}
Resolve dependencies manually in .NET Core
var serviceProvider = services.BuildServiceProvider();
using (var scope = serviceProvider.CreateScope())
{
var app = serviceProvider.GetRequiredService<ISomeInterface>();
app.SomeMethod();
}
Display total lines of code in a git branch
git diff 5cec833a 4ef01d13 --stat
// where the hex are commit id's to differentiate.