Skip to content

Instantly share code, notes, and snippets.

@erikbozic
erikbozic / README.md
Last active July 9, 2020 21:27
An example of how to implement a server that caches data

Server returning cached data

An example of how to implement a server that caches data

Goals:

  • The cache has a TTL
  • Each request must be handled as fast as possible, while returning a fully valid response
  • Consider the updateCache function as expensive, so must avoid unnecessary calls.
  • Don't block startup (assume the application does other stuff and that must be up asap)
  • Be correct (no data races)
@erikbozic
erikbozic / Generate POCOs.groovy
Created May 7, 2020 16:51
Groovy script to generate POCO from table definition in Jetbrains' products
import com.intellij.database.model.DasTable
import com.intellij.database.model.ObjectKind
import com.intellij.database.util.Case
import com.intellij.database.util.DasUtil
typeMapping = [
(~/(?i)^bit$/) : "bool",
(~/(?i)^tinyint$/) : "byte",
(~/(?i)^uniqueidentifier|uuid$/) : "Guid",
(~/(?i)^int|integer|number$/) : "int",

Keybase proof

I hereby claim:

  • I am erikbozic on github.
  • I am erikbozic (https://keybase.io/erikbozic) on keybase.
  • I have a public key ASBkiZqxFjTX1bxXzyNTyL7sYVTWsLeWcqgIlAtYNc2K5go

To claim this, I am signing this object:

FROM golang:1.13 AS build
WORKDIR /src
# Copy go.mod and go.sum (if exists) to download all dependencies (this is cached if go.mod and go.sum don't change)
COPY go.mod go.sum* .
RUN go mod download
# Copy everything else to actually build the project
COPY . .
# Build project to build folder (also copy config files etc... to this folder)
@erikbozic
erikbozic / Dockerfile
Last active September 14, 2019 09:54
Code for stack overflow question 57933340
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish so_5793340.csproj -c Release -o /app/out
# Build runtime image
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)