Skip to content

Instantly share code, notes, and snippets.

@krpeacock
krpeacock / candidToJS.js
Created April 12, 2023 17:59
Script to convert a candid file to JS IDL using a canister
import { IDL } from "@dfinity/candid";
import { Actor, HttpAgent } from "@dfinity/agent";
export const candidToJS = async (candid_source: string) => {
// call didjs canister
const didjs_interface: IDL.InterfaceFactory = ({ IDL }) =>
IDL.Service({
did_to_js: IDL.Func([IDL.Text], [IDL.Opt(IDL.Text)], ["query"]),
});
@krpeacock
krpeacock / storage.ts
Created August 4, 2022 19:31
EncryptedIdbStorage implementation using IdbKeyVal
export class EncryptedIdbStorage implements AuthClientStorage {
private initializedDb: IdbKeyVal | undefined;
get _db(): Promise<IdbKeyVal> {
return new Promise(resolve => {
if (this.initializedDb) resolve(this.initializedDb);
IdbKeyVal.create().then(db => {
this.initializedDb = db;
resolve(db);
});
});
@krpeacock
krpeacock / JavaScript-Agent.md
Created May 2, 2022 18:43
Documenting the JavaScript Agent

JavaScript on the Internet Computer

Basics

To get started with JavaScript on the Internet Computer, we recommend you follow our quickstart guide in order to get set up with the basics of your development environment. This includes:

  • Dfinity's development SDK, dfx
  • Node JS (12, 14, or 16)
  • A canister you want to experiment with
@krpeacock
krpeacock / create_canister.rs
Created August 20, 2021 18:31
Create canister from dfx
use crate::lib::environment::Environment;
use crate::lib::error::DfxResult;
use crate::lib::ic_attributes::CanisterSettings;
use crate::lib::identity::identity_utils::CallSender;
use crate::lib::identity::Identity;
use crate::lib::models::canister_id_store::CanisterIdStore;
use crate::lib::provider::get_network_context;
use crate::lib::waiter::waiter_with_timeout;
use anyhow::anyhow;
(()=>{
var mathProblem = `Calculate your bill:
Your tab came up to $88.50. Tax is 9%, and if you're feeling generous, you'll tip 20%. It's a pandemic, after all.
`
var riddle = `What goes up, but never comes down?`
var lifeSkill = `What is the second, little section, of the dishwasher detergent compartment for?`
console.log(`You are wandering through the forest, when you find a giant temple, with three ogres in front of the entrance.`);
@krpeacock
krpeacock / .zshrc
Last active November 21, 2019 22:32
Zshconfig
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/kyle/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes

6/29 Notes

Objectives:

  • Build One to many crud app
  • Add flask login
  • refactor with blueprints

For this exercise, we will have users who have many fish.

Flask Stuff

Notes from 6/28

Today's tasks:

  • Use flask-migrate to manage db state
  • manage flash messages with session
  • hash + salt with flask bcrypt

Setup instructions

from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
# Flask - class used to initialize an app
# render_template - render a template
# request - getting form data via POST request
# redirect - respond with location header
# url_for - shorthand for using function name instead of name of route
from flask_modus import Modus
Hello, world!