Skip to content

Instantly share code, notes, and snippets.

@aisrael
aisrael / proxy_service.rs
Created September 3, 2019 05:07
Hyper Proxy Service
//! ProxyService which does the actual work of the Proxy
use futures::future;
use http::header::HeaderMap;
use hyper::rt::Future;
use hyper::service::Service;
use hyper::{Body, Client, Method, Request, Response, StatusCode};
use jsonwebtoken::{decode, TokenData, Validation};
use log::{debug, error, trace, warn};
use serde::{Deserialize, Serialize};
@aisrael
aisrael / lib.rs
Created July 1, 2019 08:47
This shouldn't work according to the docs
pub struct Context<'s>(&'s str);
struct Parser<'c, 's> {
context: &'c Context<'s>,
}
impl<'c, 's> Parser<'c, 's> {
fn parse(&self) -> Result<(), &'s str> {
Err(&self.context.0[1..])
}
@aisrael
aisrael / main.rs
Created June 29, 2019 13:05
Not working using latest hyper (0.12.31) and MakeService
use futures::future;
use hyper::rt::Future;
use hyper::service::{MakeService, Service};
use hyper::{Body, Request, Response, Server, StatusCode};
/// The service
pub struct TestService {}
impl Service for TestService {
@aisrael
aisrael / main.rs
Last active June 29, 2019 13:01
Works with hyper 0.12.14 and NewService
use futures::future;
use hyper::rt::Future;
use hyper::service::{NewService, Service};
use hyper::{Body, Request, Response, Server, StatusCode};
/// The service
pub struct TestService {}
impl Service for TestService {
@aisrael
aisrael / wordpress-deployment.yml
Last active May 22, 2019 08:14
wordpress Kubernetes
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-deployment
spec:
replicas: 2
selector:
matchLabels:
app: wordpress
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mariadb-deployment
spec:
selector:
matchLabels:
app: mariadb
template:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
template:
require "csv"
require "gzip"
MINIMUM_TIME = Time.parse_rfc3339("2017-11-02T00:00:00.000Z")
# process_file processes the .csv.gz files as a stream of bytes counting all records that
# meet the minimum date
def process_file(filename : String) : NamedTuple(total: Int32, matched: Int32)
puts "Processing: #{filename}"
total = 0
@aisrael
aisrael / Dockerfile
Created March 13, 2018 23:43
crystal-amber-docker
FROM ysbaddaden/crystal-alpine:0.24.1 as builder
RUN apk add openssl-dev yaml-dev nodejs
WORKDIR /src
COPY shard.* /src/
RUN shards
COPY . /src
RUN rm -rf node_modules
RUN npm install
RUN crystal build src/hello.cr
@aisrael
aisrael / hi8test_spec.cr
Created February 5, 2018 02:52
HI8 Spec that demonstrates failure using Cossack
require "./spec_helper"
require "cossack"
require "http/client"
HI8.configure do |config|
config.cassette_library_dir = "./test_dir/cassettes"
end
describe Hi8test do
it "doesn't work using Cossack::Client" do