Skip to content

Instantly share code, notes, and snippets.

View coryan's full-sized avatar

Carlos O'Ryan coryan

View GitHub Profile
@coryan
coryan / keybase.md
Created January 20, 2017 19:33
Connect my keybase.io id with my github id.

Keybase proof

I hereby claim:

  • I am coryan on github.
  • I am coryan (https://keybase.io/coryan) on keybase.
  • I have a public key whose fingerprint is A06E F208 44CE DA02 A216 58E5 7821 E6AA 1F16 C53C

To claim this, I am signing this object:

@coryan
coryan / create-gcp-vm.md
Last active July 7, 2017 15:12
How to create a GCP VM to compile JayBeams.

Sometimes I find it convenient to create a VM to compile or test JayBeams. I grew tired of point and clicking the commands are:

PROJECTID= ## Your project ID here
ZONE= ## A valid GCP zone here
VM= ## Name your VM here
gcloud compute instances create $VM --zone $ZONE \
  --machine-type "n1-standard-2" --subnet "default" \
  --maintenance-policy "MIGRATE" \
// Also available here:
// https://godbolt.org/z/CAmvFF
#include <functional>
#include <memory>
struct MyFunctor {
MyFunctor() : x(0) {}
MyFunctor(MyFunctor const& rhs) : x(1) {}
MyFunctor(MyFunctor&& rhs) : x(2) {}
@coryan
coryan / grpc_alarm_crasher.cc
Last active March 11, 2019 17:15
Demonstrates how gRPC alarms are not synchronized.
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
#include <benchmark/benchmark.h>
#include <functional>
#include <memory>
#include <utility>
struct Base {
virtual ~Base() = default;
virtual int exec(char*,int) = 0;
};
@coryan
coryan / Dockerfile
Created November 17, 2020 14:17
Compile google-cloud-cpp without gRPC
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@coryan
coryan / resumable_upload_with_curl.md
Last active March 11, 2021 02:14
Resumeable upload to GCS with metadata annotation

curl -i -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Length: 0" -H "Content-Type: text/plain" -H "x-goog-resumable: start" -H "x-goog-meta-key1: value1" "https://storage.googleapis.com/${BUCKET_NAME}/test-meta-key.txt"

HTTP/2 201 
content-type: text/plain; charset=utf-8
x-guploader-uploadid: [censored]
location: https://storage.googleapis.com/$BUCKET_NAME/test-meta-key.txt?upload_id=[censored]
content-length: 0
date: Thu, 11 Mar 2021 01:57:02 GMT
server: UploadServer
@coryan
coryan / repro.Dockerfile
Last active May 14, 2022 17:04
Reproduce gRPC + google-cloud-cpp storage crash
# syntax=docker/dockerfile:1.3-labs
# test using
# docker buildx build --progress plain -t test - <Dockerfile
FROM rockylinux:8
RUN dnf -y update
RUN dnf -y groupinstall "Development Tools"
RUN dnf -y install gcc-toolset-10-gcc curl
RUN dnf -y install gdb
RUN curl -sSL https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64 -o /usr/bin/bazel
@coryan
coryan / streaming_transcribe_coroutines.cc
Last active May 23, 2022 19:41
Code snippet showing C++ coroutines and Google Speech-to-Text
using RecognizeStream = google::cloud::AsyncStreamingReadWriteRpc<
google::cloud::speech::v1::StreamingRecognizeRequest,
google::cloud::speech::v1::StreamingRecognizeResponse>;
// Print the responses as they are received.
google::cloud::future<void> ReadTranscript(RecognizeStream& stream) {
while (true) {
auto response = co_await stream.Read();
// Terminate the loop if the stream is closed or has an error.
if (!response) co_return;