Skip to content

Instantly share code, notes, and snippets.

@cobratbq
cobratbq / PingVerticle.java
Last active September 2, 2015 17:49
Implementation PingVerticle as provided by Vert.x as an example for integration testing. (See https://github.com/vert-x/vertx-maven)
/*
This is a simple Java verticle which receives `ping` messages on the event bus and sends back `pong` replies
*/
public class PingVerticle extends Verticle {
public void start() {
vertx.eventBus().registerHandler("ping-address", new Handler<Message<String>>() {
@Override
public void handle(Message<String> message) {
@cobratbq
cobratbq / ModuleIntegrationTest.java
Created September 2, 2015 17:51
Example integration test implementation for PingVerticle (See https://github.com/vert-x/vertx-maven)
import org.junit.Test;
import org.vertx.java.core.AsyncResult;
import org.vertx.java.core.AsyncResultHandler;
import org.vertx.java.core.Handler;
import org.vertx.java.core.eventbus.Message;
import org.vertx.java.core.http.HttpClientResponse;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.testtools.TestVerticle;
import org.vertx.testtools.VertxAssert;
@cobratbq
cobratbq / iota.go
Last active October 10, 2015 18:48
Example of using iota to define an enumeration (constants with sequential values)
package main
import "fmt"
type State uint
const (
StateCreated State = iota // 0
StateInitialized // 1
StateRunning // 2
@cobratbq
cobratbq / http2.go
Last active October 10, 2015 19:00
Sample from golang.org/x/net/http2/http2.go (https://github.com/golang/net/blob/master/http2/http2.go#L119)
type SettingID uint16
const (
SettingHeaderTableSize SettingID = 0x1
SettingEnablePush SettingID = 0x2
SettingMaxConcurrentStreams SettingID = 0x3
SettingInitialWindowSize SettingID = 0x4
SettingMaxFrameSize SettingID = 0x5
SettingMaxHeaderListSize SettingID = 0x6
)
@cobratbq
cobratbq / iota.go
Created October 10, 2015 18:53
An example of comparing variable with the constant's symbol name.
if state == StateStopped {
fmt.Println("Thingie has stopped.")
}
@cobratbq
cobratbq / http2.go
Last active October 10, 2015 18:59
Sample from golang.org/x/net/http2/http2.go (https://github.com/golang/net/blob/master/http2/http2.go#L57)
type streamState int
const (
stateIdle streamState = iota
stateOpen
stateHalfClosedLocal
stateHalfClosedRemote
stateResvLocal
stateResvRemote
stateClosed
@cobratbq
cobratbq / post.html
Last active November 12, 2015 21:13
Partial content of layouts/section/post.html
<div class="content container">
<h1>{{ .Title }}</h1>
<ul class="posts">
{{ range .Data.Pages }}
<li><span><a href="{{ .Permalink }}">{{ if .Draft }}[Draft]{{ end }} {{ .Title }}</a> <time class="pull-right post-list">{{ .Date.Format "Mon, Jan 2, 2006" }}</h4></time></span></span></li>
{{ end }}
</ul>
</div>
@cobratbq
cobratbq / ExpectationsExample.java
Last active December 21, 2015 14:26
Example 3: Third component using expectations
package thirdcomponent;
import java.math.BigDecimal;
import java.math.MathContext;
public class ExpectationsExample {
public static void main(String[] args) {
final BigDecimal one = BigDecimal.ONE;
final BigDecimal three = BigDecimal.valueOf(3L);
@cobratbq
cobratbq / UtilWithStatics.java
Last active December 21, 2015 14:23
Example 2: Object with statically defined requirement
package thirdcomponent;
import java.math.BigDecimal;
import java.math.MathContext;
public class UtilWithStatics {
// Predefined math context for use in calculation.
private final static MathContext C = MathContext.DECIMAL32;
@cobratbq
cobratbq / UtilNoState.java
Created December 21, 2015 14:21
Example 1: Util without state
package thirdcomponent;
import java.math.BigDecimal;
import java.math.MathContext;
public class UtilNoState {
public static void main(String[] args) {
System.out.println(calculate(BigDecimal.ONE,
BigDecimal.valueOf(3L), MathContext.DECIMAL32));