Skip to content

Instantly share code, notes, and snippets.

View josepot's full-sized avatar

Josep M Sobrepere josepot

View GitHub Profile
@josepot
josepot / SagasRequestSequencePattern.js
Last active December 4, 2016 16:51
Sagas: Request Sequence pattern
// Request sequence pattern
// One of the reasons why I love Redux-Saga is because it allows me
// to handle all the common requests in a consistent manner,
// which reduces the amount of boilerplate and helps me keep things
// DRYer. I usually use a variation of the following utility Saga
// whenever I have to make a normal/promise request:
import {
call,
@josepot
josepot / SagasGlobalErrorHandling.js
Created December 3, 2016 18:26
Sagas: Global Error Handling
// I usually use the request-sequence pattern
// (https://gist.github.com/josepot/cf63578fa81c7dba89ba156e71274537)
// And since 99% of the times that a saga errors it's because something
// went wrong with a request. That's not the only case when a saga can crash.
// The problem is that if there is an unhandled exception is a saga, that
// exception gets propagated all the way up to the rootSaga and the root
// saga will cancell all watchers... Which can be pretty annoying.
// This is one way to avoid such thing from happening:
// This is just a silly example on how to deal with a general exception.
const {map, pipe} = require('ramda');
const operations = {
NOT: a => ~a,
COPY: a => a,
AND: (a, b) => a & b,
OR: (a, b) => a | b,
LSHIFT: (a, b) => a << b,
RSHIFT: (a, b) => a >> b,
};
@josepot
josepot / .eslintrc.js
Last active June 1, 2020 19:26
eslint-config-nodejs-app
'use strict';
module.exports = {
root: true,
env: {
browser: false,
commonjs: false,
es6: true,
node: true,

Extrinsics

The last few weeks I've been prototyping an alternative to polkadot-js/api. My goal is to create a more modular, user-friendly, strongly-typed and light-weight version of polkadot-js/api.

I'm still not sure whether I will be able to accomplish those goals. However, I certanly hope that I will be able to share the knowledge and ideas that I gather during this attempt. That's why I'm creating this gist.

I'm not a technical writer, and I don't have a lot of time to spend on writing this. So, this is meant to be a "brain dump". although, hopefully someone who is good at writting documentation can use this for improving the substrate docs site.

@josepot
josepot / polkadot-extension-backup.ts
Last active July 31, 2023 07:40
create polkadot-js extension backup file
import { fromHex, utf16StrToUtf8Bytes } from "@unstoppablejs/utils";
import { jsonEncrypt } from "@polkadot/util-crypto";
import { createPair, Keyring } from "@polkadot/keyring";
const keyToBytes = (input: string | Uint8Array): Uint8Array =>
typeof input === "string" ? fromHex(input) : input;
export function createBackUpFileContent(
addresses: Array<{
name: string;
@josepot
josepot / replay-provider.ts
Created December 10, 2023 22:54
replay-provider.ts
import { getSyncProvider } from "@polkadot-api/json-rpc-provider-proxy";
import { PathLike } from "fs";
import { readFile } from "fs/promises";
interface QueueNode<T> {
value: T
next?: QueueNode<T>
}
class Queue<T> {
@josepot
josepot / wnd-relay.json
Created March 24, 2024 17:30
Westend V15 metadata
This file has been truncated, but you can view the full file.
{
"lookup": [
{
"id": 0,
"path": ["sp_core", "crypto", "AccountId32"],
"params": [],
"def": {
"tag": "composite",
"value": [
{