Skip to content

Instantly share code, notes, and snippets.

View rumkin's full-sized avatar
🧠
Getting deeper

Paul Rumkin rumkin

🧠
Getting deeper
View GitHub Profile
@rumkin
rumkin / git-gpg.sh
Created December 16, 2018 23:22
Make Git to add GPG signature automatically
git config --global commit.gpgsign true
git config --global user.signingKey 13D9C694
@rumkin
rumkin / abi.json
Last active December 10, 2018 23:07
PaymentProxy Contract
[
{
"constant": false,
"inputs": [],
"name": "withdraw",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
@rumkin
rumkin / curried.js
Created December 7, 2018 01:23
Curried functions for JS
const curried = Symbol('curried');
function isCurried(fn) {
return fn[curried] === true;
}
function curry(fn, stored = []) {
if (isCurried(fn)) {
return fn(...stored);
@rumkin
rumkin / migrate.js
Last active October 31, 2018 09:04
export function up(doc, db) {
return {
$set: {
newProp: true,
},
$unset: {
oldProp: 1,
},
};
}
@rumkin
rumkin / ether-units-helpers.js
Created September 13, 2018 18:33
Ethereum units helpers
const BN = require("bn.js");
const {fromWei} = require('ethjs-unit');
const bn = (value) => new BN(value, 10);
const X = bn(1000);
const WEI = new BN(1);
const KWEI = WEI.mul(X);
const MWEI = KWEI.mul(X);
const GWEI = MWEI.mul(X);
@rumkin
rumkin / lea-resistant-buffer.js
Last active February 12, 2020 20:08
Length expansion attack resistant buffer
// Node.js version
function toLeaBuffer(msg) {
const msgBuf = Buffer.from(msg, 'utf8');
const sizeBuf = Buffer.allocUnsafe(8);
sizeBuf.writeBigUInt64BE(BigInt(msgBuf.length));
return Buffer.concat([sizeBuf, msgBuf]);
}
// Browser version
const currencyType = Type.string
.enum([
'BTC',
'ETH',
'USD',
]);
const numberType = Type.number;
class Exchange {
@rumkin
rumkin / api-example.js
Last active August 15, 2018 09:01
Example of API refactoring
// В данный момент мы имеем следующий код. Этот код пронизан зависимостями и
// связями с другими элементами, что делает его неделимы, уникальным и
// не изменяемым.
export function logIn() {
return dispatch => {
// (!) Ссылка на глобальную область видимости window.
// (!) Связывание интерфейсов Web3 и Redux.
window.web3.eth.getAccounts((err, accounts) => {
const acc = accounts[0];
@rumkin
rumkin / contract-full.sol
Last active July 11, 2018 12:49
Contract boilerplate with structured code layout
pragma solidity ^0.4.0;
import './utils/safe-math.sol';
contract Contract {
// Extension ---------------------------------------------------------------
using SafeMath for uint;
// Types -------------------------------------------------------------------
// Constants ---------------------------------------------------------------
// State -------------------------------------------------------------------
@rumkin
rumkin / nodejs-cloudconfig
Last active May 7, 2018 16:29
Test Nodejs Application
#cloud-config
users:
- name: nodejs
gecos: Nodejs application
sudo: None
lock_passwd: true
# ssh_authorized_keys:
# - Add your ssh keys here