Skip to content

Instantly share code, notes, and snippets.

View Blazing-Mike's full-sized avatar
👷
Focusing

Michael Blazing-Mike

👷
Focusing
  • Earth C-137
View GitHub Profile
@Blazing-Mike
Blazing-Mike / htlc-me.js
Created May 16, 2022 11:49
going through HTLC.me code via dev tools, understanding core parts to implement something similar
// when you navigate to htlc.me for the first time it randomly assigns a wallet id
//this code return a wallet id using the crypto method ( uses UUID (universally unique identifier) concept which i don't really understand
App.uuid = (args) => {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
};
function generateAdvice() {
fetch("https://api.adviceslip.com/advice", { cache: "no-cache" })
.then((response) => response.json())
.then((response) => {
let data = response.slip;
let dataId = data.id;
let dataAdvice = data.advice;
adviceId.innerHTML = `advice # ${dataId}`;
  • JSX represents objects
  • JSX is an exoression too

The function signature is: createElement(type, props, children) . A React element is essentially a JavaScript object containing a type and props object.

  • React can't render into the body node, but we can choose any node within the body
  • Components let you split the UI into independent, reusable pieces, and think about each piece in isolation.

https://decentralizedthoughts.github.io/2020-12-22-what-is-a-merkle-tree/

A very simple way to think of a Merkle hash tree with n leaves is as a collision-resistant hash function 𝖬𝖧𝖳 that takes n inputs11 and ouputs a 2λ-bit hash, a.k.a. the Merkle root hash. More formally, the Merkle hash function is defined as:

𝖬𝖧𝖳:({0,1}∗)n→{0,1}2λ

And the Merkle root of some input x =(x1,…,xn) is denoted by:

h=𝖬𝖧𝖳(x1,…,xn)(5)

Formally, we can define a hash function as a mathematical function H:{0,1}∗↦{0,1}256. We use H(x)=y to denote that y is the output of H on input x.

A hash function is a random oracle: it takes an arbitrarily-sized input x, flips 256 coins y=⟨y1,y2,…,y256⟩, “remembers” x↦y, and from now on always returns y (i.e., 256 bits) on input x.

Applications of hash functions

  • Download integrity
  • proof-of-work
  • committment
# Set the best block hash here:
assumevalid=
# Run as a daemon mode without an interactive shell
daemon=1
# Set the data directory to the storage directory
# Set the number of megabytes of RAM to use, set to like 50% of available memory
def setup_network(self):
"""Setup the test network topology"""
def run_test(self):
"""Main test logic"""
self.log.info("Starting test!")
"""Let the user know the test has started"""
self.sync_all(self.nodes)
"""Sync all nodes for the test (1,2)"""
/* For the first task, you have to create a simple function — chooseName() — that prints
a random name from the provided array (names) to the provided paragraph (para), and then run it once. */
const names = ['Chris', 'Li Kang', 'Anne', 'Francesca', 'Mustafa', 'Tina', 'Bert', 'Jada']
const para = document.createElement('p');
function chooseName(){
let eachName = names[Math.floor(Math.random() * names.length)];
para.textContent = eachName;
}
@Blazing-Mike
Blazing-Mike / arrowfunc.js
Created November 1, 2021 23:36
Improving Readabilty of code with Arrow functions
//Normal function
function sum(num1, num2){
return num1 + num2;
}
let output =sum(10, 4);
console.log(output)
//Arrow function
let sum = (num1, num2) => return num1 + num2;
@Blazing-Mike
Blazing-Mike / order.html
Created October 26, 2021 12:52 — forked from craigshoemaker/order.html
Bethany's Pie Shop Order Form
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Order | Bethany's Pie Shop</title>
<link rel="stylesheet" href="site.css" type="text/css" />
<style>
@media only screen and (min-width: 768px) {