Skip to content

Instantly share code, notes, and snippets.

@LNow
LNow / ln.c
Created April 9, 2022 21:53 — forked from LingDong-/ln.c
simple, fast, accurate natural log approximation without <math.h>
// ln.c
//
// simple, fast, accurate natural log approximation
// when without <math.h>
// featuring * floating point bit level hacking,
// * x=m*2^p => ln(x)=ln(m)+ln(2)p,
// * Remez algorithm
// by Lingdong Huang, 2020. Public domain.
@LNow
LNow / subnets.md
Created October 8, 2021 17:46 — forked from jcnelson/subnets.md
Subnets

Disclaimer: I'm trying to flesh out a system that has only been described at a very high level. The purpose of this document is to write down notes on how I currently and tentatively believe subnets will work. This document is not authoritative, and may be significantly revised or even deleted.

All the credit for this approach goes to Aaron Blankstein. This document is based off of a conversation I had with him. I'm merely filling in the gaps.

What do we know about Subnets?

From what I've been able to gather, a Stacks subnet is shaping up to be a system that, at a high level, makes a lot of similar guarantees to sidechains and drivechains. It has the following properties:

  • Closed-membership: system liveness is driven by a whitelisted set of network participants.
@LNow
LNow / appchain.clar
Created September 27, 2021 10:49 — forked from jcnelson/appchain.clar
appchain.clar
;; Appchain MVP mining contract! Appchain peers scan the host chain (the chain that stores this contract and its state)
;; to discover one another and the appchain block metadata. From there, the appchain's miners proceed to work on their
;; chain by sending contract-call's to this contract to store more block metadata.
;;
;; This contract essentially mimics the way Bitcoin behaves towards Stacks -- it's just a dumb data storage contract that
;; holds onto the same data that would go into Bitcoin transactions for mining. The only difference is that the appchain
;; uses STX as its underlying base currency for mining and PoX, instead of BTC.
(define-constant ERR_NO_RECIPIENTS u0)
(define-constant ERR_NO_COMMIT_SPEND u1)
@LNow
LNow / appchains.md
Created September 27, 2021 10:49 — forked from jcnelson/appchains.md
Appchains

Blockchains don't scale. The fact that all nodes process all transactions means that the blockchain only goes as fast as the slowest node allowed on the network. If that's something like a Raspberry Pi, then that's as fast as the blockchain goes.

And that's okay! The upside is that the more people can run nodes, the more resilient the blockchain will be. It's much harder to break a 10,000-node blockchain where most nodes run on home computers all across the world than a 10,000-node blockchain where most nodes run in a few datacenters.

But the demand for cheap transactions isn't going anywhere. What's a distributed systems hacker to do?

A Composite Blockchain

A single blockchain can't handle unbound transaction volumes, but many blockchains can. Just like how the world's most expensive high-powered mainframe cannot match the capacity of a cloud made out of cheap servers, a single high-powered blockchain cannot match the combi

(define-constant T_BUFF 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
(define-read-only (sqrt (input int))
(get val (fold do-sqrt T_BUFF {input: input, val: (/ input 2), tmp: 0} ))
)
(define-read-only (do-sqrt (i (buff 1)) (data {input: int, val: int, tmp: int}))
(if (is-eq (get val data) (get tmp data))
data
{
Public Function CheckNIPStatus(ByVal NIP As String) As String
Dim obj As Object
Dim regEx As Object
Dim matches As Object
Dim fastVerLast As String
On Error GoTo err_h
Set regEx = CreateObject("vbscript.regexp")
regEx.MultiLine = True
@LNow
LNow / IPoint.cls
Last active November 8, 2018 15:24
Point
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "IPoint"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'@Folder("VBAProject")
@LNow
LNow / 0_reuse_code.js
Created August 10, 2014 12:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
DROP TABLE IF EXISTS time_dimension;
CREATE TABLE time_dimension (
id INTEGER PRIMARY KEY, -- year*10000+month*100+day
db_date DATE NOT NULL,
year INTEGER NOT NULL,
month INTEGER NOT NULL, -- 1 to 12
day INTEGER NOT NULL, -- 1 to 31
quarter INTEGER NOT NULL, -- 1 to 4
week INTEGER NOT NULL, -- 1 to 52/53
day_name VARCHAR(9) NOT NULL, -- 'Monday', 'Tuesday'...
@LNow
LNow / SHA1Hash.bas
Last active October 15, 2018 12:05
Public Function SHA1Hash(content As String) As String
Dim asc As Object
Set asc = CreateObject("System.Text.UTF8Encoding")
Dim enc As Object
Set enc = CreateObject("System.Security.Cryptography.SHA1CryptoServiceProvider")
Dim bytes() As Byte
bytes = asc.GetBytes_4(content)
bytes = enc.ComputeHash_2((bytes))