Skip to content

Instantly share code, notes, and snippets.

View tomericco's full-sized avatar

Tomer Gabbai tomericco

View GitHub Profile
@tomericco
tomericco / cosine_similarity.js
Created January 26, 2019 10:58
Cosine similarity implementation in JS
const str1 = 'This is an example to test cosine similarity between two strings';
const str2 = 'This example is testing cosine similatiry for given two strings';
//
// Preprocess strings and combine words to a unique collection
//
const str1Words = str1.trim().split(' ').map(omitPunctuations).map(toLowercase);
const str2Words = str2.trim().split(' ').map(omitPunctuations).map(toLowercase);
const allWordsUnique = Array.from(new Set(str1Words.concat(str2Words)));
@tomericco
tomericco / mew-hd-nav.js
Created August 23, 2018 17:15
Navigate to an HD wallet specific address on MEW
var button = document.querySelector('.m-addresses td a.ng-scope[translate=MNEM_more]');
async function navigateToIndex(addr) {
let addresses = [];
let navCount = 0;
while (addresses.indexOf(addr.toLowerCase()) === -1) {
await (() => {
return new Promise((resolve) => {
button.click();
const Web3 = require('web3');
const SignerProvider = require('ethjs-provider-signer');
const EthereumTx = require('ethereumjs-tx');
const keystore = require('../lib/keystore');
const provider = new SignerProvider('http://localhost:8545', {
signTransaction(rawTx, cb) {
const { from } = rawTx;
const privateKey = keystore.getPrivateKeyByAddress(from); // Load user's private key from your own keystore
const privateKeyHex = Buffer.from(privateKey, 'hex');
@tomericco
tomericco / account-mgmt.js
Last active November 19, 2017 19:13
Managing account against an Ethereum client
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
/*
* Creating account
*/
const passphrase = 'my-super-secret-passphrase'; // Get the passphrase from HTML form or any other way
web3.personal.newAccount(passphrase, (error, address) => {
user.setAddress(address);
});
@tomericco
tomericco / injected-web3.js
Created November 19, 2017 16:52
Using an injected Web3 instance
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
}