Skip to content

Instantly share code, notes, and snippets.

Avatar

Amanda Mitchell amanda-mitchell

View GitHub Profile
View createTuple.ts
function createTuple<T extends any[]>(...args: T) {
return args;
}
View useBoundEffect.ts
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();
View useEffectExample.ts
function CanvasComponent() {
const canvasRef = useRef<HTMLCanvasElement | null>(null);
useEffect(() => addTouchListener(canvasRef.current), [canvasRef.current]);
return <canvas ref={canvasRef} />;
}
View boundEffectExample.ts
function CanvasComponent() {
const canvasRef = useRef<HTMLCanvasElement | null>(null);
useBoundEffect(addTouchListener, canvasRef.current);
return <canvas ref={canvasRef} />;
}
function addTouchListener(canvas: HTMLCanvasElement | null) {
if (!canvas) {
View brokenUseBoundEffect.ts
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 Jun 16, 2017
React Native configuration to enable loading files with the jsx extension.
View rn-cli.config.js
module.exports = {
getSourceExts: () => [ 'jsx' ],
};
@amanda-mitchell
amanda-mitchell / partial.Global.asax.cs
Last active Aug 5, 2020
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…
View partial.Global.asax.cs
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 Jun 16, 2011
Demonstrates a bug when trying to run the lastest Mono when built for x86_64 on OS X
View x86_64-bug.cs
using System;
class Program
{
static void Main()
{
object obj = new object();
for (int i = 0; i < 2; i++)
You can’t perform that action at this time.