This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/socket.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <netinet/in.h> | |
#include <string.h> | |
#include <ctype.h> | |
#include <stdlib.h> | |
#include <arpa/inet.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## keccak256 (sha3-256) implementation in Nim | |
## for further details of this process: https://keccak.team/keccak_specs_summary.html | |
type | |
HashWords {.union.} = object | |
words: array[25, uint64] | |
bytes: array[200, uint8] | |
HashState* = ref object | |
hw: HashWords |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import time_ns | |
from threading import Lock | |
class SnowflakeGenerator: | |
def __init__(self, instance_id, epoch=-1): | |
self.instance_id = (instance_id&1023)<<12 | |
self.epoch = (time_ns()//1000 & 2199023255551) if epoch == -1 else epoch | |
self.seq = 0 | |
self.last_timestamp = 0 | |
self.lock = Lock() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import radians, sin, cos | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from dataclasses import dataclass | |
def length(vec: np.array): | |
return vec.dot(vec) ** 0.5 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import cycle | |
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
chrs = cycle('ZABCDEFGHIJKLMNOPQRSTUVWXY') | |
table = {l: {a[i-1]: c for c, i in zip(chrs, range(26)) if i != 0} for l in a} | |
def encode(message: str, key: str) -> str: | |
return ''.join( | |
c if u else c.lower() for c, u in ( | |
(table[k.upper()].get(m.upper(), m.upper()), m.isupper()) for m, k in zip(message, cycle(key)) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define W_PASSWORD "wifi-password" | |
#define W_SSID "wifi-ssid" | |
#define HOST "0.0.0.0" | |
#define PORT 80 | |
#include <M5Stack.h> | |
#undef min | |
#include "shs_network_time.h" | |
#include "simplehttpserver.h" | |
WiFiServer server(PORT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import sha256 | |
from datetime import datetime | |
from json import dumps | |
class Block: | |
def __init__(self, nonce, data, prevHash=None, difficulty=20): | |
self.nonce = nonce | |
self.data = data | |
self.timestamp = datetime.now().timestamp() | |
self.prevHash = prevHash |