Skip to content

Instantly share code, notes, and snippets.

@menduz
menduz / game.ts
Last active February 3, 2021 14:04
loading kernel modules from Decentraland's SDK scene
executeTask(async () => {
const module = await dcl.loadModule('@decentraland/CommunicationsController')
const rpcResult = await dcl.callRpc(module.rpcHandle, 'send' /* remote method */, [message /* argument list */])
/**
The code avobe is the same as:
import {send} from "@decentraland/CommunicationsController"
@menduz
menduz / db.ts
Last active April 14, 2021 13:25
database ts
// USAGE:
async function getUser(userId: string): Promise<User> {
return getSqlClient(async (SQL, poolClient) => {
// await poolClient.query()
const result = await SQL`SELECT * FROM users WHERE user_id = ${userId}`
return result.rows[0]
})
}
@menduz
menduz / sphere-normals.hlsl
Created May 30, 2020 13:15
Spherical normal encoding
// Encoding:
normalOut=normalize(normalIn.xy)*sqrt(normalIn.z*0.5+0.5);
// Decoding:
normal.z=length2(normalOut.xy)*2- 1;
normal.xy=normalize(normalOut.xy)*sqrt(1- normal.z*normal.z);
@menduz
menduz / transform.dwl
Created October 11, 2017 16:48
DataWeave prime number generator
%dw 2.0
output application/json
import some from dw::core::Arrays
fun isPrime(num: Number): Boolean = do {
// try primes <= 16
if (num <= 16)
(num == 2) or (num == 3) or (num == 5) or (num == 7) or (num == 11) or (num == 13)
else if ( // cull multiples of 2, 3, 5 or 7
@menduz
menduz / dcl.md
Created November 24, 2020 00:55
How to implement your own Decentraland, quick and dirty

Runtime

Decentraland run scenes inside a WebWorker, in an ES5 context including Fetch + WebSockets + dcl object.

Every generated scene should run by itself. That is, a piece of code that can be evaluated by an eval in a proper context. You can compile scenes using Webpack, esbuild, or the Decentraland CLI.

The scenes will interact with the renderer using the dcl object.

dcl object

import { ILoggerComponent, IMetricsComponent } from '@well-known-components/interfaces'
import { validateMetricsDeclaration } from '@well-known-components/metrics'
import PQueue from 'p-queue'
export type ISequecuentialJobExecutorComponent = {
/**
* Runs sequential jobs with a max concurrency of 1 per jobName.
*/
run<T>(jobName: string, fn: () => Promise<T>): Promise<T>
}
@menduz
menduz / guide.md
Last active May 11, 2022 09:19
Frontend React + TypeScript guidelines

Directory Structure

The sources of the project follows this structure:

/src
  /app
    /{domain}
      /actions.ts
 /actions.spec.ts
export function asnEcdsaSignatureParser(signature: Uint8Array): {
r: BigNumber
s: BigNumber
} {
// 30 — type tag indicating SEQUENCE
// 46 — length in octets of value that follows
// 02 — type tag indicating INTEGER
// 21 — length in octets of value that follows
// 00 b15232269023d8c65689f816996f6af874b484347f1e7a537df1230cb1b12d76 R
Use cases:
- Edition mode, needs component schemas and IDs
```
entity0: {
position: { x y z }
}
```
- If the devs define the component number, libraries may have conflicting numbers
const BITS = 32
export function queryBit(data: Uint32Array, index: number) {
const mask = 1 << (index % BITS)
return (data[(index / BITS) | 0] & mask) != 0
}
export function turnOnBit(data: Uint32Array, index: number) {
const mask = 1 << (index % BITS)
return (data[(index / BITS) | 0] |= mask)
}