Skip to content

Instantly share code, notes, and snippets.

@nfantone
nfantone / before-shutdown.js
Created September 23, 2020 13:00
Node.js graceful shutdown handler
'use strict';
/**
* @callback BeforeShutdownListener
* @param {string} [signalOrEvent] The exit signal or event name received on the process.
*/
/**
* System signals the app will listen to initiate shutdown.
* @const {string[]}
@JohannesMP
JohannesMP / AttributeDemo.cs
Last active July 16, 2018 17:52
Conveniently extracting data of members on an object that were tagged with a given Attribute, with Reflection caching.
using UnityEngine;
using UnityEditor;
using Utils.Reflection;
using System.Linq;
public class AttributeDemo
{
/// <summary>
/// A quick demo for grabing fields on an object that were tagged with a given Attribute.
/// In this case an ‘Order’ attribute is used to display the tagged fields in a specific order.
@JohannesMP
JohannesMP / 2DLineRectIntersection.md
Last active April 18, 2024 00:53
[C#, Unity3D] An optimized solver for intersection between a Line Segment and a Rect in 2D space with spacial partitioning.

Overview

For a 2D Unity Project, I needed a really efficient way to get the intersection points between a line segment (as defined by two Vector2) and an axis-aligned Rect in 2D space, where the intersection points are returned as a parametric fraction of the length of the original line segment:

Note how when the line intersects the rect, the green line represents the portion inside the rect, and the parametric representation of the point of intersection along the line is displayed

In my use case the vast majority of lines are either completely inside or completely outside the rect, and so I needed an approach that was very efficient in cases where there is guaranteed no intersection and avoids unecessary raycasts when possible.

@LotteMakesStuff
LotteMakesStuff / EditorExtensionMethods.cs
Last active April 28, 2023 09:50
A reimplementation of the logic in the Unity Editor that draws an inspector for a component. We can use this to learn how unity actually draws the inspector. for more info see https://www.patreon.com/posts/16724128
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Reflection;
public static class EditorExtensionMethods
{
// Public reimplmentation of extention methods and helpers that are marked internal in UnityEditor.dll
@JohannesMP
JohannesMP / Windows10RegistryHacks.md
Last active September 13, 2022 03:40
A small collection of Registry hacks for Windows 10 installations

Note: for any folder not found, navigate as far as possible, then create as a new Key

Disable Downloads like Candy Crush, etc.

  • HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\CloudContent
  • Dword DisableWindowsConsumerFeatures set to 1

Disable Lock screen, just show login form

@tony-caffe
tony-caffe / Contract Killer 3.md
Last active March 3, 2024 14:50 — forked from malarkey/Contract Killer 3.md
The latest version of Bytes Unlimited ‘Contract Killer’ for web professionals

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Revised by Bytes Unlimited : Feb 3rd 2020

@LotteMakesStuff
LotteMakesStuff / EditorCoroutineRunner.cs
Last active May 20, 2022 10:21
Run stuff in the editor with all the convenience of co-routines! Add a status UI super easily to see readouts what your long running code is actually doing! nice~ There is a short API demo at the top of the class. This is a prefect companion for my inspector buttons https://gist.github.com/LotteMakesStuff/dd785ff49b2a5048bb60333a6a125187
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
public class EditorCoroutineRunner
{
[MenuItem("Window/Lotte's Coroutine Runner: Demo")]
@LotteMakesStuff
LotteMakesStuff / InspectorButtonsTest.cs
Last active November 2, 2023 21:03
Code running pack! two property drawing scripts that make it super easy to trigger code via buttons in the inspector, and get feedback! [TestButton] draws you little buttons that call a method on your MonoBehaviour, and [ProgressBar] give you a great way to show feedback from long running methods. These are *super* helpful for things like proced…
using UnityEngine;
using System.Collections;
public class InspectorButtonsTest : MonoBehaviour
{
[TestButton("Generate world", "DoProcGen", isActiveInEditor = false)]
[TestButton("Clear world", "ClearWorld", 2, isActiveInEditor = false)]
[ProgressBar(hideWhenZero = true, label = "procGenFeedback")]
public float procgenProgress = -1;
Shader "Name" {
Properties {
name ("display name", Range (min, max)) = number
name ("display name", Float) = number
name ("display name", Int) = number
name ("display name", Color) = (number,number,number,number)
name ("display name", Vector) = (number,number,number,number)
@AndrewRayCode
AndrewRayCode / easing.js
Created March 13, 2016 05:01
ES6 module-ified easing functions, based on https://gist.github.com/gre/1650294
// based on https://gist.github.com/gre/1650294
// no easing, no acceleration
export function linear( t ) {
return t;
}
// accelerating from zero velocity
export function easeInQuad( t ) {
return t * t;