Skip to content

Instantly share code, notes, and snippets.

@miroswan
miroswan / di-is.go
Created May 11, 2021 23:00
Dependency Inversion and Interface Segregation
/*
This toy example explains how you can use dependency inversion and
interface segregation in Go. It allows your code to remain flexible,
unit testable, and better protected from upstream changes. In the
last case, if a library author decides to break their own code in
ways that do not fit your design, you have the opportunity to
impelement the interface yourself or simply wrap their code in a way
that suites you, all while not having to change a single line in your
existing code that depends on it since you own the interface.
@miroswan
miroswan / function-options.go
Created May 11, 2021 18:19
Functional Variadic Arguments as Options
package main
import (
"fmt"
"strings"
)
// consoleOptions is a private structure that contains
// the possible options for a Console. It's private so
// that consumers do not rely on its members. This allows
{:timestamp=>"2016-09-09T22:01:49.624000+0000", :message=>"Pipeline aborted due to error", :exception=>"LogStash::ConfigurationError", :backtrace=>["/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-input-kafka-2.0.9/lib/logstash/inputs/kafka.rb:129:in `register'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/pipeline.rb:330:in `start_inputs'", "org/jruby/RubyArray.java:1613:in `each'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/pipeline.rb:329:in `start_inputs'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/pipeline.rb:180:in `start_workers'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/pipeline.rb:136:in `run'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/agent.rb:491:in `start_pipeline'"], :level=>:error}
{:timestamp=>"2016-09-09T22:01:52.629000+0000", :message=>"stopping pipeline", :id=>"main"}
{:timestamp=>"2016-09-0
@miroswan
miroswan / Vagrantfile
Last active August 29, 2015 14:19
Install salt master and two minions w/ Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Install landrush if it's not installed. This bash script is saved
# into a Ruby var. Landrush allows the nodes to reference each other
# by hostname.
check_landrush = <<CHECK_LANDRUSH
#!/bin/bash
plugins="$(vagrant plugin list)"