Skip to content

Instantly share code, notes, and snippets.

@vietlq
vietlq / call-then-sendtx-pattern.js
Created March 6, 2018 07:41 — forked from ethers/call-then-sendtx-pattern.js
call-then-sendtx pattern for Ethereum Dapps
/*
In Ethereum, a contract can be written so that it returns a value for eth_call.
A Dapp can then check for success or error value of eth_call, before calling eth_sendTransaction,
to take advantage of eth_call effectively being a "preview" of the code flow that the transaction
will take. In traditional client-server, clients can't ask servers beforehand what's going to
happen when the client makes a call; with Dapps contracts can be written so that clients can ask
for a "preview" of what is going to happen, before any funds/ethers are actually utilized
(eth_call does not cost any ethers).
Note: it is possible that in between eth_call and when eth_sendTransaction is actually mined,
@vietlq
vietlq / send_transfer_call.sol
Created March 9, 2018 10:56 — forked from tomw1808/send_transfer_call.sol
This is an example of the difference between "address.send()", "address.call.value()()" and "address.transfer()" in Solidity. If you like this example, then checkout my courses I do on Udemy (https://vomtom.at/tag/course/)
pragma solidity ^0.4.13;
contract someContract {
mapping(address => uint) balances;
function deposit() payable {
balances[msg.sender] += msg.value;
}
Verifying my Blockstack ID is secured with the address 1JgATzmvUGYJZYfQnHqTMo5GCfAgcPnQT6 https://explorer.blockstack.org/address/1JgATzmvUGYJZYfQnHqTMo5GCfAgcPnQT6
@vietlq
vietlq / index.js
Created March 20, 2018 08:46 — forked from AndrewJakubowicz/index.js
Example of using neon after `neon new ... ` step
// JS calling Rust
var addon = require('../native');
console.log(addon.hello());
// -> "hello node"
console.log(addon.adder(1,2));
// -> 3
console.log(addon.objAdder({a: 2, b: 5}));
@vietlq
vietlq / gist.md
Created March 29, 2018 12:20 — forked from rubensayshi/gist.md
Bitcoin Script Overview

rundown of different scripts and what is what and what goes where.

  • the prevoutScript is the script of the output being spend
  • the redeemScript is the script that is used to solve the P2SH
  • the signatureScript is the script that is taken into the signatureHash for signing
  • the witnessRedeemScript is the script that is used to solve the P2WSH
  • the scriptSig is what goes into the input.scriptSig when serializing the TX
  • the witnessScript is what goes into the input.witness when serializing the TX

for a P2KH

@vietlq
vietlq / DropZone.jsx
Created April 9, 2018 12:48 — forked from chrise86/DropZone.jsx
HTML5 Drag and Drop React Component
import React, {PropTypes} from 'react';
import classNames from 'classnames';
class BatchDropZone extends React.Component {
static propTypes = {
// function that recieves an array of files
receiveFiles: PropTypes.func.isRequired,
@vietlq
vietlq / gist:3969c0e5588e78a97b9ccbf62a1a0d17
Created April 10, 2018 14:44 — forked from jollytoad/gist:4201905
Read a File using a FileReader returning a jQuery promise
function readFile(file) {
var reader = new FileReader();
var deferred = $.Deferred();
reader.onload = function(event) {
deferred.resolve(event.target.result);
};
reader.onerror = function() {
deferred.reject(this);
@vietlq
vietlq / #wd-drop-file.py
Created April 19, 2018 10:22 — forked from florentbr/#wd-drop-file.py
Selenium - Drop a file from the desktop on a drop area
# JavaScript: HTML5 File drop
# param1 (WebElement): Drop area element
# param2 (int): Optional - Drop offset x relative to the top/left corner of the drop area. Center if 0.
# param3 (int): Optional - Drop offset y relative to the top/left corner of the drop area. Center if 0.
# load minified script
JS_DROP_FILE = "for(var b=arguments[0],k=arguments[1],l=arguments[2],c=b.ownerDocument,m=0;;){var e=b.getBoundingClientRect(),g=e.left+(k||e.width/2),h=e.top+(l||e.height/2),f=c.elementFromPoint(g,h);if(f&&b.contains(f))break;if(1<++m)throw b=Error('Element not interractable'),b.code=15,b;b.scrollIntoView({behavior:'instant',block:'center',inline:'center'})}var a=c.createElement('INPUT');a.setAttribute('type','file');a.setAttribute('style','position:fixed;z-index:2147483647;left:0;top:0;');a.onchange=function(){var b={effectAllowed:'all',dropEffect:'none',types:['Files'],files:this.files,setData:function(){},getData:function(){},clearData:function(){},setDragImage:function(){}};window.DataTransferItemList&&(b.i
@vietlq
vietlq / forwarder.sol
Created April 23, 2018 15:55 — forked from izqui/forwarder.sol
Very cheap to deploy (66k gas) forwarder contracts that can clone any contract and still have their own storage
// 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 Jordi Baylina for this way of deploying contracts https://gist.github.com/jbaylina/e8ac19b8e7478fd10cf0363ad1a5a4b3
// Forwarder is slightly modified to only return 256 bytes (8 normal returns)
// Deployed Factory in Kovan: https://kovan.etherscan.io/address/0xaebc118657099e2110c90494f48b3d21329b23eb
// Example of a Forwarder deploy using the Factory: https://kovan.etherscan.io/tx/0xe995dd023c8336685cb819313d933ae8938009f9c8c0e1af6c57b8be06986957
// Just 66349 gas per contract
@vietlq
vietlq / warn_unused_result.cpp
Last active May 12, 2018 16:54
C++ (GCC / Clang): Warn on unused function result/return for safety
// https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attributes.html
// https://infektor.net/posts/2017-01-19-using-cpp17-attributes-today.html
// Compiler flags: -Wall -Werror -Wextra -pedantic -Wunused-result -std=c++11
// Suggested macro names: HANDLE_OUTPUT / NODISCARD / MUST_HANDLE
#define HANDLE_OUTPUT __attribute__((warn_unused_result))
HANDLE_OUTPUT int critical_func()
{
return 1234;