Skip to content

Instantly share code, notes, and snippets.

View hd9's full-sized avatar

Bruno Hildenbrand hd9

View GitHub Profile
@hd9
hd9 / LocalFunctions-Razor-AspNetCore.cshtml
Last active August 29, 2018 20:37
Simplifying Razor logic with C# Local Functions in Asp.Net Core | blog.hildenco.com
@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 November 1, 2018 06:30
GitHub - Integrated Security
@hd9
hd9 / js-pdf-exporter.html
Last active November 1, 2018 06:32
A simple js-pdf exporter
<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 January 24, 2019 17:51
A simple chatroom to demo how simple and elegant Vue.Js is
// 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 February 1, 2019 18:20
AZURE: Migrate data between Sql Server databases using Sql and PolyBase
-- 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 October 18, 2019 17:41
Accessing Entity Framework context on the background on .NET Core
// 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 October 18, 2019 17:42
Accessing Entity Framework context on the background on .NET Core
// 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 October 18, 2019 19:34
Export CSV generated in-memory from an Asp.Net controller
// 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 December 20, 2019 17:54
RavenDB Cloud Operations
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 January 16, 2020 22:27
List installed .NET Framework versions
######################################################################
# 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() {