Skip to content

Instantly share code, notes, and snippets.

View jfoshee's full-sized avatar
🗺️
Exploring

Jacob Foshee jfoshee

🗺️
Exploring
View GitHub Profile
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Xunit.Sdk;
namespace Example.Testing
{
/// <summary>
@FreyaHolmer
FreyaHolmer / MathWishlist.cs
Created January 15, 2020 12:07
Things I'd love to have in Unity's Mathf and Vector classes~
public class MathWishlist {
// Mathf
public const float TAU = 6.28318530717959f;
public static float Frac( float x ) => x - Mathf.Floor( x );
public static float Smooth01(float x) => x * x * (3 - 2 * x);
public static float InverseLerpUnclamped( float a, float b, float value) => (value - a) / (b - a);
public static float Remap(float iMin, float iMax, float oMin, float oMax, float value) {
float t = Mathf.InverseLerp(iMin, iMax, value);
return Mathf.Lerp( oMin, oMax, t );
@inikitin
inikitin / .gitattributes
Last active June 14, 2024 10:06
.gitattributes for Unity with case-insensitive Git LFS extension filters
# Unity specific .gitattributes
* text=auto
*.cs diff=csharp text
*.cginc text
*.shader text
# Unity YAML
*.anim -text merge=unityyamlmerge diff
@bpesquet
bpesquet / .gitattributes-lfs-unity
Last active December 7, 2022 22:37
.gitattributes file for LFS with Unity
* text=auto
# Unity files
*.meta -text -merge=unityamlmerge
*.unity -text -merge=unityamlmerge
*.asset -text -merge=unityamlmerge
*.prefab -text -merge=unityamlmerge
# Image formats
*.psd filter=lfs diff=lfs merge=lfs -text
@davidfowl
davidfowl / Global.asax.cs
Last active July 8, 2024 22:23
ASP.NET MVC and ServiceCollection sample
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Microsoft.Extensions.DependencyInjection;
using WebApplication16;
using WebApplication16.Controllers;
@ramonsmits
ramonsmits / RateGate.cs
Last active December 8, 2021 06:55
RateGate originally from Jack Leitch, now async and using Stopwatch.GetTimestamp() instead of Environment.TickCount
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Used to control the rate of some occurrence per unit of time.
/// </summary>
/// <remarks>
@bjcull
bjcull / CustomRequireHttpsFilter.cs
Created May 15, 2015 06:50
An improved HTTPS redirection filter for ASP.NET MVC.
public class CustomRequireHttpsFilter : RequireHttpsAttribute
{
protected override void HandleNonHttpsRequest(AuthorizationContext filterContext)
{
// The base only redirects GET, but we added HEAD as well. This avoids exceptions for bots crawling using HEAD.
// The other requests will throw an exception to ensure the correct verbs are used.
// We fall back to the base method as the mvc exceptions are marked as internal.
if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase)
&& !String.Equals(filterContext.HttpContext.Request.HttpMethod, "HEAD", StringComparison.OrdinalIgnoreCase))
@martinjw
martinjw / SqlExceptionMocker.cs
Last active October 16, 2022 21:02 — forked from timabell/SqlExceptionMocker.cs
Create a SqlException for testing
using System.Data.SqlClient;
using System.Reflection;
namespace HorribleThingsInHere
{
/// <summary>
/// Workaround completely test-unfriendly sql error classes.
/// Copy-paste from http://stackoverflow.com/a/1387030/10245
/// Adjusted with updates in comments
/// Adjusted to not use ctor indexes
@jfoshee
jfoshee / UIViewAnimations.cs
Last active December 14, 2015 01:39
An RAII style class for setting UIView.AnimationsEnabled MonoTouch / Xamarin.iOS
using System;
using MonoTouch.UIKit;
public sealed class UIViewAnimations : IDisposable
{
public UIViewAnimations(bool enabled)
{
_wasEnabled = UIView.AnimationsEnabled;
UIView.AnimationsEnabled = enabled;
}
@mynameismiek
mynameismiek / ViewExtensions.cs
Last active December 14, 2015 00:08 — forked from ChuckSavage/ViewExtensions.cs
Added tap gestures and a way to remove the views from this class when they are disposed. This class registers itself with the default notification center. Simply add NSNotificationCenter.DefaultCenter.PostNotificationName(ViewExtensions.ViewDisposed, View) to your disposal method.
using System.Collections.Generic;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;
namespace iOSLib
{
public static class ViewExtensions
{
public static String ViewDisposed = "ViewExtension_ViewDisposed";