Skip to content

Instantly share code, notes, and snippets.

View shammelburg's full-sized avatar

Sander Hammelburg shammelburg

View GitHub Profile
@shammelburg
shammelburg / app.component.html
Last active January 28, 2022 18:58
Pagination Component with Angular
<div class="card">
<div class="card-body">
<app-pagination #pagination [collectionSize]="tableContent.length" [pageSize]="10" [firstLastButtons]="true" [maxSize]="2">
</app-pagination>
<table class="table table-sm">
<tbody>
<tr
*ngFor="let t of tableContent | slice : (pagination.currentPage - 1) * pagination.pageSize : pagination.currentPage * pagination.pageSize">
<td>{{ t.name }}</td>
@shammelburg
shammelburg / Dockerfile
Created May 12, 2021 09:58
.devcontainer angular configuration
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/javascript-node/.devcontainer/base.Dockerfile
# [Choice] Node.js version: 16, 14, 12
ARG VARIANT="16-buster"
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
@shammelburg
shammelburg / index.js
Last active March 17, 2021 14:53
SendGrid Inbound Parse with Express
const express = require('express')
const multer = require('multer')
const app = express()
const upload = multer()
app.post('/api/parse', upload.any(), async (req, res) => {
const body = req.body
@shammelburg
shammelburg / auth-middleware.js
Last active December 8, 2021 17:13
express-graphql-api
const jwt = require('jsonwebtoken');
const authMiddleware = (req, res, next) => {
const authHeader = req.get('Authorization')
if (!authHeader) {
req.error = "No authentication header found."
req.isAuth = false
return next()
}
@shammelburg
shammelburg / truncate-all.sql
Created November 9, 2020 09:05
Truncate all tables in Azure SQL Database
DECLARE @SQL varchar(max)
SET @SQL = (SELECT ' TRUNCATE TABLE [' + TABLE_SCHEMA +'].['+ TABLE_NAME + '];'
FROM INFORMATION_SCHEMA.TABLES
ORDER BY TABLE_SCHEMA DESC
FOR XML PATH(''))
-- Print Statement
-- SELECT @SQL
@shammelburg
shammelburg / client-file-download.js
Created January 15, 2020 09:52
JavaScript File Download
function createDownloadLink(str, fileName, contentType) {
var blob = new Blob([str], {
type: "application/json;charset=utf-8"
});
var blobUrl = URL.createObjectURL(blob);
var a = document.createElement("a");
a.href = blobUrl;
a.setAttribute("download", fileName + ".json");
document.body.appendChild(a);
a.click();
@shammelburg
shammelburg / sort-others.js
Created December 5, 2019 10:06
JavaScript Sorting
const asc = (a, b) => a - b
const desc = (a, b) => b - a
array = array.map(a => new Date(a.dob)).sort(desc)//.reverse() // Date
array = array.map(a => a.pocketMoney).sort(asc)//.reverse() // Number
console.log(array)
@shammelburg
shammelburg / remove-last-commit.txt
Created September 22, 2019 19:24
remove last commit from GitHub
git reset --soft HEAD^
git push origin [+branchName(master)] --force
@shammelburg
shammelburg / Startup.cs
Created August 30, 2019 14:20
WebAPI AzureAD Authorization snippets
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthorization(o =>
{
o.AddPolicy("GroupOfUsers", policy => policy.RequireClaim("groups", "3916f0cf-d728-48c4-b18b-e3a29e852c12", "5169a59e-a4c6-44c2-b6ec-dff6910fb2f4"));
});
}
@shammelburg
shammelburg / Startup.cs
Last active August 30, 2019 14:07
Angular WebAPI AzureAD snippets
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(AzureADDefaults.BearerAuthenticationScheme)
.AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins", builder =>