Skip to content

Instantly share code, notes, and snippets.

# dispatch method. can be put in base controller
def op(klass)
logger.info "Params: ", params.to_h
obj = klass.new(params.to_h).register(:keystore, @keystore).register(:configstore, @configstore)
resp = obj.process!(self, @context)
rescue => e
logger.error e.message
raise e
end
require 'dry-struct'
require 'dry-initializer'
module Types
include Dry::Types.module
class ExtHash < ::Hash
def self.from_hash(hsh)
new.merge! hsh
end
require 'washroom'
washroom = WashroomPool.get
begin
washroom.use
ensure
washroom.flush
end
package main
import "log"
type EyeReq interface {
setI(int)
getI() int
}
type EyeTrait struct {
@adityagodbole
adityagodbole / verbose.md
Last active May 20, 2016 20:40
Verbose java?

One of the pet FUD items of Go programmers when it comes to Java bashing is the verbosity of the language.

Here is a real world comparison. This is function that takes the name of a text file which has one number on each line and returns an array of long/uint64 numbers, or raises exception/returns error on error.

    private static Long[] getNumbers(String filename) throws IOException {
 final Stream lines = Files.lines(Paths.get(filename));

Gilmour proxy spec

The control TCP port

Gilmour proxy listens for http requests on inet socket on a port it is configured to start with. The following routes are available on the control port.

:POST /nodes - Create a new upstream gilmour node

Request

Golang generics via using code generation using the C preprocessor

This post is a followup to a talk I gave at the Pune golang meetup on using the C pre-processor to generate code to implement a poor man's generics. If you want to skip the introduction, you can directly.

When Go came out, it was positioned as a better C++. However, Go does not have generics. And interfaces are not generics, no matter what anyone says. So I don't see people who use C++ templates, moving to Go. And by that I don't mean that I don't think they won't move; I have asked a lot of people who write C++ and they have said they are not moving because they need generics.

After being heavily influenced by SICP and having used dynamically typed languages like Ruby and Javascript, and to a lesser extent Java 8 and Haskell for the last 5 odd years, I was quite dissapointed that there was no simple way to express higher order process abstractions in Go. Sure it has first class functions. But in a stati

Over the last weekend I fiddled around a bit with the Go Programming Language. I had sort of written a few snippets here and there before this, while I was evaluating it and learning the basics. This was the first time I wrote more than a few hundred lines of code in Go. One of the unique features of Go is extremely lightweight concurrency primitives called goroutines (a play on coroutines). It also has first class communication mechanisms called channels which you can use to send data between these goroutines. These channels also double up as synchronisation mechanisms. By having goroutines and channels, go lends itself towards a “service oriented” design. You can model your entire process in terms of producers and consumers (and consumers+producers) and set it up to run concurrently. As opposed to object oriented design (static blobs of data manipulated by privileged sections of the code) or functional design (pure data being acted upon by pure functions resulting in a new state of the universe), you can mo

package main
import (
"errors"
"os"
"fmt"
"reflect"
"strconv"
)
func(a Blob, params interface{}) interface{} {
var data int
if params != nil {
data = params.(int)
}
val := a.(*myStruct)
return val.inc(data)
},