Skip to content

Instantly share code, notes, and snippets.

View MichalZalecki's full-sized avatar

Michał Załęcki MichalZalecki

View GitHub Profile
@MichalZalecki
MichalZalecki / CycleRun.js
Created July 9, 2016 19:13
Mount Cycle.js app as react component
import React, { PropTypes, Component } from "react";
import ReactDOM from "react-dom";
import { makeDOMDriver } from "@cycle/dom";
import { run } from "@cycle/xstream-run";
class CycleRun extends Component {
static propTypes = {
main: PropTypes.func.isRequired,
drivers: PropTypes.object,
};
@MichalZalecki
MichalZalecki / validateType.js
Last active May 5, 2017 10:03
Filter uploaded files by file type
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 / utils.js
Last active November 29, 2017 22:06
Native implementation of common helper functions
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"]
]);
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)));
};
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;
}
@MichalZalecki
MichalZalecki / ScalableRewardDistribution.sol
Last active November 17, 2018 10:47
Scalable Reward Distribution implementation based on http://batog.info/papers/scalable-reward-distribution.pdf paper
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;
@MichalZalecki
MichalZalecki / web3Events.js
Created April 8, 2018 15:48
MetaMask and web3 1.0
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 / ensutils-rinkeby.js
Created May 3, 2018 08:16
ensutils to work with Rinkeby
// 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 / visor-archivos-online.md
Created September 5, 2016 20:23 — forked from izazueta/visor-archivos-online.md
Google Docs Viewer & Office Web Apps Viewer

Google Docs Viewer

Only files under 25 MB can be previewed with the Google Drive viewer.

Google Drive viewer helps you preview over 16 different file types, listed below:

  • Image files (.JPEG, .PNG, .GIF, .TIFF, .BMP)
  • Video files (WebM, .MPEG4, .3GPP, .MOV, .AVI, .MPEGPS, .WMV, .FLV)
  • Text files (.TXT)
  • Markup/Code (.CSS, .HTML, .PHP, .C, .CPP, .H, .HPP, .JS)
  • Microsoft Word (.DOC and .DOCX)
@MichalZalecki
MichalZalecki / rails-gmail.rb
Last active May 15, 2020 00:57
Gmail configuration for Rails
# /config/environments/development.rb
# Gmail configuration
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.com',
user_name: ENV['EMAIL_USER'],