Skip to content

Instantly share code, notes, and snippets.

@joewagner
joewagner / bulk-insert.mjs
Created March 2, 2023 01:10
An example of helpers for Tableland bulk inserts that will need to be split into multiple transactions.
// Dependencies: @tableland/sdk, @tableland/local
// Run `npx local-tableland` and then run this script in another window
import { Database, helpers } from "@tableland/sdk";
import { Wallet, getDefaultProvider, utils } from "ethers";
// NOTE: using 34000 here to give a 1000 byte padding for the `insert into table values` and
// in case the sql parser increases the size, which is unlikely but possible.
// If you wanted to limit for gas you'd have to kinda guess a value here.
const BYTES_LIMIT = 34000
@joewagner
joewagner / policy-upgrades-testing.sh
Created February 28, 2023 23:10
List of commands to manually setup, deploy, upgrade a tableland registry. This enables testing the affects of existing policy contracts.
# you will want to run the hardhat node in a separate terminal
# putting this here as a reminder
cd evm-tableland
npx hardhat node
# Add the following to the `networks` prop in hardhat.config.ts
# "local-tableland": {
# url: "http://127.0.0.1:8545",
# accounts: [
# "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
@joewagner
joewagner / plog alias
Created November 2, 2022 01:06
Create a git alias that pretty logs
alias.plog log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=iso --branches
@joewagner
joewagner / muller-kahan.js
Created October 10, 2022 15:05
Javascript Muller Kahan
// This is a test designed by muller and kahan that demonstrates how
// the calculation of a known convergence returns incorrectly because
// of the mathematics of floating point numbers
const max = 21
let u = 2.0;
let v = -4.0;
let w;
for (let i = 3; i < max; i++) {
w = 111.0 - 1130.0/v + 3000.0/(v*u);
@joewagner
joewagner / Filecoin vanilla block inspector
Last active October 28, 2021 23:29
Filecoin vanilla block inspector
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chain Height</title>
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<!--
Make sure your Docker daemon is running
@joewagner
joewagner / brute force limit folding a paper
Created December 28, 2019 05:10
copy paste this into a javascript shell and you'll get 33.33333333333333
var lim = function (num) {
if (num === void 0) num = 100;
var series = [100, 50, 25];
var next = function () {
var lastTerm = series[series.length - 1];
var secondToLastTerm = series[series.length - 2];
// notice that, since we started above with the first three terms, that the fliping back and forth between adding
// and subtracting is handled here ↓, i.e. `secondToLastTerm - lastTerm` is alternating negative and positive
const express = require("express");
const session = require("express-session");
const cors = require("cors");
const app = express();
app.use(cors({
origin: ["http://localhost:3000"], credentials: true
}
));
@joewagner
joewagner / optimization-status.js
Created February 2, 2016 20:06
Demonstrates v8 optimization for reassigning vs. not reassigning `arguments` object
// reassigning an argument
function argReassign1(a) {
a = a || {};
}
// not reassigning an argument
function argReassign2(a) {
if (a === void 0) var a = {};
}
∆ ∆ ∫
˚Ú˚ ÒÒÒ
¯¯¯ | |
@joewagner
joewagner / gist:611c31b49dbe17d49168
Last active August 29, 2015 14:01
Simple class that may be used to create a pool of mongoose connections with unique MongoURIs
var mongoose = require('mongoose');
var UserSchema = require(__dirname + '/user-schema');
var DatabasePool = function () {
this.dbs = {};
};
// gets a connection to a specific mongo uri string, or
// creates it if it doesn't exist, or isn't connected
// Then attaches "User" Model to the connection