Skip to content

Instantly share code, notes, and snippets.

@Gerst20051
Gerst20051 / calculateComplex.js
Last active June 24, 2021 04:50
Calculate Complex
const expression1 = '5+16-((9-6)-(4-2))+1';
const expression2 = '22+(2-4)';
const expression3 = '6+9-12';
const expression4 = '((1024))';
const expression5 = '1+(2+3)-(4-5)+6';
const expression6 = '255';
const operations1 = [['5', '+', '16', '-'], [['9', '-', '6'], '-', ['4', '-', '2']], ['+', '1']];
const operations2 = [['22', '+'], ['2', '-', '4']];
const operations3 = [['6', '+', '9', '-', '12']];
@Gerst20051
Gerst20051 / calculateSimple.js
Last active June 24, 2021 04:50
Calculate Simple
const expression1 = '6+9-12';
const expression2 = '1+2-3+4-5+6-7';
const expression3 = '100+200+300';
const expression4 = '1-2-3-0';
const expression5 = '255';
const expression6 = '0-1-2-3';
function calculate(input) {
return reduceOperations(buildOperations(input));
}
@Gerst20051
Gerst20051 / mine.go
Last active March 6, 2021 06:41
Mine Bitcoin Block In Go
// go run mine.go
// RESOURCES:
// http://www.righto.com/2014/02/bitcoin-mining-hard-way-algorithms.html
// https://en.bitcoin.it/wiki/Block_hashing_algorithm
// https://gist.github.com/Gerst20051/30d76e657fe8767fb5b57fb814d97341
// `mining.notify` stratum message
// https://en.bitcoin.it/wiki/Stratum_mining_protocol
// https://github.com/aeternity/protocol/blob/master/STRATUM.md#mining-notify
// https://github.com/MintPond/mtp-stratum-mining-protocol/blob/master/04_MINING.NOTIFY.md
@Gerst20051
Gerst20051 / minePYTHON36.py
Created November 26, 2020 20:32 — forked from turunut/minePYTHON36.py
Example of how a Bitcoin block is mined by finding a successful nonce
import hashlib, struct, codecs
ver = 2
prev_block = "000000000000000117c80378b8da0e33559b5997f2ad55e2f7d18ec1975b9717"
mrkl_root = "871714dcbae6c8193a2bb9b2a69fe1c0440399f38d94b3a0f1b447275a29978a"
time_ = 0x53058b35 # 2014-02-20 04:57:25
bits = 0x19015f53
# https://en.bitcoin.it/wiki/Difficulty
exp = bits >> 24
@Gerst20051
Gerst20051 / mine.py
Created November 26, 2020 20:32 — forked from shirriff/mine.py
Example of how a Bitcoin block is mined by finding a successful nonce
import hashlib, struct
ver = 2
prev_block = "000000000000000117c80378b8da0e33559b5997f2ad55e2f7d18ec1975b9717"
mrkl_root = "871714dcbae6c8193a2bb9b2a69fe1c0440399f38d94b3a0f1b447275a29978a"
time_ = 0x53058b35 # 2014-02-20 04:57:25
bits = 0x19015f53
# https://en.bitcoin.it/wiki/Difficulty
exp = bits >> 24
@Gerst20051
Gerst20051 / generate_template.py
Last active November 26, 2020 04:18
Generate Template
#!/usr/bin/env python3
import random
import unittest
def generate_template(group_id, template_data):
"""
Randomly generates a string based on the given group_id & template_data
:param group_id: int - ID for one of the groups in template_data
:param template_data: list - List of templates (see example in description)
@Gerst20051
Gerst20051 / sort_binaries.py
Last active November 26, 2020 03:37
Sort Binaries
#!/usr/bin/env python3
import unittest
def sort_binaries(arr):
j, l = -1, len(arr)
for i in range(l):
if arr[i] == 0:
j += 1
arr[i], arr[j] = arr[j], arr[i]
@Gerst20051
Gerst20051 / lengthOfLongestStraightFlush.js
Last active November 24, 2020 20:05
Length Of Longest Straight Flush
/*
Given a random subset of a standard deck of cards, return the length of the longest straight flush.
A standard deck of cards contains a total of 52 cards with 4 suits (Spades, Hearts, Clubs, Diamonds) and 13 cards for each suit (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King).
A straight flush is a set of cards that have the same suit and are in sequential order. The minimum hand size for this problem is 1.
*/
const testCards1 = [
{ suit: 'Hearts', rank: '3' },
{ suit: 'Clubs', rank: '10' },
{ suit: 'Spades', rank: 'Ace' },
@Gerst20051
Gerst20051 / addStrings.py
Created November 23, 2020 23:03
Add Strings
#!/bin/python3
#
# Complete the 'addStrings' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
# 1. STRING string1
# 2. STRING string2
#
@Gerst20051
Gerst20051 / CustomPromise.all.js
Last active June 24, 2021 04:51
Promise All Implementation
const CustomPromise = {
all: function (promises) {
return new Promise((resolve, reject) => {
const resolved = [];
promises.forEach((promise, index) => {
Promise.resolve(promise).then(result => {
resolved[index] = result;
if (resolved.length === promises.length) {
resolve(resolved);
}