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
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 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 <rnavarro@rnavarro.com.br>"] | |
edition = "2018" | |
[[bin]] | |
name = "proxy" | |
path = "proxy.rs" |
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
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 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 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 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 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 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; |
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
import React, { | |
Component, | |
PropTypes, | |
} from "react"; | |
import { | |
Animated, | |
View, | |
} from "react-native"; |
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
const fs = require("fs"); | |
const path = require("path"); | |
const promisify = fn => (...args) => | |
new Promise((resolve, reject) => | |
fn(...args, (err, res) => err === null ? resolve(res) : reject(err)) | |
); | |
const mkdir = promisify(fs.mkdir); | |
const stat = promisify(fs.stat); |