Skip to content

Instantly share code, notes, and snippets.

package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"time"
FROM golang:1.16
RUN mkdir -p /app
COPY cmd/ /app
COPY go.* /app
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -o service gitlab.com/gertjana/tiny/main.go
@gertjana
gertjana / main.go
Created August 8, 2021 15:51
small go webservice
package main
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
deltas = loop([], nil, measurements)
defp loop(acc, _, []), do: acc
defp loop(acc, nil, [head | tail]), do: loop(acc, head, tail)
defp loop(acc, prev, [head | tail]) do
diff = (head.value - prev.value) / diff_string_date(prev.date, head.date)
loop([diff | acc], head, tail)
end
deltas = loop([], nil, measurements)
defp loop(acc, prev, list) do
case list do
[] -> acc
[head | tail] when prev == nil -> loop(acc, head, tail)
[head | tail] ->
delta = (head.value - prev.value) / diff_string_date(prev.date, head.date)
loop([delta | acc], head, tail)
end
\frac{\frac{v_{x} \ -v_{n}}{t_{x} \ -t_{n}}}{1} =\frac{\frac{v_{1} -v_{0}}{t_{1} -t_{0}} \ +\ \frac{v_{2} \ -v_{1}}{t_{2} \ -t_{1}} \ ...\frac{v_{n} \ -\ v_{n-1}}{t_{n} -t_{n-1}}}{n}

Keybase proof

I hereby claim:

  • I am gertjana on github.
  • I am gertjan (https://keybase.io/gertjan) on keybase.
  • I have a public key ASA_yv5Ti4bFxCl8FQWowE-x2Q0MIpFnU2azMTvcu1MWwQo

To claim this, I am signing this object:

@gertjana
gertjana / ActorStream
Created December 15, 2014 19:42
Akka Stream based on an Actor
package com.thenewmotion.streams
import akka.stream.actor.ActorPublisher
import akka.stream.scaladsl._
import akka.actor.{Props, ActorSystem}
import akka.stream.FlowMaterializer
import scala.language.postfixOps
case class Tick()
@gertjana
gertjana / mapreduce_akka.scala
Created August 3, 2011 20:45
MapReduce example using Akka Actors
package net.addictivesoftware.scala.akkaactors
import akka.actor.{Actor, PoisonPill}
import Actor._
import akka.routing.{Routing, CyclicIterator}
import Routing._
import collection.mutable.{HashMap, Map}
import java.util.concurrent.CountDownLatch
@gertjana
gertjana / gist:1014284
Created June 8, 2011 11:53
Getting a list Of Authors for a User through liftweb's REST interface
Given the Following Mapper Data Model:
Author <- 1) -> Book <- 2) -> User
1) An Author can have more books while books can be written by multiple authors (N-N)
2) A user can own multiple books, while a book can have multiple owners (N-N)
note: When successfully authenticating in a user his API key is returned which is used in all other requests