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 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
View posts_controller.rb
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def show
@post = Post.find(params[:id])
event = {
post_id: @post.id,
ip_address: request.remote_ip,
timestamp: Time.now,
}
@dasch
dasch / README.md
Last active Jul 7, 2017
Event Sourcing Example
View README.md

The rules of the reservation of a train are the following:

  • We cannot reserve seats in a train if it bumps up the occupancy over 70%
  • All the reserved seats should be in the same coach (we cannot separate families)
  • Preferably, we should avoid bumping the occupancy of a coach over 80%
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