Skip to content

Instantly share code, notes, and snippets.

let UserContext = React.createContext();
class App extends React.Component {
state = {
user: null,
setUser: user => {
this.setState({ user });
}
};
@miguelmota
miguelmota / sign_send_transaction.js
Last active September 7, 2023 07:31
Node.js Ledger Nano S Ethereum sign transaction and broadcast
const Transport = require('@ledgerhq/hw-transport-node-hid').default
const AppEth = require('@ledgerhq/hw-app-eth').default
const Tx = require('ethereumjs-tx')
const Web3 = require('web3')
const web3 = new Web3('https://mainnet.infura.io:443')
async function main() {
const index = 1
const devices = await Transport.list()
if (devices.length === 0) throw 'no device'
@dakk
dakk / tezos-baking-howto.md
Last active March 6, 2022 21:22
tezos-baking-howto.md

Tezos baking howto

This howto is valid for Betanet on Ubuntu or Debian

Setup

Prereq

You have to install some dependencies. In debian / ubuntu run:

@educationofjon
educationofjon / regtest.js
Created March 9, 2018 21:25
Regtest Blocks
'use strict';
process.title = 'bcoin';
const assert = require('assert');
const FullNode = require('bcoin/lib/node/fullnode');
const plugin = require('bcoin/lib/wallet/plugin');
const node = new FullNode({
network: 'regtest',
@GNSPS
GNSPS / ProxyFactory.sol
Last active October 9, 2021 08:47
Improved `delegatecall` proxy contract factory (Solidity) [v0.0.5]
/***
* Shoutouts:
*
* Bytecode origin https://www.reddit.com/r/ethereum/comments/6ic49q/any_assembly_programmers_willing_to_write_a/dj5ceuw/
* Modified version of Vitalik's https://www.reddit.com/r/ethereum/comments/6c1jui/delegatecall_forwarders_how_to_save_5098_on/
* Credits to Jorge Izquierdo (@izqui) for coming up with this design here: https://gist.github.com/izqui/7f904443e6d19c1ab52ec7f5ad46b3a8
* Credits to Stefan George (@Georgi87) for inspiration for many of the improvements from Gnosis Safe: https://github.com/gnosis/gnosis-safe-contracts
*
* This version has many improvements over the original @izqui's library like using REVERT instead of THROWing on failed calls.
* It also implements the awesome design pattern for initializing code as seen in Gnosis Safe Factory: https://github.com/gnosis/gnosis-safe-contracts/blob/master/contracts/ProxyFactory.sol
@danfinlay
danfinlay / sendMutableTransaction.md
Last active January 17, 2018 01:41
An idea for a new web3 method, sendMutableTransaction

New Web3 Method Proposal: sendMutableTransaction

Today, when a dapp calls eth_sendTransaction, the parameters are sent up to the signer, and the app is called back once, with the resulting transaction hash.

This is a great way to allow a dapp to track the progress of a signed transaction, assuming that transaction is static and not mutable.

Recent transaction backlogs have forced us at MetaMask to add a button on long-pending transanctions to "Retry with higher gas price", but if a dapp or service was tracking the signed transaction by hash, it has no way of discovering that this transaction was ever resubmitted successfully.

This is only a problem for apps that submit a transaction, and continue tracking that specific transaction hash until it is mined, but for dapps with that problem, one solution could be to add a new method, maybe called eth_sendMutableTransaction, which calls back not wit

@jdkanani
jdkanani / decorators.js
Created August 2, 2017 11:06
Javascript decorators
export function sleepFor (timeInMilliSeconds = 1000) {
return new Promise((resolve, reject)=>{
setTimeout(resolve, timeInMilliSeconds);
});
}
export function waitFor (...names) {
return (target, prop, descriptor) => {
const fn = descriptor.value;
let newFn = function (...args) {
@benjick
benjick / persist.js
Created June 15, 2017 11:09
mobx-state-tree persist PoC
/* globals localStorage */
import { onSnapshot, applySnapshot } from 'mobx-state-tree';
import Storage from './storage';
export const persist = (name, store, options, schema = {}) => {
let hydrated = false;
let storage = options.storage;
if (typeof localStorage !== 'undefined' && localStorage === storage) {
@vadimshvetsov
vadimshvetsov / objectToDotNotation.js
Created May 25, 2017 11:56
Function for merging objects in find*Update function with one level nesting.
/**
* Consume update args object for document and can handle one level nesting.
* Returns object for leverage by $set in Mongoose update function.
*
* @param args
* @returns {{}}
*/
const objectToDotNotation = (args) => {
const setObject = {};
Object.keys(args).forEach((key) => {
@tomsapps
tomsapps / FRP.MD
Last active November 16, 2016 16:09

Observable

Observables are producers that can return many values asynchronously

Producers determine when the values are sent (PUSH)

Observable executions are NOT shared

setTimeout(() => foo.subscribe)
foo.subscribe