Skip to content

Instantly share code, notes, and snippets.

function createTuple<T extends any[]>(...args: T) {
return args;
}
function useBoundEffect<TArguments extends any[]>(
effect: (...params: TArguments) => ReturnType<React.EffectCallback>,
getArguments: () => TArguments
) {
const lastArguments = useRef<TArguments | undefined>(undefined);
const lastEffectCleanup = useRef<ReturnType<React.EffectCallback>>(undefined);
useEffect(() => {
const newArguments = getArguments();
function CanvasComponent() {
const canvasRef = useRef<HTMLCanvasElement | null>(null);
useEffect(() => addTouchListener(canvasRef.current), [canvasRef.current]);
return <canvas ref={canvasRef} />;
}
function CanvasComponent() {
const canvasRef = useRef<HTMLCanvasElement | null>(null);
useBoundEffect(addTouchListener, canvasRef.current);
return <canvas ref={canvasRef} />;
}
function addTouchListener(canvas: HTMLCanvasElement | null) {
if (!canvas) {
function useBoundEffect<TArguments extends any[]>(
effect: (...params: TArguments) => ReturnType<React.EffectCallback>,
...params: TArguments
) {
return useEffect(() => effect(...params), params);
}
@amanda-mitchell
amanda-mitchell / rn-cli.config.js
Created June 16, 2017 18:35
React Native configuration to enable loading files with the jsx extension.
module.exports = {
getSourceExts: () => [ 'jsx' ],
};
@amanda-mitchell
amanda-mitchell / partial.Global.asax.cs
Last active September 12, 2022 11:48
Demonstrates how to decode an .ASPXAUTH cookie as generated by the current version of Microsoft's implementation of .NET. You should be able to drop this into the `Global.asax.cs` file of an ASP.NET project and be able to share cookies with code running on Mono. A few notes: (1) This assumes a machine key section that uses SHA1 validation and AE…
public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
{
var machineKeySection = (MachineKeySection) WebConfigurationManager.GetWebApplicationSection("system.web/machineKey");
var cookie = args.Context.Request.Cookies[".ASPXAUTH"];
if (cookie == null || !Regex.IsMatch(cookie.Value, "^([a-fA-F0-9]{2})+$"))
return;
var cookieBytes = ByteUtility.ToBytes(cookie.Value);
int signatureLength;
@amanda-mitchell
amanda-mitchell / x86_64-bug.cs
Created June 16, 2011 04:01
Demonstrates a bug when trying to run the lastest Mono when built for x86_64 on OS X
using System;
class Program
{
static void Main()
{
object obj = new object();
for (int i = 0; i < 2; i++)