Skip to content

Instantly share code, notes, and snippets.

View dimitardanailov's full-sized avatar

Dimitar Danailov (a.k.a Mitco) dimitardanailov

View GitHub Profile
@dimitardanailov
dimitardanailov / delete-index.js
Created February 17, 2022 16:12
ElasticSearch: Delete an index
'use strict'
const {Client} = require('@elastic/elasticsearch')
const client = new Client({node: 'http://localhost:9200'})
client.indices
.delete({
index: 'audit-*',
})
.then(
@dimitardanailov
dimitardanailov / signTxn.js
Created February 12, 2022 07:16
Algorand sign transaction
signTxn(sk: Uint8Array) {
// construct signed message
const sTxn: EncodedSignedTransaction = {
sig: this.rawSignTxn(sk),
txn: this.get_obj_for_encoding(),
};
// add AuthAddr if signing with a different key than From indicates
const keypair = nacl.keyPairFromSecretKey(sk);
const pubKeyFromSk = keypair.publicKey;
if (
@dimitardanailov
dimitardanailov / algorand-transaction.js
Created February 11, 2022 19:39
Algorand transaction
/**
* @resource
* https://github.com/PureStake/api-examples/blob/master/javascript-examples/algod_submit_tx.js
* https://developer.algorand.org/docs/sdks/javascript/#build-first-transaction
*/
export async function pureTransaction() {
const regExp = new RegExp(/\,/, 'g')
const mnemonic = 'final, equal, social, attack, chimney, spend, swear, civil, sad, jungle, dumb, assault, metal, feature, monitor, marriage, fly, depart, ill, shed, burger, census, swift, absent, garlic'.replace(
regExp,
'',
@dimitardanailov
dimitardanailov / algorand-wallet.js
Created January 29, 2022 07:24
Create an Account on Algorand + re-generate the address from public key
import algosdk from 'algosdk'
const createAddress = () => {
const account = algosdk.generateAccount()
const mn = algosdk.secretKeyToMnemonic(account.sk)
console.log('Account Mnemonic:', mn)
console.log('account', account)
const {publicKey, checksum} = algosdk.decodeAddress(account.addr)
@dimitardanailov
dimitardanailov / algorand-wallet-output.md
Created January 29, 2022 07:10
Create an Account on Algorand: Output
Account Mnemonic: couch august visa harbor fit amount blind yellow tent exile resist hurry bone eternal taxi usage moral roast mercy recipe thunder volcano grant able shove
account {
  addr: 'RW6EZIUTLGTG7HSARRGDUX55ZV5OLAS4WNOEIO2DQ4YRITL7TB7QQYFEYQ',
  sk: Uint8Array(64) [
    135, 201,  67, 233, 145, 230,  43,  32, 248,   2, 255,
    250, 238, 211, 110, 251, 166,  12,  54, 205, 155, 239,
    125, 196, 174,  22,  59, 203, 240, 214, 183,  76, 141,
    188,  76, 162, 147,  89, 166, 111, 158,  64, 140,  76,
     58,  95, 189, 205, 122, 229, 130,  92, 179,  92,  68,
@dimitardanailov
dimitardanailov / algorand-wallet.js
Created January 29, 2022 07:00
Create an Account on Algorand
const algosdk = require('algosdk');
const createAccount = function() {
try {
const myaccount = algosdk.generateAccount();
console.log("Account Address = " + myaccount.addr);
let account_mnemonic = algosdk.secretKeyToMnemonic(myaccount.sk);
console.log("Account Mnemonic = "+ account_mnemonic);
console.log("Account created. Save off Mnemonic and address");
console.log("Add funds to account using the TestNet Dispenser: ");
console.log("https://dispenser.testnet.aws.algodev.network/ ");
const {TransactionFactory} = require('@ethereumjs/tx')
const Common = require('@ethereumjs/common').default
const {Hardfork} = require('@ethereumjs/common')
const BN = require('bn.js')
const {ethers} = require('ethers')
const elliptic = require('elliptic')
const ec = new elliptic.ec('secp256k1')
const sha256 = require('js-sha256')
const fromAddressPrivKey =
@dimitardanailov
dimitardanailov / README.txt
Created September 12, 2021 16:45
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
REMIX EXAMPLE PROJECT
Remix example project is present when Remix loads very first time or there are no files existing in the File Explorer.
It contains 3 directories:
1. 'contracts': Holds three contracts with different complexity level, denoted with number prefix in file name.
2. 'scripts': Holds two scripts to deploy a contract. It is explained below.
3. 'tests': Contains one test file for 'Ballot' contract with unit tests in Solidity.
SCRIPTS
@dimitardanailov
dimitardanailov / machine.js
Created February 13, 2020 15:56
Generated by XState Viz: https://xstate.js.org/viz
const lightBulbMachine = Machine({
id: 'toggle',
initial: 'inactive',
states: {
inactive: {
on: {TOGGLE: 'active'},
},
active: {
on: {TOGGLE: 'inactive'},
},
@dimitardanailov
dimitardanailov / google-compute-engine.md
Last active June 23, 2021 20:14
Tips and tricks related with Google Compute engine

Creating a Persistent Disk

Create a new instance
gcloud compute instances create gcelab --zone us-central1-c
Create a new persistent disk