This file contains hidden or 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
# /// script | |
# dependencies = ["pydantic"] | |
# /// | |
from typing import Self | |
from pydantic import BaseModel, computed_field | |
class A(BaseModel): |
This file contains hidden or 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
events {} | |
http { | |
access_log /usr/local/openresty/nginx/logs/access.log; | |
error_log /usr/local/openresty/nginx/logs/error.log; | |
lua_shared_dict posts 1m; | |
init_by_lua_block { | |
local lfs = require"lfs" | |
local markdown = require "markdown" | |
local posts_root = "/usr/local/openresty/nginx/html/templates/posts" | |
for file in lfs.dir(posts_root) do |
This file contains hidden or 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
""" | |
utility for creating tiny primary keys | |
with a prefix (think type info) | |
keys are 32 bit integers: | |
- 5 bits: single-character prefix | |
- 27 bits: random | |
~134 million keys per prefix | |
for example: | |
U93152957 (user) or P42163488 (post) | |
""" |
This file contains hidden or 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 __future__ import annotations | |
from typing import Optional, NamedTuple, List | |
from dataclasses import dataclass, field | |
from enum import Enum | |
class Order(NamedTuple): | |
""" | |
public limit order interface | |
""" |
This file contains hidden or 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 jdb.db import DB | |
db = DB() | |
with db.transaction() as txn: | |
txn.read(b'foo') | |
txn.write(b'bar', b'baz') |
This file contains hidden or 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
""" | |
https://en.wikipedia.org/wiki/Merge-insertion_sort | |
""" | |
from typing import List, Callable, Tuple | |
from bisect import bisect | |
# max of pair, min of pair | |
Pair = Tuple[int, int] |
This file contains hidden or 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
#!/usr/bin/env python3 | |
""" | |
rule 90 implementation | |
""" | |
def rule90(starting): | |
grid, m = [starting], len(starting) | |
for i in range(1, m): |
This file contains hidden or 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
export default Component.extend({ | |
didInsertElement() { | |
document.addEventListener('message', this._handleMessage.bind(this)); | |
}, | |
willDestroyElement() { | |
document.removeEventListener('message', this._handleMessage.bind(this)); | |
} | |
_handleMessage(message) { |
This file contains hidden or 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
@objc(CardReaderManager) | |
class CardReaderManager: RCTEventEmitter { | |
func cardDataReceived(data: Dictionary<String, String>, sender: AnyObject) { | |
StripeUtil.createToken(data) { (token, error) in | |
self.sendEvent( | |
withName: "stripeToken", | |
body: token | |
) | |
} | |
} |
This file contains hidden or 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
class Checkout extends Component { | |
constructor(props) { | |
super(props); | |
this.subscriptions = []; | |
} | |
componentDidMount() { | |
const { cardReader: { emitter } } = global; |
NewerOlder