Skip to content

Instantly share code, notes, and snippets.

@0sc
0sc / sample-sarama-producer.go
Last active August 22, 2016 22:48
Code snippet for sarama producer described here:
//addresses of available kafka brokers
brokers := []string{'localhost:9201'}
//setup relevant config info
config := sarama.NewConfig()
config.Producer.Partitioner = sarama.NewRandomPartitioner
config.Producer.RequiredAcks = sarama.WaitForAll
producer, err := sarama.NewSyncProducer(brokers, config)
topic := "kafka-topic-for-the-message" //e.g create-user-topic
partition := -1 //Partition to produce to
msg := "actual information to save on kafka" //e.g {"name":"John Doe", "email":"[email protected]"}
message := &sarama.ProducerMessage{
Topic: topic,
Partition: partition,
Value: sarama.StringEncoder(msg),
}
partition, offset, err := producer.SendMessage(message)
//addresses of available kafka brokers
brokers := []string{'localhost:9201'}
consumer, err := sarama.NewConsumer(brokers, nil)
topic := "topic-to-subscribe-to" //e.g. user-created-topic
partitionList := consumer.Partitions(topic) //get all partitions
messages := make(chan *sarama.ConsumerMessage, 256)
initialOffset := sarama.OffsetOldest //offset to start reading message from
for _, partition := range partitionList {
pc, _ := consumer.ConsumePartition(topic, partition, initialOffset)
go func(pc sarama.PartitionConsumer) {
for message := range pc.Messages() {
messages <- message //or call a function that writes to disk
}
@0sc
0sc / manifest.yml
Created September 11, 2016 18:10
bluemix tutorial sample manifest.yml file
applications:
- path: .
memory: 256M
instances: 1
domain: eu-gb.mybluemix.net
name: bluemix-blog
host: bluemix-blog
disk_quota: 1024M
command: rake db:migrate && bin/rails server -p $PORT -e $RAILS_ENV
services:
@0sc
0sc / simple-auth.cr
Created January 8, 2017 16:35
Main code for handling google oauth request for k8tes tutorial
require "http/client"
require "./simple-auth/*"
module Simple::Auth
macro default_layout_view_for(view)
render "src/views/#{{{view}}}.ecr", "src/views/layouts/default.ecr"
end
get "/" do
default_layout_view_for "index"
@0sc
0sc / ingress.yaml
Created January 8, 2017 18:01
Ingress deployment for simple auth tutorial
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: simple-auth-ingress
spec:
backend:
serviceName: default-http-backend
servicePort: 80
rules:
- host: simple-auth.me
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-tutorial
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
backend:
serviceName: default-http-backend
servicePort: 80
@0sc
0sc / docker-compose.yml
Created March 12, 2017 11:36
parallelising RSpec test with docker
version: '2'
services:
feature_tests:
image: project/image:ci
container_name: features_tests
command: bash -c "service postgresql start; sleep 1m; xvfb-run -a rspec spec/features"
controller_tests:
image: project/image:ci
container_name: controller_tests
@0sc
0sc / circle.yml
Last active March 12, 2017 11:44
parallelising RSpec test
machine:
pre:
- curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.10.0
services:
- docker
dependencies:
override:
- sudo pip install --upgrade docker-compose
- docker build --rm=false -t project/image:ci .
database: