Skip to content

Instantly share code, notes, and snippets.

Avatar

Bruno Hildenbrand hd9

View GitHub Profile
@hd9
hd9 / LocalFunctions-Razor-AspNetCore.cshtml
Last active Aug 29, 2018
Simplifying Razor logic with C# Local Functions in Asp.Net Core | blog.hildenco.com
View LocalFunctions-Razor-AspNetCore.cshtml
@using Microsoft.AspNetCore.Mvc.Controllers
@{
var controllerName = ((ControllerActionDescriptor)ViewContext.ActionDescriptor).ControllerName;
string GetClass(string controller)
{
return $"nav-link { (controllerName == controller ? "active admin" : "" ) }";
}
}
<nav class="navbar navbar-expand-lg navbar-light bg-light">
@hd9
hd9 / gh-integrated-sec-vuln.md
Created Nov 1, 2018
GitHub - Integrated Security
View gh-integrated-sec-vuln.md
@hd9
hd9 / js-pdf-exporter.html
Last active Nov 1, 2018
A simple js-pdf exporter
View js-pdf-exporter.html
<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js"></script>
<script>
$(document).ready(function(){
$('#cmd').click(function () {
doc.fromHTML($('#content').html(), 15, 15, {
'width': 170,
@hd9
hd9 / Vue-ChatRoom.js
Created Jan 24, 2019
A simple chatroom to demo how simple and elegant Vue.Js is
View Vue-ChatRoom.js
// Vue-ChatRoom.js: A simple chatroom to demo how simple and elegant Vue.Js is
// By: Bruno Hildenbrand
// Source: https://github.com/hd9/vue-chatroom
// blog post available at: blog.hildenco.com
const app = new Vue({
el: '#chat',
data: {
name: 'Bruno',
msg: '',
@hd9
hd9 / Azure-migrate-data-between-servers.sql
Created Feb 1, 2019
AZURE: Migrate data between Sql Server databases using Sql and PolyBase
View Azure-migrate-data-between-servers.sql
-- Script to migrate data between Azure Databases
-- Author: Bruno Hildenbrand (https://github.com/hd9)
-- Full post detailed here: https://blog.hildenco.com
-- Note: replace everything between <> with your own configuration
print '--- STARTING MIGRATION ---'
-- create master key
print 'Creating master key...'
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<super-strong-password>';
@hd9
hd9 / EF-AccessBgContext-Step2.cs
Created Oct 18, 2019
Accessing Entity Framework context on the background on .NET Core
View EF-AccessBgContext-Step2.cs
// Step 2 - Pass it to your background thread
// Source: https://blog.hildenco.com/2018/12/accessing-entity-framework-context-on.html
public async Task<IActionResult> TestAsyncCall(string id)
{
Task.Run(() => BgTask(id, serviceScopeFactory));
return Ok("Thanks, your code will be executed!");
}
@hd9
hd9 / EF-AccessBgContext-Step3.cs
Created Oct 18, 2019
Accessing Entity Framework context on the background on .NET Core
View EF-AccessBgContext-Step3.cs
// Step 3 - Resolve the service from the background task
// Source: https://blog.hildenco.com/2018/12/accessing-entity-framework-context-on.html
private async Task BgTask(string id, IServiceScopeFactory serviceScopeFactory)
{
await Task.Delay(30000);
using (var scope = serviceScopeFactory.CreateScope())
{
var dbContext = scope.ServiceProvider.GetService<ApplicationDbContext>();
@hd9
hd9 / export-csv-aspnet.cs
Last active Oct 18, 2019
Export CSV generated in-memory from an Asp.Net controller
View export-csv-aspnet.cs
// Export CSV generated in-memory from an Asp.Net controller
// Source: https://blog.hildenco.com/2018/03/exporting-csv-generated-in-memory-in.html
public class MyController : Controller
{
public void DownloadReport(string id)
{
var rptLines = new List<CsvLine>();
var count = 0;
@hd9
hd9 / RavenDBCloud-DbOperations.cs
Created Dec 20, 2019
RavenDB Cloud Operations
View RavenDBCloud-DbOperations.cs
using Raven.Client.Documents;
using Raven.Client.Documents.Operations.Backups;
using Raven.Client.Documents.Operations.ETL.SQL;
using Raven.Client.Documents.Smuggler;
using Raven.Client.ServerWide;
using Raven.Client.ServerWide.Operations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
@hd9
hd9 / list-dotnet-frameworks.ps1
Last active Jan 16, 2020
List installed .NET Framework versions
View list-dotnet-frameworks.ps1
######################################################################
# list-dotnet-frameworks.ps1 | List installed .NET Framework versions
######################################################################
# Source: https://blog.hildenco.com/2020/01/determining-installed-net-framework.html
# It may be required to run Powershell with the following command line:
# Powershell.exe -executionpolicy remotesigned -File
function Get-Installed-Framework-Versions() {