Skip to content

Instantly share code, notes, and snippets.

View DanielVF's full-sized avatar

Daniel Von Fange DanielVF

View GitHub Profile
@DanielVF
DanielVF / debug.js
Created August 1, 2018 02:35
Origin helper for debugging events
// Example usage:
//
// console.table(await debugEvents(origin.contractService, {fromBlock:175, topics:[]}))
//
async function debugEvents(contractService, options){
const web3 = contractService.web3
// Lookup table for contracts from bytecode
@DanielVF
DanielVF / collect.js
Created September 28, 2018 11:36
Get origin contract address JSON from an origin DAPP
out = {}
for (const k in originTest.contractService.contracts) {
out[k] = {4: {address:originTest.contractService.contracts[k].networks[4].address}}
}
JSON.stringify(out)
@DanielVF
DanielVF / header.py
Last active November 15, 2018 12:37
Jupyter notebook standard header
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import json
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
pd.options.mode.chained_assignment = None
@DanielVF
DanielVF / atc.nim
Last active January 28, 2020 01:07
Nim engine, no documentation
import sets
import engine
import strutils
import math
# import log
type
Atc* = ref object of RootObj
available*: HashSet[Ship]
occupied*: seq[bool]
@DanielVF
DanielVF / live_reindex.sh
Created May 10, 2019 15:59
reindex elastic search listings with new mappings in two seconds
# If running against any data you care about, check the results of each command for success before running the next command.
# Create new index
curl -X PUT "localhost:9200/listings_two" -H 'Content-Type: application/json' -d'
{
"mappings":{"listing":{"properties":{"price.amount":{"type":"double"},"price.currency.id":{"type":"keyword"},"commission":{"type":"double"},"commissionPerUnit":{"type":"double"},"unitsTotal":{"type":"integer"},"language":{"type":"keyword"},"listingType":{"type":"keyword"},"status":{"type":"keyword"},"marketplacePublisher":{"type":"keyword"},"category":{"type":"keyword","copy_to":"all_text"},"subCategory":{"type":"keyword","copy_to":"all_text"},"description":{"type":"text","copy_to":"all_text"},"title":{"type":"text","copy_to":"all_text"},"all_text":{"type":"text"}}}}
}
'
# copy listings to new index
@DanielVF
DanielVF / traceprint.ts
Created September 9, 2019 17:01
Pretty print control flow of Etherium debug traces
const fs = require('fs')
const chalk = require('chalk')
const trace = JSON.parse(fs.readFileSync('2019_08_09_mike_fail.json'))
const logs = trace.result.structLogs as TraceLog[]
interface TraceLog {
depth: number
error: string
gas: number,
pragma solidity ^0.6.0;
// Calling SafeERC20.safeTransfer and SafeERC20.safeTransferFrom can fail
// with a "SafeERC20: ERC20 operation did not succeed" message when the
// underlying cause is running out of gas inside the transfer
// This is because the low level call to the ERC20 is indeed reverted by
// running out of gas, but that revert is caught, and a different revert
// is raised by the safeTransfer method.
@DanielVF
DanielVF / generate_random_airdrop.py
Created December 9, 2020 15:15
Generate random ethereum airdrop csv
import pandas as pd
import numpy as np
import secrets
num = 800
addresses = ['0x'+secrets.token_hex(20) for _ in range(0,num)]
amounts = np.power(1200000, np.random.rand(num)*np.random.rand(num))
df = pd.DataFrame({'address':addresses, 'amount':amounts})
df.to_csv('sample_amounts.csv')
@DanielVF
DanielVF / _charts.ipynb
Last active February 2, 2021 19:08
Compound USDT change proposal
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@DanielVF
DanielVF / OusdKeeper.sol
Last active September 8, 2021 19:36
OusdKeeper Draft
pragma solidity 0.8.7;
interface KeeperCompatibleInterface {
function checkUpkeep(bytes calldata checkData)
external
returns (bool upkeepNeeded, bytes memory performData);
function performUpkeep(bytes calldata performData) external;
}