Skip to content

Instantly share code, notes, and snippets.

Michał Załęcki MichalZalecki

View GitHub Profile
View ScalableRewardDistribution.sol
pragma solidity 0.4.24;
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";
/// @title Scalable Reward Distribution
/// @dev ref. http://batog.info/papers/scalable-reward-distribution.pdf
contract ScalableRewardDistribution {
using SafeMath for uint256;
View blockchain.ts
import { performance } from "perf_hooks";
import { SHA256 as sha256 } from "crypto-js";
function calculateTarget(difficulty: number): number {
return Math.ceil(2 ** 256 / difficulty);
}
function padLeft(str: string, to: number, chr: string): string {
return str.length < to ? padLeft(chr + str, to, chr) : str;
}
View 3_presale.js
const SimpleToken = artifacts.require("./SimpleToken.sol");
const PresaleCrowdsale = artifacts.require("./02-presale-multiple-rounds/PresaleCrowdsale.sol");
module.exports = (deployer, network, [owner]) => {
return deployer
.then(() => deployer.deploy(SimpleToken, "Tooploox", "TPX", 18, 21000000))
.then(() => deployer.deploy(PresaleCrowdsale, 10000, owner, SimpleToken.address, owner))
.then(() => SimpleToken.deployed())
.then(token => token.increaseApproval(PresaleCrowdsale.address, 1000000 * (10 ** 18)));
};
@MichalZalecki
MichalZalecki / ensutils-rinkeby.js
Created May 3, 2018
ensutils to work with Rinkeby
View ensutils-rinkeby.js
// STOP!
// Are you thinking of using this in an app? Don't!
// This script is designed for interactive use in the go-ethereum console.
// For use in an app, consider one of these fine libraries:
// - https://www.npmjs.com/package/ethjs-ens
// - https://www.npmjs.com/package/ethereum-ens
function namehash(name) {
var node = '0x0000000000000000000000000000000000000000000000000000000000000000';
if (name !== '') {
@MichalZalecki
MichalZalecki / web3Events.js
Created Apr 8, 2018
MetaMask and web3 1.0
View web3Events.js
import Web3 from "web3";
const web3 = new Web3(Web3.givenProvider);
const web3Events = new Web3(new Web3.providers.WebsocketProvider("wss://mainnet.infura.io/ws"));
const Contract = new web3.eth.Contract(ABI, ADDRESS);
const ContractEvents = new web3Events.eth.Contract(ABI, ADDRESS);
@MichalZalecki
MichalZalecki / utils.js
Last active Nov 29, 2017
Native implementation of common helper functions
View utils.js
function toPairs(obj) {
return Object.entries(obj); // ES2017
}
describe("toPairs", () => {
it("transforms object to key-value pairs", () => {
expect(toPairs({ foo: "bar", foz: "baz" })).toEqual([
["foo", "bar"],
["foz", "baz"]
]);
@MichalZalecki
MichalZalecki / docx2pdf.py
Created Jul 8, 2017
Converting DOCX to PDF using Python
View docx2pdf.py
import sys
import subprocess
import re
def convert_to(folder, source, timeout=None):
args = [libreoffice_exec(), '--headless', '--convert-to', 'pdf', '--outdir', folder, source]
process = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout)
filename = re.search('-> (.*?) using filter', process.stdout.decode())
@MichalZalecki
MichalZalecki / Dockerfile
Last active Mar 9, 2020
Install oh-my-zsh in Docker
View Dockerfile
RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "zsh"]
RUN wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true
# docker exec -it my-app-container /bin/zsh
@MichalZalecki
MichalZalecki / validateType.js
Last active May 5, 2017
Filter uploaded files by file type
View validateType.js
export default function validateType(accepts) {
const typeExps = accepts.split(/ *, */).map(type => new RegExp(type));
return file => Boolean(typeExps.find(exp => exp.test(file.type)));
}
// function onChange({ target }) {
// const acceptedFiles = target.files.filter(validateType("images/*, application/pdf"));
// }
@MichalZalecki
MichalZalecki / storage.js
Last active Jan 3, 2020
Simple sessionStorage/localStorage wrapper factory
View storage.js
import storageFactory from "./storageFactory";
export const localStore = storageFactory(localStorage);
export const sessionStore = storageFactory(sessionStorage);
You can’t perform that action at this time.