Skip to content

Instantly share code, notes, and snippets.

View rklaehn's full-sized avatar

Rüdiger Klaehn rklaehn

  • Independent hacker
  • Transylvania, Romania
View GitHub Profile
@rklaehn
rklaehn / merge_sorted.rs
Last active October 30, 2019 08:32
Merge 2 sorted iterators
use std::iter::{Iterator, Peekable};
pub struct MergeSorted<A: Iterator, B: Iterator> {
a: Peekable<A>,
b: Peekable<B>,
}
impl<A: Iterator, B: Iterator> MergeSorted<A, B> {
fn new(a: A, b: B) -> MergeSorted<A, B> {
MergeSorted {
let msgpackLite = require('msgpack-lite');
let borc = require('borc');
let _ = require('lodash');
let { performance } = require('perf_hooks')
let arrays = _.times(100, (n) => {
return _.times(n, i => ({ i, a: [String(i * 1234), String(i * 1234), String(i * 1234), String(i * 1234)] }))
});
let encodedBORC = arrays.map(array => borc.encode(array));
@rklaehn
rklaehn / Results
Last active October 8, 2018 10:14
CBOR encoding performance
$ node benchmark2.js
= Encoding Time (ms) =
msgp.encode 9172.339491000399
borc.encode 20400.477496000007
json.stringify 9445.365290999413
= Decoding Time (ms) =
msgp.decode 121.99922000057995
borc.decodeFirst 383.22095499932766
json.parse 48.20755399949849
const enum Test { a = 'a' }
type Protocol = {
foo: { x: string };
bar: { y: number };
}
type WithTag<T> = {
[TKey in keyof T]: { type: TKey } & T[TKey]
}
type ToDiscriminatedUnion<P> = WithTag<P>[keyof P]
type Constructor<T> = {
@rklaehn
rklaehn / match.ts
Last active February 23, 2018 21:14
type Protocol = {
foo: { x: string };
bar: { y: number };
}
type Fold<T, U> = {
readonly [P in keyof T]: (value: T[P]) => U
}
type WithTag<T> = {
[TKey in keyof T]: { type: TKey } & T[TKey]
}
@rklaehn
rklaehn / ipfs-publish-remote.sh
Last active July 23, 2019 19:44
Publishing to ipfs/ipns by key
#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "usage:"
echo " ipfs-publish-remote.sh <keyname> <dir> <host>"
echo " example: ipfs-publish-remote.sh keyname output/rootdir user@ipfs.company.net"
exit 1
fi
KEYNAME=$1
DIR=$2
HOST=$3

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

package akkahttptest
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Route
import akka.stream.ActorMaterializer
import akka.http.scaladsl.server.Directives._
object UploadHandler extends App {
rklaehn@rklaehn-hp:~/projects_git/satmon3$ sbt satmonjavaservices/dependencyTree
[info] Loading project definition from /home/rklaehn/projects_git/satmon3/project
[info] Set current project to satmon3 (in build file:/home/rklaehn/projects_git/satmon3/)
[info] heavens-above:satmonjavaservices_2.11:3.1.75_33302eb [S]
[info] +-com.google.protobuf:protobuf-java:2.5.0 (evicted by: 2.6.1)
[info] +-com.google.protobuf:protobuf-java:2.6.1
[info] +-com.jgoodies:jgoodies-looks:2.7.0
[info] | +-com.jgoodies:jgoodies-common:1.8.1
[info] |
[info] +-com.typesafe.akka:akka-actor_2.11:2.3.13 [S]
// -Yno-predef
package collection
import scala.Predef.{???, println, implicitly}
trait Foreachable[T, U] {
def foreach(value: T, f: U ⇒ Any): Unit
}
trait Indexable[T, U] {
def apply(value: T, index: Int): U