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
package main | |
import ( | |
"context" | |
"fmt" | |
"math/rand" | |
"runtime" | |
"sync" | |
"time" | |
) |
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
use bytes::Bytes; | |
use http_body_util::combinators::BoxBody; | |
use hyper::{Error, Response, Request}; | |
use std::collections::BinaryHeap; | |
use tower::{Layer, Service}; | |
use std::sync::{Arc, Mutex}; | |
use std::cmp::Ordering; | |
use std::pin::Pin; | |
use std::task::{Context, Poll}; |
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
fn main() { | |
let re = regex::Regex::new(r"[A-Za-z]").unwrap(); | |
println!( | |
"{:?}", | |
include_str!("../input.txt") | |
.lines() | |
.map(|s| re.split(s).filter(|s| !s.is_empty())) | |
.map(|s| { | |
s.into_iter() | |
.flat_map(|s| { |
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
# the file contents of state_of_the_union.txt is at the end of this gist, just copy and paste it into a file named state_of_the union.txt and place it in the same directory as the python file | |
# OpenAI api example | |
from langchain.embeddings.openai import OpenAIEmbeddings | |
from langchain.vectorstores import Chroma | |
from langchain.text_splitter import CharacterTextSplitter | |
from langchain.llms import OpenAI | |
from langchain.chains import RetrievalQA | |
from langchain.document_loaders import TextLoader |
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
package main | |
import ( | |
"log" | |
"time" | |
// remember go get these libs | |
"github.com/dgrijalva/jwt-go" | |
"github.com/MicahParks/keyfunc" | |
) |
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
--- | |
apiVersion: networking.istio.io/v1alpha3 | |
kind: EnvoyFilter | |
metadata: | |
name: lua-filter | |
namespace: dev | |
spec: | |
workloadSelector: | |
labels: |
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
# we run with api-key 123abc and we are limited to 5 (which is what the auth svc returned to us via the header) | |
❯❯❯ hey -c 1 -n 100 -H "x-api-key:123abc" http://localhost:30000/index on branch: main | |
... | |
Status code distribution: | |
[200] 5 responses | |
[429] 95 responses | |
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
function envoy_on_request(request_handle) | |
local reqs_per_unit = request_handle:streamInfo():dynamicMetadata():get("envoy.filters.http.header_to_metadata")["rate.requests_per_unit"] | |
local reqs_unit = request_handle:streamInfo():dynamicMetadata():get("envoy.filters.http.header_to_metadata")["rate.unit"] | |
request_handle:logWarn("requests_per_unit value: " .. reqs_per_unit) | |
request_handle:logWarn("unit value: " .. reqs_unit) | |
local rate_limits = { requests_per_unit = reqs_per_unit, unit = reqs_unit} | |
request_handle:streamInfo():dynamicMetadata():set("envoy.filters.http.ratelimit.override", "limit", rate_limits) |
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
--- | |
apiVersion: networking.istio.io/v1alpha3 | |
kind: EnvoyFilter | |
metadata: | |
name: core-authz-filter | |
spec: | |
workloadSelector: | |
labels: | |
app: python-api |
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
--- | |
apiVersion: networking.istio.io/v1alpha3 | |
kind: EnvoyFilter | |
metadata: | |
name: python-api-filter-ratelimit-svc | |
spec: | |
workloadSelector: | |
labels: | |
app: python-api | |
configPatches: |
NewerOlder