Skip to content

Instantly share code, notes, and snippets.

View dested's full-sized avatar
🕛
Code

Salvatore dested

🕛
Code
View GitHub Profile
@dested
dested / awaitLocker.ts
Created November 4, 2021 21:22
Await Locker
export class AwaitLocker {
private static lockerCallbacks: {[key: string]: {callback?: () => void}[]} = {};
static async startLock(key: string) {
if (!AwaitLocker.lockerCallbacks[key]) {
AwaitLocker.lockerCallbacks[key] = [];
}
if (AwaitLocker.lockerCallbacks[key].length > 0) {
let callback: () => void;
const promise = new Promise<void>((res) => {
@acutmore
acutmore / README.md
Last active January 21, 2024 20:30
Emulating a 4-Bit Virtual Machine in (TypeScript\JavaScript) (just Types no Script)

A compile-time 4-Bit Virtual Machine implemented in TypeScript's type system. Capable of running a sample 'FizzBuzz' program.

Syntax emits zero JavaScript.

type RESULT = VM<
  [
    ["push", N_1],         // 1
    ["push", False],       // 2
 ["peek", _], // 3
@DavidWells
DavidWells / aws-lambda-redirect.js
Created June 28, 2018 20:48
How to do a 301 redirect from an AWS lambda function
exports.handler = (event, context, callback) => {
const response = {
statusCode: 301,
headers: {
Location: 'https://google.com',
}
};
return callback(null, response);
}
@christopher4lis
christopher4lis / util-elastic-collision.js
Last active April 23, 2024 15:40
A set of utility functions used to reproduce the effect of elastic collision within HTML5 canvas. Used in the Chris Courses tutorial video on collision detection: https://www.youtube.com/watch?v=789weryntzM
/**
* Rotates coordinate system for velocities
*
* Takes velocities and alters them as if the coordinate system they're on was rotated
*
* @param Object | velocity | The velocity of an individual particle
* @param Float | angle | The angle of collision between two objects in radians
* @return Object | The altered x and y velocities after the coordinate system has been rotated
*/
@evnm
evnm / datadog-iam-stack.yml
Last active July 5, 2022 19:50
A CloudFormation template describing an IAM policy+role pair which grants cross-account read access for monitoring AWS infrastructure in Datadog
---
AWSTemplateFormatVersion: "2010-09-09"
Description: Creates a stack containing an IAM role used to grant
Datadog monitoring access to AWS infrastructures. See
http://docs.datadoghq.com/integrations/aws/#installation for
details.
Parameters:
DatadogAwsAccountId:
@AArnott
AArnott / StaticFuncWithArgExaminer.cs
Created August 21, 2014 21:21
Creating a static method that accepts a first argument supplied by the delegate.
namespace ILExaminer
{
using System;
static class Program
{
internal static Func<T> AsFunc<T>(this T value)
where T : class
{
return new Func<T>(value.Return);
@basarat
basarat / cardinaldirections.js
Last active November 14, 2022 17:44
Snapping an angle to the nearest cardinal direction in javascript
/**
* Given "0-360" returns the nearest cardinal direction "N/NE/E/SE/S/SW/W/NW"
*/
export function getCardinal(angle) {
/**
* Customize by changing the number of directions you have
* We have 8
*/
const degreePerDirection = 360 / 8;