Skip to content

Instantly share code, notes, and snippets.

View amukherj's full-sized avatar

Arindam Mukherjee amukherj

View GitHub Profile

Expression classes

Code for the BufferOwner class is here: http://coliru.stacked-crooked.com/a/0b21daacd5dff5b4

lvalue expression:

Any expression in a given scope which is associated with addressable memory that is valid in that scope.

// Example 1:
{
  int x;

foo(x); // x is an lvalue expression

@amukherj
amukherj / client.go
Last active April 21, 2021 12:50
HTTPS with client authentication using Go
package main
// Code copied from open source repos and customized
import (
"crypto/tls"
"crypto/x509"
"flag"
"io/ioutil"

Setting up repos of .deb packages for Ubuntu may not be something people need to do often on their own laptops. But I was recently doing something where it made sense. I was setting up a kubernetes cluster and wanted to automate the whole process using vagrant and ansible. This meant that each time a VM would be spun up, I would add apt repositories to it and then install docker.io, kubeadm, kubectl, kubelet, and kubernetes-cni packages. All of these VMs were to be on my laptop, and each time they'd reach out to google's or docker's repos to pull these packages in. A sum total of around 70 MB isn't big but I could be spinning up tens of VMs over the course of my experiments and a fresh download off the web is a terribly inefficient use of bandwidth (certainly here in India). So I wanted to setup an apt repository locally on the host laptop which runs Ubuntu 16.04 (xenial).

The plan

On the host: What we need to do is to run a web server (Apache2 works fine) that serves a directory with the packages tha

The Callback-Resume pattern

The callback-resume pattern is used to leverage Ruby fibers for async-IO tasks. You can avoid callback nesting a la Node, and having to manually manage all the context and state from one callback to another.

You can get the key concepts about Ruby fibers from here:

  1. [The best description of Ruby fiber] (lee.hambley.name/2012/06/19/the-best-description-of-a-ruby-fiber.html)
  2. [Ruby Fiber documentation] (ruby-doc.org/core-2.2.0/Fiber.html)

This tutorial teaches some useful techniques involving streams that let you employ them in a much wider set of uses.

Using flatMap to merge sequences

Using Optional effectively

Creating streams from iterators

Code Notes

Headers

folly/Executor.h folly/futures/ThreadedExecutor.h folly/futures/ScheduledExecutor.h folly/futures/QueuedImmediateExecutor.h folly/futures/InlineExecutor.h folly/futures/ManualExecutor.h

Brief steps for building Seastar

Building seastar from source:

$ git clone https://github.com/scylladb/seastar.git
$ cd seastar
$ vi doc/building-ubuntu.md    # or the appropriate file
$ # install all pre-requisites, not boost if you already have
$ ./configure.py --cflags "-I /opt/boost/include" --ldflags "-L /opt/boost/lib"  # etc.

$ vi build.ninja # and then :s^-Werror ^^g and save

This is a short tutorial on converting JSON to objects of Java classes (deserialization) and back (serialization), using Java. The Jackson library, one of the more popular JSON libraries used in Java, provides a very elegant way to do this using annotations and reflection.

Basic deserialization and serialization

Imagine you have some JSON describing a book in your library. How would you write a Book class that can be deserialized from this JSON?

{
  "title": "The Linux Programming Interface",
  "author": "Michael Kerrisk",
  "publisher": "No Starch Press",

"isbn": "978-1-59327-220-3"