Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
LOOKING INTENTLY INTO THE VOID

Daniel Schierbeck dasch

💭
LOOKING INTENTLY INTO THE VOID
View GitHub Profile
View ruby-kafka-stream.rb
class ParseEntries
def process(message)
entry = JSON.parse(message.value)
[entry]
end
end
class CombineEntries
def initialize
@open_transactions = {}
@dasch
dasch / Kafka.elm
Last active Aug 7, 2021
Mock stream processing API in Elm
View Kafka.elm
module Kafka exposing (..)
type alias KafkaRecord =
{ topic : String
, partition : Int
, offset : Int
, key : Maybe String
, value : Maybe String
}
View hello_consumer.rb
# app/consumers/hello_consumer.rb
class HelloConsumer < Racecar::Consumer
subscribes_to "some-topic"
def process(message)
puts "Received message: #{message.value}"
end
end
View App.elm
import Sql
import Sql.Param
findArticleById : Int -> Result Sql.Error Article
findArticleById id =
let
query =
"SELECT articles.id, articles.title, article.body WHERE articles.id = :id LIMIT 1"
in
Sql.queryWithParams query [ ("id", Sql.Param.int id) ]
View autocomplete.rb
require 'redis'
# Search query autocompletion based on http://oldblog.antirez.com/post/autocomplete-with-redis.html
class Autocomplete
# Expire the completion database for a scope after 30 days with no new data.
TTL = 60 * 60 * 24 * 30
def initialize(redis = Redis.new)
@redis = redis
end
View SqlSchema.elm
module SqlSchema exposing (..)
type SqlType
= SqlInt
| SqlString
type Table =
Table { name : String, fields : List FieldSpec }
type FieldSpec =
@dasch
dasch / Bencode.Parse.elm
Last active Nov 21, 2018
Monad syntax in Elm
View Bencode.Parse.elm
module Bencode.Parse exposing (parseString, Value)
import Parser exposing (Parser)
import Dict exposing (Dict)
type Value
= BencString String
| BencInt Int
| BencList (List Value)
| BencDict (Dict String Value)
View Makefile
# Distributed build system using Makefile-esque syntax.
base:
FROM ruby:2.4.1
bundle: base
ADD Gemfile Gemfile.lock vendor/
RUN bundle install
assets: base
View Monoids.elm
type Product = Product Integer
instance Monoid Product where
empty : Product
empty = Product 1
add : Product -> Product -> Product
add (Product x) (Product y) = Product (x * y)
View event_log.rb
module EventLog
AVRO = AvroTurf.new(schemas_path: "app/schemas/")
def self.publish(event_name, payload = {})
data = AVRO.encode(payload, schema_name: event_name)
DeliveryBoy.deliver(data, topic: event_name)
end
end