Skip to content

Instantly share code, notes, and snippets.

@artiya4u
artiya4u / index.js
Last active March 8, 2020 19:05
Use callback function from .then
const {promisify} = require('util');
const fs = require('fs');
const readFileAsync = promisify(fs.readFile);
const filePath = 'index.js';
readFileAsync(filePath, {encoding: 'utf8'}).then(function (text) {
console.log(text);
}).catch(function (error) {
console.log(error);
});
@artiya4u
artiya4u / index.js
Created March 8, 2020 18:36
SyntaxError: await is only valid in async function
const {promisify} = require('util');
const fs = require('fs');
const readFileAsync = promisify(fs.readFile);
const filePath = 'index.js';
let text = await readFileAsync(filePath, {encoding: 'utf8'});
console.log(text);
pragma solidity ^0.4.24;
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
contract PromoCode is Ownable {
ERC20 public token;
mapping(bytes32 => bool) public used;
uint256 public amount;
const express = require('express');
const Web3 = require('web3');
const {bufferToHex} = require('ethereumjs-util');
const HDWalletProvider = require('truffle-hdwallet-provider');
const providerWithMnemonic = (mnemonic, rpcEndpoint) =>
new HDWalletProvider(mnemonic, rpcEndpoint);
const infuraProvider = network => providerWithMnemonic(
process.env.MNEMONIC || '',
process.env.RPC_URL || `https://${network}.infura.io/${process.env.INFURA_API_KEY}`,
);
#QRcodes
URL:https://carboneum.io/p/?c=C8190613001&s=0x90b20a71d07db5a09b755d7a27c298f0afc06177012ac5b6ab4486a6bd24741e2519d1016569adbdba91bb7e8f919dc9910a06d482f22ae8c5069311f6fd51351c
URL:https://carboneum.io/p/?c=C8190613002&s=0x421948181f831b8f9c63506587f3e52ce9cd2a016cac170ad6c2127ec561c9246daaeecf540bea4ce115bf4498b11697f148ac6199f6e39bb7e8fa9af53f86f11b
URL:https://carboneum.io/p/?c=C8190613003&s=0xe463970c8524046209f1d8c09076bae02b63a6fb3a37be12f2f9705c34ceb14a7a058c9883d6c926965a2eaf380280dffd2ad07276ad2869d176fa8d302243191c
URL:https://carboneum.io/p/?c=C8190613004&s=0x53652962e3e798af9029a3624217998eaea69d317685ccac83d63f8440d259c25d4c62e503bc2d1b00f76a882f15ccf51c57403688dde2405cfff010e55b26bd1c
URL:https://carboneum.io/p/?c=C8190613005&s=0xbb75ec7e03139b09d9c621228981e2ab82a7879a32da6f97a5b9509dedd0dd1f178d1250f8f5afde07ce1ff0ac501efeacf6343ee1db83d9b5e1468d7061de601c
URL:https://carboneum.io/p/?c=C8190613006&s=0x289cf3b5117f40f6fcb70e38827ef91ea41db3a7b37c983432b206ada2584c49361ef73188ed05572022
const Web3 = require('web3');
const {bufferToHex} = require('ethereumjs-util');
const HDWalletProvider = require('truffle-hdwallet-provider');
const TokenABI = require('./abi/ERC20');
const PromoCodeABI = require('./abi/PromoCode');
const providerWithMnemonic = (mnemonic, rpcEndpoint) =>
new HDWalletProvider(mnemonic, rpcEndpoint);
const infuraProvider = network => providerWithMnemonic(
@artiya4u
artiya4u / PromoCode.sol
Last active June 16, 2019 04:53
Example promo code redeem smart contract. GOT FRONT RUN PROBLEM, DO NOT USE IT.
pragma solidity ^0.4.24;
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
// GOT FRONT RUN PROBLEM, DO NOT USE IT.
contract PromoCode is Ownable {
ERC20 public token;
mapping(bytes32 => bool) public used;
uint256 public amount;
@artiya4u
artiya4u / talib-install.sh
Last active July 9, 2022 14:29
Install TA-Lib script
#!/usr/bin/env bash
sudo apt install build-essential wget -y
wget https://artiya4u.keybase.pub/TA-lib/ta-lib-0.4.0-src.tar.gz
tar -xvf ta-lib-0.4.0-src.tar.gz
cd ta-lib/
./configure --prefix=/usr
make
sudo make install
@artiya4u
artiya4u / gen_binance_wallet.tcl
Last active May 14, 2019 08:03
Script to generate Binance chain wallet for testnet.
#!/usr/bin/expect
set timeout 20
for {set x 1} {$x<=20} {incr x} {
spawn tbnbcli keys add [format "wallet_%02d" $x]
expect "Enter a passphrase for your key:"
send "password\r";
expect "Repeat the passphrase:"
send "password\r";
interact
}
@artiya4u
artiya4u / random_with_weight.go
Last active September 22, 2018 02:54
Demo algorithm to get the random choice with different weight.
package main
import (
"fmt"
"math/rand"
)
func randomWithWeight(weights []int) int {
var sum int
for _, v := range weights {