Skip to content

Instantly share code, notes, and snippets.

Avatar
🕛
Code

Salvatore dested

🕛
Code
View GitHub Profile
View aws-websocket-trpc.ts
export const socketProcedure = publicProcedure.use(connectionSocket);
export const socketConnectProcedure = socketProcedure.use(connectionSocketConnect);
export const socketDisconnectProcedure = socketProcedure.use(connectionSocketDisconnect);
export const socketRequestProcedure = socketProcedure.use(connectionSocketRequest);
export const socketEventProcedure = socketProcedure.use(connectionSocketEvent);
export const mySocketRouter = router({
connect: socketConnectProcedure.mutation(async ({ctx, input}) => {
// aws connection connect callback
View rapier-crash.ts
function test() {
const rapierEventQueue = new EventQueue(true);
let world = new World({x: 0.0, y: 0, z: 0.0});
// create the kinematic controller
const characterController = createObjectFromDesc(
world,
{
View collider.ts
let result = new Vector3(0, 0, 0);
world.contactPair(myCollider!.handle, collider.handle, (overlap, flipped) => {
const contacts = overlap.numContacts();
if (contacts === 0) {
// strange
return;
}
const contactResults: {direction: Vector3; distance: number}[] = [];
const resultAvg = new Vector3(0, 0, 0);
@dested
dested / awaitLocker.ts
Created November 4, 2021 21:22
Await Locker
View awaitLocker.ts
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) => {
View fancytypes.ts
export type Discriminate<T, TField extends keyof T, TValue extends T[TField]> = T extends {[field in TField]: TValue}
? T
: never;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
type IsUnion<T, U extends T = T> = T extends unknown ? ([U] extends [T] ? false : true) : false;
type IsStringUnion<T> = IsUnion<T> extends true ? (T extends string ? true : false) : false;
View process-assets.js
let glob = require('glob');
let fs = require('fs');
const prettier = require('prettier');
var readJson = (path, cb) => {
fs.readFile(require.resolve(path), (err, data) => {
if (err) cb(err);
else cb(JSON.parse(data));
});
};
View sort-bools.js
const m = [
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 10},
{firstOrder: false, secondOrder: true, thirdOrder: false, rank: 15},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 12},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 16},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 21},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 54},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 13},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 30},
{firstOrder: true, secondOrder: false, thirdOrder: false, rank: 35},
View react-native-with-css-full.tsx
import React from 'react';
import {Image, ScrollView, StyleProp, TextStyle, View, ViewProps, ViewStyle} from 'react-native';
export interface WithCssProps {
classNames?: string[];
parentComponentTree?: ComponentTree;
siblingsLength?: number;
childIndex?: number;
style?: StyleProp<TextStyle>;
}
View react-native-with-css.tsx
import React from 'react';
import {StyleProp, TextStyle, View, ViewProps, ViewStyle} from 'react-native';
export interface WithClassProps {
classNames?: string[];
componentTree?: ComponentTree;
style?: StyleProp<TextStyle>;
}
type ComponentTree = {
View react-native-css-attempt
export class Screen extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {};
}
render() {
return (
<CView classNames={['a']}>
<CView classNames={['b']}>