Skip to content

Instantly share code, notes, and snippets.

View raineorshine's full-sized avatar

Raine Revere raineorshine

  • New York, NY
View GitHub Profile
@raineorshine
raineorshine / assert-throw.js
Last active March 16, 2019 18:37
Asserting solidity throws in truffle tests.
it('should throw an error', cb => {
const result = aMethodThatRejects()
result.then(x => { cb('Expected error. Instead got ' + x) }))
result.catch(() => cb())
})
@holiman
holiman / Cloner.sol
Last active April 9, 2024 16:36
A generic 'cloner' contract which clones other contract instances
pragma solidity ^0.4.4;
contract X{
string junk;
function y() returns(string){
//Uncomment the 'junk' below to make gas-measurements
//junk="0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345
@haroldtreen
haroldtreen / promise-test.js
Last active August 25, 2023 13:59
Testing promise rejection with Mocha
const { assert } = require('chai');
function isError(e) {
if (typeof e === 'string') {
return Promise.reject(new Error(e));
}
return Promise.resolve(e);
}
@chriseth
chriseth / 0 README.md
Last active November 6, 2022 19:55
Formal verification for re-entrant Solidity contracts

This gist shows how formal conditions of Solidity smart contracts can be automatically verified even in the presence of potential re-entrant calls from other contracts.

Solidity already supports formal verification of some contracts that do not make calls to other contracts. This of course excludes any contract that transfers Ether or tokens.

The Solidity contract below models a crude crowdfunding contract that can hold Ether and some person can withdraw Ether according to their shares. It is missing the actual access control, but the point that wants to be made

anonymous
anonymous / FallbackGasFunctions.sol
Created June 8, 2016 18:44
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-latest.js&optimize=undefined&gist=
// 21,030
contract Fallback {
uint deposits = 0;
}
// Transaction: 41,143
// Execution: 20,143
contract FallbackDeposit {
uint deposits = 0;
function() {
/**
* Base contract that all upgradeable contracts should use.
*
* Contracts implementing this interface are all called using delegatecall from
* a dispatcher. As a result, the _sizes and _dest variables are shared with the
* dispatcher contract, which allows the called contract to update these at will.
*
* _sizes is a map of function signatures to return value sizes. Due to EVM
* limitations, these need to be populated by the target contract, so the
* dispatcher knows how many bytes of data to return from called functions.
@raineorshine
raineorshine / package.json
Last active October 23, 2023 15:35
Raine's initial package.json
{
"name": "",
"description": "",
"version": "0.0.0",
"author": {
"name": "Raine Revere",
"email": "raine.revere@pm.me",
"url": "https://github.com/raineorshine"
},
"engines": {
@paullewis
paullewis / requestIdleCallback.js
Last active February 21, 2024 16:56
Shims rIC in case a browser doesn't support it.
/*!
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
module TimeApp ( start, Config, App ) where
{-| This module helps you start your application in a typical Elm workflow.
It assumes you are following [the Elm Architecture][arch] and using
[elm-effects][]. From there it will wire everything up for you!
**Be sure to [read the Elm Architecture tutorial][arch] to learn how this all
works!**
[arch]: https://github.com/evancz/elm-architecture-tutorial
[elm-effects]: http://package.elm-lang.org/packages/evancz/elm-effects/latest
@Akira-Hayasaka
Akira-Hayasaka / gist:026b7c7ae611bc7485e4
Created April 5, 2015 00:39
osx shutdown, restart, sleep script
Shut down without showing a confirmation dialog:
osascript -e 'tell app "System Events" to shut down'
Shut down after showing a confirmation dialog:
osascript -e 'tell app "loginwindow" to «event aevtrsdn»'
Restart without showing a confirmation dialog:
osascript -e 'tell app "System Events" to restart'
Restart after showing a confirmation dialog: