Skip to content

Instantly share code, notes, and snippets.

View tintoy's full-sized avatar

Adam Friedman tintoy

View GitHub Profile
@tintoy
tintoy / generate-rke-config.py
Last active January 19, 2023 01:12
Terraform - DigitalOcean droplet with Docker
#!/usr/bin/python
import click
import json
import yaml
from collections import defaultdict
from os import path
@tintoy
tintoy / ClientWSFactory.cs
Last active April 29, 2019 15:28
Kubernetes-compatible WebSockets on .NET Core 2.1
// This code "borrowed" (and then adapted) from corefx (2.0).
static class ClientWSFactory
{
/// <summary>
/// GUID appended by the server as part of the security key response.
///
/// Defined in the RFC.
/// </summary>
const string WSServerGuid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
@tintoy
tintoy / DecodeFromStream.cs
Last active February 27, 2018 22:20
Decode UTF-8 from stream (can handle characters that span buffer boundary)
StringBuilder lineBuilder = new StringBuilder();
Encoding encoding = Encoding.UTF8;
// A Decoder is stateful; it remembers if it's halfway through decoding a multi-byte character.
Decoder decoder = encoding.GetDecoder();
byte[] buffer = new byte[10];
int bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
while (bytesRead > 0)
@tintoy
tintoy / install-docker.sh
Last active February 13, 2018 21:11
Install Docker 1.12.6 and kubectl on Ubuntu
#!/bin/bash
set -euo pipefail
apt update
apt install -y --no-install-recommends apt-transport-https curl software-properties-common
apt install -y --no-install-recommends linux-image-extra-$(uname -r) linux-image-extra-virtual
curl -fsSL 'https://sks-keyservers.net/pks/lookup?op=get&search=0xee6d536cf7dc86e2d7d56f59a178ac6c6238f52e' | sudo apt-key add -
add-apt-repository "deb https://packages.docker.com/1.12/apt/repo/ ubuntu-$(lsb_release -cs) main"
apt update
@tintoy
tintoy / cloud.yml
Last active February 15, 2018 23:37
Salt setup
#
master_config: master
log_file: /var/log/salt/salt-cloud.log
log_level_logfile: debug
pki_dir: pki
# Influences the list_nodes_select function of cloud providers
query.selection:
- id
@tintoy
tintoy / HistoricalScheduling.cs
Last active December 13, 2019 16:03
Historical scheduling of events
using System;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
namespace HistoricalScheduling
{
static class Program
{
public static void Main()
@tintoy
tintoy / Rope.cs
Last active January 28, 2018 00:49
Rope-like data structure based on Span<T>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SpanString
{
public static class Rope
{
@tintoy
tintoy / IOExtensions.cs
Created January 19, 2018 09:03
IObservable for file-change notifications
using System;
using System.IO;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
/// <summary>
/// Extension methods for System.IO types.
/// </summary>
public static class IOExtensions
@tintoy
tintoy / MedDependencyResolver.cs
Last active November 20, 2017 19:33
Akka.NET and Microsoft.Extensions.DependencyInjection
using Akka.Actor;
using Akka.DI.Core;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Concurrent;
/// <summary>
/// An Akka.NET dependency resolver using Microsoft.Extensions.DependencyInjection.
/// </summary>
public class MedDependencyResolver
@tintoy
tintoy / td-agent.Dockerfile
Created November 15, 2017 04:24
Fluentd on Kubernetes for ASP.NET Core logging (via Serilog)
FROM gcr.io/google_containers/fluentd-elasticsearch:1.22
RUN apt-get update && \
apt-get install -y --no-install-recommends make gcc g++ libc6-dev ruby-dev && \
td-agent-gem install fluent-plugin-concat --version '~>1.0.0' --no-ri --no-rdoc && \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false make gcc g++ libc6-dev ruby-dev
# Copy the Fluentd configuration file for concatenating lines in docker logs.
COPY td-agent.conf /etc/td-agent/td-agent.conf