Skip to content

Instantly share code, notes, and snippets.

View W3stside's full-sized avatar
🧟‍♂️

daveo W3stside

🧟‍♂️
View GitHub Profile
@W3stside
W3stside / cbWrappingCache.ts
Last active May 7, 2020 10:18
Callback-Wrapping Single Item Cache
interface SingleItemCache<R, A> {
cachedArg?: R[]
cachedValue?: A
}
export function cbCacheWrapper<R, A>(cb: Function): (...args: R[]) => A {
// create cache in closure
let singleItemCache: SingleItemCache<R, A> = {}
// close over a cb
@W3stside
W3stside / Web31.2.4_LogBloomsAndTopics.js
Last active April 30, 2020 07:22
Web3 LogBlooms & Topics
// 1. Log blooms: https://web3js.readthedocs.io/en/v1.2.4/web3-utils.html?highlight=bloom#bloom-filters
// Specific topic you're looking for, typically topics are:
// Contract Event params must not be anonymous
// topics array:
// 1. topics[0] = keccak256 hashed entire signature of specific Event e.g Deposit(uint amt, address user)
// 2. topics[1] = keccak256 hashed 1st param i.e uint amt
// 3. topics[2] = keccak256 hashed 2nd param i.e address user
@W3stside
W3stside / PDF_in_React_Webpack.js
Created July 18, 2018 21:27
Serving PDF files in React + Webpack
// Add file-loader
// in Webpack.dev and .prod
// in module.rules[]
{
test: /\.(pdf)$/i,
use: {
loader: 'file-loader',
options: {
@W3stside
W3stside / toBNSmart.js
Last active July 17, 2018 09:06
Show BigNumber.js amounts by MAX precision amount
// this gist is to show how, when using BigNumber JS
// one can display numbers in the FE using a set precision
// but without the issue of (assuming always precision 4)
// Numbers such as e.g 1 being shown as 1.000 or
// 1.00001 being show as 1.000
// this gist uses some typescript, just remove the typings in
// the function params if you're having problems
// using web3 v0.20
@W3stside
W3stside / contractValidityChecker.js
Created March 14, 2018 13:21
Checks array of passed in contracts for validity against EtherScan's validated contract list
/**
* EtherScan Validate Contract API
* URL: https://api.etherscan.io/api?module=contract&action=getabi&address=ContractAddressHere&apikey=YourApiKeyToken
* Checks contract address against database of approved Contracts
*/
const apiKey = 'yourEtherScanAPIKeyHere'
const checkContract = (addr, ak) =>
fetch(`https://api.etherscan.io/api?module=contract&action=getabi&address=${addr}&apikey=${ak}`)
@W3stside
W3stside / DDA.js
Last active November 24, 2017 16:19
Dynamic Decreasing Array (DDA)
// thanks Dmitry ^.^
let dynamicIdx = 15
const indexes = Array.from({ length: dynamicIdx }, (v, i) => dynamicIdx - i)
// spits out:
// [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
var json = {
heading: 'Welcome to the app!',
modal: {
message: {
alternate: 'Do you want to continue?',
default: 'Are you sure?'
},
no: 'Cancel',
yes: 'Continue',
},
/** Use NumGen to create a randomly sorted and filled Array to pass to quickSorter to test
* Can call quickSorter with numGen(<Number>) directly
* e.g quickSorter(numGen(500));
*/
/** numGen
* @param {number} - length
* @param {limit} - limit
* @returns {array}
*/
/** Use arrGen to create a randomly sorted and filled Array to pass to quickSorter to test
* Can call quickSorter with numGen(<Number>) directly
* e.g quickSorter(numGen(500));
*/
/** arrGen
* @param {number} - length
* @returns {array}
*/
const arrGen = (length, limit) => {