Skip to content

Instantly share code, notes, and snippets.

View andreiashu's full-sized avatar

Andrei Simion andreiashu

View GitHub Profile
@andreiashu
andreiashu / solidity.mapping.BoolvsInt.sol
Created February 16, 2022 12:47
gas costs and a small gotcha about address to bool mappings
// SPDX-License-Identifier: MIT
pragma solidity 0.8.11;
contract MappingBool {
// NB: if you need to distinguish from nil vs false this method does not work
mapping(address => bool) entries;
// gas 44463
@andreiashu
andreiashu / 4.3.md
Created January 30, 2022 12:13 — forked from hayeah/4.3.md
yellopaper rewritten with source code references

4.3 The Block

The block in Ethereum is the collection of relevant pieces of information (known as the block header), together with information corresponding to the comprised transactions, and a set of other block headers that are known to have a parent equal to the present block’s parent’s parent (such blocks are known as uncles).

https://sourcegraph.com/github.com/ethereum/go-ethereum@479aa61f11724560c63a7b56084259552892819d/-/blob/core/types/block.go#L139

type Block struct {
	header       *Header
	uncles []*Header
@andreiashu
andreiashu / load-ethersjs.js
Created October 20, 2021 04:03
Load ethers in browser console
// paste this in your browser's console
(function() {
_loadScript = function(path){ var script= document.createElement('script'); script.type= 'text/javascript'; script.src= path; document.head.appendChild(script); }
_loadScript('https://cdn.jsdelivr.net/npm/ethers@5.5.0/dist/ethers.umd.js');
// @TODO: this can fail on slow connections; should have a retry mechanism
setTimeout(() => {
console.log(`Loaded ethersjs version: ${ethers.version}`);
}, 1500);
@andreiashu
andreiashu / load-web3.js
Created October 20, 2021 03:45
Load Web3 within browser console
// paste this in your browser's console
(function() {
_loadScript = function(path){ var script= document.createElement('script'); script.type= 'text/javascript'; script.src= path; document.head.appendChild(script); }
_loadScript('https://cdnjs.cloudflare.com/ajax/libs/web3/1.6.1-rc.0/web3.min.js');
// @TODO: this can fail on slow connections; should have a retry mechanism
setTimeout(() => {
console.log(`Loaded Web3 version: ${Web3.version}`);
}, 1500);
@andreiashu
andreiashu / jest.test.ts
Created July 31, 2018 06:01
Jest tests that helped me understand how different Jest settings behave
describe("Understand Jest framework", () => {
test("async works with Promise.resolve", async () => Promise.resolve(true))
test("async works with return", async () => true)
test("async works with expect met", async () => expect(true).toBe(true))
test("expect throws", async () => {
try {
expect(true).toBe(false)
console.log('This should not be printed')
} catch (err) {
// silence the error
@andreiashu
andreiashu / rinkeby.wallet
Created November 9, 2017 14:38
0x518d4640876362611fd93a177bf5f2a7b01f873c
0x518d4640876362611fd93a177bf5f2a7b01f873c
@andreiashu
andreiashu / bash_obliterate.sh
Created October 1, 2017 01:46
WARNING! this will obliterate absolutely all your Docker containers and images. I'm using it on an OSX installation to get rid of the pesky "No space left on device" error (with plenty of free space on my disk). Put it in your ~/.bashrc or ~/.zshrc and run it with `pwndocker`
# PWN that sucker!
# Warning: completely obliterates Docker: removes all containers, images and volumes
# add this function to your ~/.bash_profile or ~/.zshrc (or equivalent)
pwndocker() {
echo -n "You sure you want to pwn Docker (y/n)? "
read answer
if echo "$answer" | grep -iq "^y$" ;then
[[ -n $(docker ps -qa) ]] && docker kill $(docker ps -qa)
[[ -n $(docker ps -qa) ]] && docker rm -v $(docker ps -qa)
[[ -n $(docker images -q) ]] && docker rmi -f $(docker images -q)
@andreiashu
andreiashu / gdn_datapoint_schema.sql
Last active September 9, 2017 09:53
GDN DATA SQL TABLE SCHEMA
CREATE TABLE `datapoints` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`lineid` varchar(255) DEFAULT NULL,
`geolocation` point DEFAULT NULL,
`price` float NOT NULL,
`currency` varchar(20) NOT NULL DEFAULT '',
`locname` text DEFAULT NULL,
`time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
@andreiashu
andreiashu / index.js
Created May 24, 2017 22:23
bluebird handling unhandled rejections
const Promise = require('bluebird');
// bluebird unhandledRejection event
process.on('unhandledRejection', function (reason, promise) {
console.log(`unhandledRejection, reason ${reason}`, promise);
// don't continue in this state you plonker!
process.exit(1);
});
@andreiashu
andreiashu / git-dmz-flow.md
Created June 30, 2016 14:08 — forked from djspiewak/git-dmz-flow.md
Git DMZ Flow

Git DMZ Flow

I've been asked a few times over the last few months to put together a full write-up of the Git workflow we use at RichRelevance (and at Precog before), since I have referenced it in passing quite a few times in tweets and in person. The workflow is appreciably different from GitFlow and its derivatives, and thus it brings with it a different set of tradeoffs and optimizations. To that end, it would probably be helpful to go over exactly what workflow benefits I find to be beneficial or even necessary.

  • Two developers working on independent features must never be blocked by each other
    • No code freeze! Ever! For any reason!
  • A developer must be able to base derivative work on another developer's work, without waiting for any third party
  • Two developers working on inter-dependent features (or even the same feature) must be able to do so without interference from (or interfering with) any other parties
  • Developers must be able to work on multiple features simultaneously, or at lea