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 std::io::Write; | |
use std::net::TcpListener; | |
use std::thread::sleep; | |
use std::time::Duration; | |
fn main() -> std::io::Result<()> { | |
let port = std::env::var("PORT").unwrap_or("3000".into()); | |
let listener = TcpListener::bind(format!("0.0.0.0:{port}"))?; | |
loop { |
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 anyhow::anyhow; | |
use aws_sdk_s3::{ | |
model::{CompletedMultipartUpload, CompletedPart}, | |
ByteStream, Client as S3Client, | |
}; | |
use futures::{StreamExt, TryStreamExt}; | |
use tokio::io::AsyncRead; | |
use tokio_util::io::ReaderStream; | |
pub async fn upload_file( |
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
mod as_json_string { | |
use serde::de::{Deserialize, DeserializeOwned, Deserializer}; | |
use serde::ser::{Serialize, Serializer}; | |
use serde_json; | |
pub fn serialize<T: Serialize, S: Serializer>( | |
value: &T, | |
serializer: S, | |
) -> Result<S::Ok, S::Error> { | |
let json = serde_json::to_string(value).map_err(serde::ser::Error::custom)?; |
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] | |
name = "naive-http-proxy" | |
version = "0.1.0" | |
authors = ["Rodrigo Navarro <[email protected]>"] | |
edition = "2018" | |
[[bin]] | |
name = "proxy" | |
path = "proxy.rs" |
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
Person = Immutable.new(:name, :age) | |
p1 = Person.new(name: "Sasha", age: 30) # <Person @name="Sasha", @age=30> | |
p2 = p1.with_name("Tori") # <Person @name="Tori", @age=30> | |
p3 = p2.update(name: "Craudio", age: 10) # <Person @name="Craudio", @age=10> | |
Person.new(name: "Sasha").with_age(30).with_name { |name| "#{name} Grey" } # <Person @name="Sasha Grey", @age=30> |
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
const http = require("http"); | |
const { PORT, PROXY_HOST, PROXY_PORT } = process.env; | |
http | |
.createServer((req, res) => { | |
const proxyRequest = http | |
.request({ | |
hostname: PROXY_HOST, | |
port: PROXY_PORT || 80, |
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
import { h1, div, p } from "./html"; | |
div([ | |
h1({ class: "title" }, "Title"), | |
p("A nice text"), | |
]); |
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
const http = require("http"); | |
const path = require("path"); | |
const target = process.env.TARGET; // ex: google.com | |
const port = process.env.PORT || 80; | |
http | |
.createServer(({ url, headers }, res) => { | |
const protocol = headers["x-forwarded-proto"] || "http"; | |
res.writeHead(308, { Location: `${protocol}://${path.join(target, url)}` }); |
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
// @flow | |
import { | |
always, | |
memoize, | |
pick, | |
} from "ramda"; | |
type ParsedURL = { | |
protocol: string, |
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
const { curry, splitEvery } = require("ramda"); | |
const batchMap = curry((batchSize, fn, list) => | |
splitEvery(batchSize, list) | |
.map(batch => all => Promise.all(batch.map(fn)).then(res => all.concat(res))) | |
.reduce((results, batch) => results.then(batch), Promise.resolve([])) | |
); | |
module.exports = batchMap; |