Skip to content

Instantly share code, notes, and snippets.

View charithe's full-sized avatar

Charith Ellawala charithe

View GitHub Profile
package mapbench
import (
"sync"
log "github.com/sirupsen/logrus"
)
type MapBench struct {
objects sync.Map
@charithe
charithe / index.erl
Created March 5, 2017 15:15
FutureLearn Erlang MOOC Week 2: Indexing a file
-module(index).
-export([do_index/1, show_file_contents/1]).
%% Main entrypoint
%% In the Erlang shell, execute: rp(index:do_index("path_to_file")).
%% Reads the contents of the file using the provided functions, builds up a map
%% of words to their locations, compresses the locations to ranges and returns a
%% list sorted in alphabetical order
do_index(Name) ->
Lines = get_file_contents(Name),
@charithe
charithe / curry.exs
Created January 4, 2015 15:10
Elixir Currying With Macros
defmodule Curry do
defmacro defcurry({func_name, _func_ctx, args}, do: body) do
num_args = Enum.count(args)
if num_args - 1 >= 1 do
new_args = Enum.take(args, num_args - 1)
quote do
def unquote(func_name)(unquote_splicing(args)) do
unquote(body)
end
@charithe
charithe / client.go
Created March 26, 2017 16:28
GRPC Opentracing Interceptors
package otgrpc
import (
context "golang.org/x/net/context"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/opentracing/opentracing-go/log"
"google.golang.org/grpc"
)
@charithe
charithe / x_test.go
Created June 22, 2023 09:33
Viewing Cerbos test server logs
package x_test
import (
"context"
"testing"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
"github.com/cerbos/cerbos/client"