Skip to content

Instantly share code, notes, and snippets.

View benmccallum's full-sized avatar

Ben McCallum benmccallum

View GitHub Profile
@PascalSenn
PascalSenn / MultipartRequestMiddleware
Last active April 7, 2024 20:27
MultiPartRquestMiddlware made with ❤️ by https://github.com/acelot
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
@PascalSenn
PascalSenn / auth-apollo-how-to.md
Last active March 31, 2023 12:20
Authentication Apollo Client - How To

The problem with authentication of web sockets is that you can only authenticate a http request once against a authentication scheme. After that the authentication is cached and will always yield the same result.

A web socket connection starts over HTTP. A HTTP request with the Upgrade header is send to the back end. This request is then "upgraded" into a web socket that runs over the web socket pipeline. The main issue with web sockets is that you cannot set additional headers with this initial HTTP header. Therefore the authentication will fail and the request will be unauthenticated. The HTTP context of the initial request will last as long as the web socket connection is running.

The trick we do is that we add a stub authentication scheme:

@davidfowl
davidfowl / PeekJsonToken.cs
Last active February 29, 2024 17:47
Peeking at a JSON token using a PipeReader in the ASP.NET Core request pipeline
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO.Pipelines;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@guysmoilov
guysmoilov / Git pre-commit hook for large files.md
Last active February 14, 2024 23:46
Git pre-commit hook for large files

Git pre-commit hook for large files

This hook warns you before you accidentally commit large files to git. It's very hard to reverse such an accidental commit, so it's better to prevent it in advance.

Since you will likely want this script to run in all your git repos, a script is attached to add this hook to all git repos you create / clone in the future.

Of course, you can just download it directly to the hooks in an existing git repo.

If you find this script useful, you might enjoy our more heavy-duty project FastDS, which aims to make it easier to work with versioning in data science projects.

@rajbos
rajbos / dotnetToolInstallCheck.ps1
Last active May 17, 2024 01:59
Use dotnet tool to find out if a specific tool is installed on an environment
# Preface:
# dotnet tool install -g will return an error code when the tool is already installed in the system (at the same location)
# adding a test like below, will prevent the error
# this is mostly needed in a CI/CD environment where you don't want to break your pipeline if the tool was installed already.
# find if stryker is installed
$list = (dotnet tool list -g)
# echo the list
# $list
Param(
[string]$sourceRootPath
)
$paths=New-Object System.Collections.Generic.List[System.Object]
$paths.Add("C:\Program Files\nodejs")
$paths.Add("${HOME}\.dotnet\NuGetFallbackFolder")
$paths.Add("${HOME}\.nuget\packages")
$paths.Add("${HOME}\AppData\Local\Yarn")
$paths.Add("${HOME}\AppData\Roaming\npm")
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active June 29, 2024 16:03
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@patrickperrone
patrickperrone / ChangeSearchProvider.ps1
Last active November 2, 2017 11:00
This PowerShell script will change your Sitecore instance search provider from Lucene to Solr or vice versa.
function Get-ConfigFileFilter([string]$providerName)
{
return "^.*\." + $providerName + "\.(.+\.)?config.*$"
}
function Set-SCSearchProvider
{
$rootPath = Read-Host "What is the path of your Sitecore instance's website folder?";
$choice = Read-Host "(L)ucene or (S)olr?";
@iki
iki / README.md
Last active December 12, 2021 08:50 — forked from othiym23/npm-upgrade-bleeding.sh
Update global top level npm packages

Update global top level npm packages

Problem

npm update -g updates all global packages and their dependencies, see npm/npm#6247.

Solution

  1. Either use the shell script or windows batch here instead.
@dmitrye
dmitrye / validate_credit_card.js
Last active February 1, 2018 16:42 — forked from DiegoSalazar/validate_credit_card.js
JavaScript Luhn validator method. Modifications made here include support for non-numeric characters in the value being cleaned up instead of rejecting the value. Also, cleaned up a duplicate variable and added identity check at the end instead of equality check.
// takes the form field value and returns true on valid number
function valid_credit_card(value) {
// The Luhn Algorithm. It's so pretty.
var nCheck = 0, bEven = false;
//this will remove all non-numeric characters and validate against remaining code.
//therefore this now supports 4111-1111-1111-1111 patterns as an example
value = value.replace(/\D/g, "");
for (var n = value.length - 1; n >= 0; n--) {