Skip to content

Instantly share code, notes, and snippets.

Table products {
name product
Indexes {
(name) [pk]
}
}
Table organizations {
id uuid
name text
@dchw
dchw / grpc.go
Created July 26, 2022 00:18
Prototype streaming healthcheck?
func monitorHealth(ctx context.Context, cc *grpc.ClientConn, cancelConn func()) {
defer cancelConn()
defer cc.Close()
healthClient := grpc_health_v1.NewHealthClient(cc)
wc, err := healthClient.Watch(ctx, &grpc_health_v1.HealthCheckRequest{})
if err != nil {
bklog.G(ctx).
WithError(err).
@dchw
dchw / grpc.go
Last active July 26, 2022 00:16
Buildkit monitorHealth with debug logs
func monitorHealth(ctx context.Context, cc *grpc.ClientConn, cancelConn func()) {
defer cancelConn()
defer cc.Close()
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
healthClient := grpc_health_v1.NewHealthClient(cc)
for {
select {
package main
import (
"encoding/base64"
"flag"
"fmt"
"log"
"net/http"
"net/url"
"os"
@dchw
dchw / spinnaker-session-token-ms.sh
Last active September 7, 2018 22:28
Get a Spinnaker session cookie when using MS OAuth
echo "Authorizing with MS"
curl -s --request POST \
--url https://login.microsoftonline.com/$AZURE_TENANT_ID/oauth2/token \
--header 'content-type: application/x-www-form-urlencoded' \
--data-urlencode "grant_type=password" \
--data-urlencode "resource=https://graph.windows.net" \
--data-urlencode "client_id=$SPINNAKER_CLIENT_ID" \
--data-urlencode "password=$BUILD_PASSWORD" \
--data-urlencode "client_secret=$SPINNAKER_CLIENT_SECRET" \
--data-urlencode "username=$BUILD_USER" \
@dchw
dchw / CastingByExample1.cs
Last active August 29, 2015 14:00
An extension method to enamble casting by example in C#.
public static class ObjectExtensions
{
public static T CastByExample<T>(this object o, T example)
{
return (T) o;
}
}
void Main()
{
@dchw
dchw / OperatorOverloading2.cs
Created May 1, 2014 06:47
An object that is always true
public class AlwaysTrue
{
public static bool operator true(AlwaysTrue alwaysTrue)
{
return true;
}
public static bool operator false(AlwaysTrue boyfriend)
{
return true;
@dchw
dchw / OperatorOverloading3.cs
Last active August 29, 2015 14:00
Solving a paradox with C#
void Main()
{
var answer = new ThisIsTrue();
if(answer)
Console.WriteLine("Paradox ain't nuthin for .NET");
}
public class ThisIsTrue
{
@dchw
dchw / OperatorOverloading1.cs
Created May 1, 2014 06:33
Using the true/false overrides to easily choose people to marry.
void Main()
{
var boyfriends = new List<Boyfriend>
{
new Boyfriend
{
LovesMe = true,
LovesMeNot = false,
EntriesOnRapSheet = int.MaxValue,
Name = "Ima Baddude"
@dchw
dchw / RoundingExamplesOutput.txt
Created April 12, 2014 08:57
LINQPad output from RoundingExamples.cs.
Banker|Away|Convert|Cast
0 | 1 | 0 | 0
2 | 2 | 2 | 1
2 | 3 | 2 | 2
4 | 4 | 4 | 3
4 | 5 | 4 | 4