Skip to content

Instantly share code, notes, and snippets.

View fersilva16's full-sized avatar
🦀

Fernando Silva fersilva16

🦀
View GitHub Profile
@fersilva16
fersilva16 / nixos-setup.sh
Created April 10, 2022 04:54
My NixOS setup
sudo -i
loadkeys br-abnt2
setfont ter-v18n
ifconfig
wpa_supplicant -B -i INTERFACE -c <(wpa_passphrase 'SSID' 'PASS')
curl google.com
@fersilva16
fersilva16 / vite.config.ts
Created March 28, 2022 22:36
Vite with polyfills for Buffer and global
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import inject from '@rollup/plugin-inject';
export default defineConfig(({ mode }) => {
return {
plugins: [react()],
build:
mode === 'production'
? {
@fersilva16
fersilva16 / virtualbox-nixos-setup.bash
Created March 12, 2022 21:17
NixoOS setup on VirtualBox
sudo -i
loadkeys br-abnt2 # Setting the keyboard layout to Brazilian ABNT2
setfont ter-v32n # Increase font
curl google.com # Check internet connection
parted /dev/sda -- mklabel gpt # use GPT partition table
parted /dev/sda -- mkpart primary 512MiB 100% # 16GiB partition for LVM and 512MiB boot partition
@fersilva16
fersilva16 / axiosAuthInterceptor.ts
Created February 22, 2022 17:25
Auth interceptor to automatically request for new token when the response returns 401
const api = axios.create({
baseURL: apiBaseURL,
});
api.interceptors.request.use(async (config) => {
if (!getToken()) await auth();
return {
...config,
@fersilva16
fersilva16 / GraphQLFields.ts
Created February 10, 2022 22:31
Get the GraphQL fields type from a type
export type GraphQLFields<T, C> = {
[K in keyof T]: Omit<GraphQLFieldConfig<T, C>, 'type' | 'resolve'> & {
type: GraphQLScalarTypeConfig<T[K], T[K]>,
resolve?: GraphQLFieldResolver<T, C, any, T[K]>
};
};
@fersilva16
fersilva16 / package.json
Created February 7, 2022 15:23
Run a TypeScript project using ESBuild and TSUP
{
"scripts": {
"build": "tsup",
"dev": "yarn build --onSuccess \"yarn start\"",
"dev:watch": "yarn dev --watch",
"start": "node dist/index.js",
},
"devDependencies": {
"tsup": "^5.11.13",
"typescript": "4.5.5"
@fersilva16
fersilva16 / findByOwnerBenchmark.js
Last active February 5, 2022 16:25
Benchmark of Metaplex's Metadata's findByOwner method
const web3 = require('@solana/web3.js');
const { Metadata } = require('./token-metadata/js/dist/src/mpl-token-metadata');
const connection = new web3.Connection(web3.clusterApiUrl('devnet'), 'confirmed');
const wallet = new web3.PublicKey('WALLET_PUBLIC_KEY');
console.time('findByOwnerV2');
Metadata.findByOwnerV2(connection, wallet).then(() => console.timeEnd('findByOwnerV2'));
console.time('findByOwnerV3');
@fersilva16
fersilva16 / getTokensOfOwnerFromWallet.ts
Created February 4, 2022 20:10
Get tokens of the owner from an given wallet
import web3 from '@solana/web3.js';
import base58 from 'bs58';
import { asyncFilter } from './asyncFilter'; // From https://gist.github.com/fersilva16/dea9bb85ca69de435d01b8793d44948a
const TOKEN_PROGRAM_ID = new web3.PublicKey(
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
);
const TOKEN_METADATA_PROGRAM_ID = new web3.PublicKey(
@fersilva16
fersilva16 / asyncFilter.ts
Created February 4, 2022 17:58
Async array filter
import { asyncEach } from './asyncEach'; // From https://gist.github.com/fersilva16/bdf2d0b9a5eedbcf7232760df876a87d
export async function asyncFilter<T>(
array: { map(callback: (value: T) => any): Promise<any>[] },
predicate: (value: T) => Promise<boolean>
): Promise<T[]> {
const result: T[] = [];
await asyncEach(array, async (value, ...args) => {
const shouldAdd = await predicate(value, ...args);
@fersilva16
fersilva16 / transformMUIImports.ts
Last active January 13, 2022 19:13
Fix MUI imports from v4
import type { FileInfo, API } from 'jscodeshift';
const newPackagesMap: Record<string, string> = {
'@material-ui/core': '@mui/material',
'@material-ui/icons': '@mui/icons-material',
'@material-ui/styles': '@mui/styles',
};
const newPackages = Object.keys(newPackagesMap);