Skip to content

Instantly share code, notes, and snippets.

@menduz
menduz / index.sh
Created October 6, 2020 12:37
Lock pan mac
# install dependencies
brew install pam_yubico
if sc_auth identities | grep PIV --quiet
then
# run lock with sudo
sudo bash ./lockpan-1.sh
else
@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

@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 / url-parser.ts
Last active January 5, 2021 16:03
url-parser-types.ts
/**
* Creates object types compliant with https://github.com/pillarjs/path-to-regexp
*
* ParseUrlParams<"/users/:user_id/:test+"> = { user_id: string, test: string | string[] }
*
* @public
*/
export type ParseUrlParams<State extends string, Memo extends Record<string, any> = {}> = string extends State
? ParseUrlParams.ParserError<"ParseUrlParams got generic string type">
: State extends `${infer _}:${infer Rest}`
@menduz
menduz / readme.md
Last active January 22, 2021 15:23
Unified NFT naming for blockchain based Metaverses

A common way to refer to assets across the metaverse projects

Identifying a blockchain asset is difficult. Wallets, exchanges, tools and other pieces of software need to know the specifics about how to interact with the project's infrastructure to get images or to render content. This proposal shows a temptative solution to the content addressing mechanisms to embed our crypto-art, assets, wearables and avatars into metaverse(s).

URN

@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"
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>
}
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)
}