Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeff Johnson jjxtra

View GitHub Profile
View Wfp.cs
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Wfp
{
/// PInvoke wrappers for Windows Filtering Platform
public class WfpNativeInterop
{
View ILockProvider.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Polly.Utilities
{
/// <summary>
/// Defines operations for locks used by Polly policies.
@jjxtra
jjxtra / IDistributedCache.cs
Created Dec 23, 2019
New and improved C# IDistributedCacheInterface
View IDistributedCache.cs
/// <summary>
/// Simplified and improved IDistributedCache interface. No more stupid byte arrays. Removal events
/// can also be hooked into allowing removal from a local memory cache if desired.
/// </summary>
public interface IDistributedCache
{
/// <summary>
/// Fires when an item is removed by another machine, parameters are the key and the machine name
/// </summary>
event Action<DistributedCacheRemoveEventArgs>? Removed;
@jjxtra
jjxtra / CloudflareForwardHeaders.cs
Created Sep 10, 2019
Cloudflare IApplicationBuilder forward header and proxy security
View CloudflareForwardHeaders.cs
private static string[] GetStrings(string url)
{
return new WebClient().DownloadString(url).Split('\n').Select(s => s.Trim()).ToArray();
}
private static string[] GetCloudflareIP()
{
try
{
return GetStrings("https://www.cloudflare.com/ips-v4").Union(GetStrings("https://www.cloudflare.com/ips-v6")).ToArray();
@jjxtra
jjxtra / BetterEmbeddedFileProvider.cs
Last active Jul 11, 2019
The Microsoft embedded file provider is buggy and difficult to use, requires arcane project settings and fails in unit tests, especially with class libraries and multiple projects. This embedded file provider has no such problems.
View BetterEmbeddedFileProvider.cs
// MIT license, https://github.com/jjxtra
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using Microsoft.Extensions.FileProviders;
@jjxtra
jjxtra / ComputeOcclusionFromDepth.shader
Created Dec 12, 2018 — forked from aras-p/ComputeOcclusionFromDepth.shader
Unity command buffer that modifies screenspace shadow mask
View ComputeOcclusionFromDepth.shader
Shader "Hidden/ComputeOcclusion"
{
Properties
{
_MainTex ("", 2D) = "white" {}
}
SubShader
{
Pass
{
@jjxtra
jjxtra / HttpContext_RemoteIPAddress.cs
Last active Jul 8, 2020
C# / .NET core: Get Remote IP Address with Proxy / CDN Support
View HttpContext_RemoteIPAddress.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace HttpContext_RemoteIPAddress
@jjxtra
jjxtra / imageRotated.m
Last active Aug 11, 2016
Rotating UIImage from AVCaptureSession [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:]
View imageRotated.m
// this method rotates the UIImage captured by the capture session manager based on the device orientation when the image was captured ([AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];)
- (UIImage*) imageRotated:(UIImage*)image position:(AVCaptureDevicePosition)position orientation:(AVCaptureVideoOrientation)orientation
{
CGAffineTransform transform = CGAffineTransformIdentity;
CGFloat w = image.size.width * image.scale;
CGFloat h = image.size.height * image.scale;
CGFloat dw = w;
CGFloat dh = h;
image = [UIImage imageWithCGImage:image.CGImage scale:1.0f orientation:UIImageOrientationUp];
You can’t perform that action at this time.