Skip to content

Instantly share code, notes, and snippets.

View gist:72272eb75f0158d333afded6e691b3d3
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=Visual Studio
compiler.runtime=MTd
compiler.version=17
os=Windows
os_build=Windows
View example.py
import asyncio
async def message(delay):
await asyncio.sleep(delay)
print(delay, flush=True)
async def main():
task = asyncio.create_task(message(2))
await message(1)
View blog.md

My last post covered the importance of supplying a RAII type for every pair of balanced functions in an API. Is it possible to write a reusable generic type that can implement that pattern for developers?

We might imagine a type that calls the start function in its constructor and the stop function in its destructor. The constructor would be parameterized by the start and stop functions; let them be callable objects in the general case. The start callable object would not be needed after the constructor returns, and honestly, maybe it shouldn't be passed to the constructor. Maybe the caller of the constructor should be responsible for calling the start function first, and then just constructing the gener

For this technique, we could write a generic type, call it Stopper, that calls an arbitrary function in its destructor.

View naxx.md

Notes on Naxxramas from a caster perspective

Short descriptions of each fight, with actions you must take in bold.

Anub'Rekhan

Two adds and Anub. Keep your distance from everything at all times. Focus down the adds while the tank holds Anub, then switch to Anub.

The tank and Anub will start to move around the perimeter of the room, and a new add will spawn. Switch focus to the add, but keep your distance from it and Anub. The add can root you with a web, and if Anub gets close enough to you, he'll silence you. We'll probably wipe if that happens to the healers. Anub will send out waves of little critters. AOE them down.

View isFullyCanonicalSig.js
GROUP_ORDER = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141'
// Divide by two and round up = shift right 1 bit and add 1.
HALF_GROUP_ORDER = '7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A1'
function isFullyCanonical(signatureDer) {
s = signatureDer.slice(-32)
// A lexicographical compare between big-endian hex strings yields the same ordering
// as a comparision of the unsigned integers they represent.
return s < HALF_GROUP_ORDER
}
View rfc2616.cpp
split(FwdIt first, FwdIt last, Char delim)
{
Result result;
using string = typename Result::value_type;
FwdIt iter = first;
string word;
bool need_space = false;
while (iter != last)
{
Char c = *iter++;
View test.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jfreeman/code/xpring-py/xpring/client.py", line 108, in send
self.submit(signed_transaction)
File "/home/jfreeman/code/xpring-py/xpring/client.py", line 88, in submit
self.grpc_client.SubmitSignedTransaction(request)
File "/home/jfreeman/code/xpring-py/.venv/lib/python3.7/site-packages/grpc/_channel.py", line 826, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "/home/jfreeman/code/xpring-py/.venv/lib/python3.7/site-packages/grpc/_channel.py", line 729, in _end_unary_response_blocking
raise _InactiveRpcError(state)
View gist:4ad7cad47cb9ae43c4c67223bfcf60b7
secp256k1 is just one popular curve for the Elliptic Curve Digital Signature algorithm (ECDSA).
An ECDSA key is a 256-bit value.
ECDSA will sign a 256-bit value.
If you want to sign a message of arbitrary length, it is customary to first hash the message to a 256-bit value.
One popular hash is SHA-256, but the one XRPL uses is "SHA-512 Half" (SHA-512 truncated to the first half, which is 256 bits).
ECDSA returns a point on a plane, whose coordinates are commonly named `r` and `s`.
Distinguished Encoding Rules (DER) is a popular encoding of a structure called Abstract Syntax Notation One (ASN.1).
ASN.1 can represent types like integers, sequences, and sets.
DER encodes these values to tag-length-value byte sequences.
View gist:519c0bdea684a8d41e6e8e7b03dbe426
secp256k1 is just one popular curve for the Elliptic Curve Digital Signature algorithm (ECDSA).
An ECDSA key is a 256-bit value.
ECDSA will sign a 256-bit value.
If you want to sign a message of arbitrary length, it is customary to first hash the message to a 256-bit value.
One popular hash is SHA-256, but the one XRPL uses is "SHA-512 Half" (SHA-512 truncated to the first half, which is 256 bits).
ECDSA returns a point on a plane, whose coordinates are commonly named `r` and `s`.
Distinguished Encoding Rules (DER) is a popular encoding of a structure called Abstract Syntax Notation One (ASN.1).
ASN.1 can represent types like integers, sequences, and sets.
DER encodes these values to tag-length-value byte sequences.
ECDSA signatures (`r` and `s`) are customarily encoded with DER.