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
cargo install cargo-sweep | |
# Create a launchd job to run `cargo sweep --recursive --time 15 ~/GitHub` | |
# This will clean up all the cargo cache files older than 15 days | |
# Make it run once per day at midnight | |
# https://www.launchd.info/ | |
# First, create a plist file for the launchd job | |
cat > ~/Library/LaunchAgents/com.user.cargosweep.plist << 'EOF' | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
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
CREATE OR REPLACE FUNCTION has_overlap(arr1 text[], arr2 text[]) | |
RETURNS boolean AS $$ | |
DECLARE | |
i integer := 1; | |
j integer := 1; | |
n1 integer; | |
n2 integer; | |
x text; | |
BEGIN | |
-- Ensure arr1 is the shorter array |
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 typing import ( | |
Awaitable, | |
Iterable, | |
Mapping, | |
Optional, | |
Protocol, | |
Tuple, | |
TypeVar, | |
Union, | |
cast, |
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 typing import ClassVar, Protocol | |
class APIKey(Protocol): # provided by some framework | |
header_name: ClassVar[str] | |
key: str | |
def __init__(self, key: str) -> None: # so that framework can construct the subclass | |
self.key = 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
""" Snippet that demonstrates how to use Uvicorn in code. | |
Feel free to run: | |
- `python main.py` | |
""" | |
import asyncio | |
import uvicorn | |
from pydantic import BaseSettings |
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
use std::cmp; | |
use std::hash; | |
use pyo3::basic::CompareOp; | |
use pyo3::prelude::*; | |
// We can't put a Py<PyAny> directly into a HashMap key | |
// So to be able to hold references to arbitrary Python objects in HashMap as keys | |
// we wrap them in a struct that gets the hash() when it receives the object from Python |
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
use std::cmp; | |
use std::collections::HashMap; | |
use std::collections::hash_map::Entry; | |
use std::hash; | |
use pyo3::prelude::*; | |
use pyo3::types::{PyTuple}; | |
// We can't put a Py<PyAny> directly into a HashMap 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
use std::cmp; | |
use std::hash; | |
use std::collections::HashSet; | |
use std::os::raw::c_int; | |
use pyo3::prelude::*; | |
use pyo3::ffi; | |
use pyo3::conversion::{AsPyPointer}; | |
use pyo3::{pyobject_native_type_base,pyobject_native_type_info,pyobject_native_type_extract,PyNativeType}; | |
use pyo3::types::{PyString}; |
Loading
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 __future__ import annotations | |
import cProfile | |
import pstats | |
from collections import deque | |
from dataclasses import dataclass, field | |
from random import Random | |
from timeit import default_timer | |
from typing import Awaitable, Callable, Deque, Iterable, List, Optional, Protocol, Union |
NewerOlder