Skip to content

Instantly share code, notes, and snippets.

View peterpeterparker's full-sized avatar

David Dal Busco peterpeterparker

View GitHub Profile
@peterpeterparker
peterpeterparker / tokensymbols.mjs
Last active October 20, 2024 08:28
List of token symbols of length
// Relates to https://ethereum.stackexchange.com/questions/25619/is-there-length-limits-on-token-symbols?newreg=787e203d2b4c49cd8caecc1434ef435b
//
// Data source: Coingecko public API.
// Jul. 4th 2024
//
// Coin symbols of length 0: 7
// Coin symbols of length 1: 39
// Coin symbols of length 2: 353
// Coin symbols of length 3: 4339
// Coin symbols of length 4: 5025
@peterpeterparker
peterpeterparker / internet-identity-integration-basics.ts
Last active February 17, 2024 17:28
Integrating Internet Identity into a Client App: The Basics
/**
*
* Simplified Gist to showcase the basics of how to intergrate Internet Identity with agent-js in a frontend app.
*
* - Sign-in
* - Sign-out
* - Sync
*
*/
@peterpeterparker
peterpeterparker / deploy-ii-locally.md
Created November 2, 2022 20:34
Deploy II locally easily

Options 1

Automate the deployment with dfx.json - i.e. add following to your configuration. It will fetch and deploy the wasm of II locally.

"internet_identity": {
      "type": "custom",
      "candid": "internet_identity.did",
      "wasm": "internet_identity.wasm",
 "build": "bash -c 'test -f internet_identity.wasm || curl -sSL https://github.com/dfinity/internet-identity/releases/latest/download/internet_identity_dev.wasm -o internet_identity.wasm; test -f internet_identity.did || curl -sSL https://raw.githubusercontent.com/dfinity/internet-identity/main/src/internet_identity/internet_identity.did -o internet_identity.did'",
@peterpeterparker
peterpeterparker / ic-bundle-static-files.mjs
Last active November 2, 2023 10:37
Bundle static files in Motoko canisters
#!/usr/bin/env node
import {writeFile} from 'fs/promises';
import {Blob} from 'node:buffer';
import fetch from 'node-fetch';
const fetchData = async (url) => {
const response = await fetch(url);
@peterpeterparker
peterpeterparker / json-blob-array-number.ts
Created August 13, 2021 08:12
JSON <-> Blob <-> Array number
const toArray = async <T>(data: T): Promise<Array<number>> => {
const blob: Blob = new Blob([JSON.stringify(data)], {type: 'application/json; charset=utf-8'});
return [...new Uint8Array(await blob.arrayBuffer())];
};
const fromArray = async <T>(data: Array<number>): Promise<T> => {
const blob: Blob = new Blob([new Uint8Array(data)], {type: 'application/json; charset=utf-8'});
return JSON.parse(await blob.text());
};
@peterpeterparker
peterpeterparker / HelloWorld.mo
Created July 23, 2021 08:22
Motoko Hello World with permission check
import Hash "mo:base/Hash";
import Principal "mo:base/Principal";
import Text "mo:base/Text";
import Debug "mo:base/Debug";
import Error "mo:base/Error";
// Motoko Playground:
// https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/
@peterpeterparker
peterpeterparker / index.js
Created November 7, 2020 13:47
Create a PDF manually with JavaScript
const fs = require('fs');
/**
* Source: Mario's Security Blog - http://mariomalwareanalysis.blogspot.com/2012/02/how-to-manually-create-pdf.html
*/
function generatePDF() {
const lines = [];
lines.push(`%PDF-1.3`);
lines.push(`%\xFF\xFF\xFF\xFF`);