Skip to content

Instantly share code, notes, and snippets.

View jjgonecrypto's full-sized avatar
🔗
Eth wrangling.

j-j.eth jjgonecrypto

🔗
Eth wrangling.
View GitHub Profile
@jjgonecrypto
jjgonecrypto / async-foreach.js
Created November 28, 2019 05:57
async forEach
// Useful if you want to run a bunch of promises in serial (which admittedly isn't very often frankly)
exports.asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
};
@jjgonecrypto
jjgonecrypto / index.html
Created October 20, 2019 16:53
Synthetix top holders lock status
<header><img src="https://developer.synthetix.io/api/img/logo.png" /></header>
<main>
<p class="helper-text">Note: these results aren't strictly ordered to increase performance.</p>
<button name="begin">Begin</button>
<button name="stop">Stop</button>
<ul>
<li id="tokenHolders"><strong>Token Holders:</strong><var>?</var></li>
@jjgonecrypto
jjgonecrypto / totalIssuedSynths.js
Created July 3, 2019 21:54
Get total issued debt at some specific block
const { SynthetixJs } = require('synthetix-js');
const snxjs = new SynthetixJs();
(async () => {
const provider = snxjs.ethers.getDefaultProvider();
const currentBlock = await provider.getBlockNumber();
const totalDebtInSystemAtBlock = await snxjs.Synthetix.contract.totalIssuedSynths(
snxjs.utils.toUtf8Bytes4('sUSD'),
@jjgonecrypto
jjgonecrypto / exchanges.js
Created July 3, 2019 21:37
Get all SynthExchange events in the last 24hours using The Graph
const graphAPI = 'https://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix';
const ts = Math.floor(Date.now()/1e3);
const oneDayAgo = ts - (3600 * 24);
const response = await fetch(graphAPI, {
method: 'POST',
body: `{"query":"{synthExchanges(orderBy:timestamp, orderDirection:desc, where:{timestamp_gt: ${oneDayAgo}}){id,from,gasPrice,fromAmount,fromCurrencyKey,toCurrencyKey,block,timestamp,toAddress}}","variables":null}`
});
const json = await response.json();
@jjgonecrypto
jjgonecrypto / vcheck.js
Created May 14, 2019 17:27
Node script to check npm version of package (expects piped in versions from npm)
'use strict';
const version = process.argv[2];
// Simple script to exit non-zero if the given version
// usage: npm view [package] versions | node vcheck [version]
// eg: npm view synthetix versions | node vcheck 2.4.1
process.stdin
.resume()
.setEncoding('utf8')
@jjgonecrypto
jjgonecrypto / random-split.js
Created December 4, 2018 19:48
Function to split up some given number into a fixed number of parts.
const random = require('random-js')();
// Splits up number into times random parts
const splitter = (number, times) => {
const ran = random.real(0, number);
if (times < 2) {
return [number];
}
const halved = times / 2;
if (times % 2 === 0) {
@jjgonecrypto
jjgonecrypto / EOS Smart Contract Development.md
Last active March 3, 2021 14:39
Getting started writing Smart Contracts with EOS

Getting started writing Smart Contracts with EOS

This information has been extrapolated from https://developers.eos.io/eosio-home/docs

Latest version of EOS when writing: 1.4.0

Note: the Developer Portal has a number of older links inside it. Some of the URLs contain older version numbers. For example, if you use the breadcrumbs at the top, things can get confusing as the latest version shows as v1.3.0 which has different C++ syntax due to the latest changes in eosio.cdt )Contract Development Toolkit) https://developers.eos.io/eosio-cpp/v1.3.0/docs/introduction-to-smart-contracts

Environment Setup

@jjgonecrypto
jjgonecrypto / Deferred.js
Last active May 11, 2018 15:21
Migrating to jQuery 3 Promises A+
module.exports = class Deferred {
constructor() {
this._promise = new Promise((resolve, reject) => {
this._resolve = resolve;
this._reject = reject;
});
}
resolve(value) {
this._resolve(value);
@jjgonecrypto
jjgonecrypto / grecent.sh
Last active March 28, 2017 16:34
Git show branches with most recent commits
# via http://stackoverflow.com/a/5188364/794170
git for-each-ref --sort=committerdate refs/heads/ --format="%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))"
@jjgonecrypto
jjgonecrypto / index.html
Last active December 14, 2021 02:04
es6 proxy #jsbench #jsperf (http://jsbench.github.io/#531652a2edfa806a5014558bafe6eb0e) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>es6 proxy #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>