Skip to content

Instantly share code, notes, and snippets.

View hd9's full-sized avatar

Bruno Hildenbrand hd9

View GitHub Profile
@hd9
hd9 / EF-AccessBgContext-Step1.cs
Created October 18, 2019 17:41
Accessing Entity Framework context on the background on .NET Core
// Step 1 - Inject IServiceScopeFactory in your controller
// Source: https://blog.hildenco.com/2018/12/accessing-entity-framework-context-on.html
private readonly IServiceScopeFactory serviceScopeFactory;
public ApiController(ApplicationDbContext context, IServiceScopeFactory serviceScopeFactory)
{
this.context = context;
this.serviceScopeFactory = serviceScopeFactory;
}
@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 / 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 / gh-integrated-sec-vuln.md
Created November 1, 2018 06:30
GitHub - Integrated Security
@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 / MassTransit.Scheduling.InMemory.cs
Created May 22, 2018 06:23
MassTransit InMemory Scheduling App using RabbitMQ and .Net Core
using System;
using System.Threading.Tasks;
using MassTransit;
using MassTransit.QuartzIntegration;
namespace MassTransit.InMemory.Scheduling
{
public class ScheduledMessageConsumer :
IConsumer<ScheduledMessage>
@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 / 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,