Skip to content

Instantly share code, notes, and snippets.

David Strauß stravid

Block or report user

Report or block stravid

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stravid
stravid / child-machine.js
Last active Aug 12, 2019
Statechart Parent Child Activity Example
View child-machine.js
const { Machine } = XState;
export default Machine({
id: 'child',
initial: 'present',
context: {
name: undefined
},
states: {
present: {
View SketchSystems.spec
Pre-Match*
start match -> Match
Match
Starting Order*
play -> Game
Game
Running?*
another dart can be thrown? -> During
no dart can be thrown? -> After
During
View web.rb
class Web < Roda
def initialize(database_url:)
@database_url = database_url
end
route do |r|
r.root do
"Configured database URL: #{@database_url}"
end
end
View projection_pool_demo.rb
require "rubygems"
require "bundler/setup"
require "concurrent"
tasks = 10.times.map do |s|
Concurrent::TimerTask.new(execution_interval: 1) do
sleep s
puts "s: #{s}\n"
end
end
View client.rb
require "socket"
server_ip = "192.168.1.14"
client_ip = "192.168.1.5"
server_port = 22040
server_socket = UDPSocket.new
server_socket.connect(server_ip, server_port)
name = "Schorsch-Klaus-David-#{rand}"
View gist:6ae2a13b8c1edd2527169ebe0b14bf45
Possible tasks I have a hard time mapping to resources.
- Issuing an invoice
- Completing some kind of sports match
- Advancing an item in a defined process
- Lock/Release an item (to prevent tampering by others)
- Move an upload from temporary to permanent storage
View example.rb
module BaseCommand
module ClassMethods
def schema(&block)
@schema = Dry::Validation.Form(&block)
end
def build(data)
result = schema.call(data)
if result.success?
@stravid
stravid / README.md
Last active Jun 21, 2016
Ruby JSON API Stack
View README.md

Ruby JSON API Stack

What is this? I'm a little bugged out by all current approaches that are available to build JSON API APIs. I'm writing all this down to help me figure out what I want and how to accomplish it.

There are basically two sides, reading data and writing data. There are also a few parts of the stack that can be generalized. On the other side there are also parts where I think generalization is harmful.

Things like transforming parameters from dasherized to snake case, and serializing an object graph to JSON can be kept pretty generic. The thing I'm not so sure about on the read side is handling query parameters like included, fields, sort, filter, page and so on. For example using JSONAPI::Resources gives you the query parameter handling out of the box. On the other side I think it's impossible to deal with associations if you don't use the Active Record pattern and/or have 1:1 mapping between API resources and models.

On the write

@stravid
stravid / application.controller.js
Last active Dec 20, 2015
Ember Data Auto-Update Test Case
View application.controller.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
@stravid
stravid / cURL request
Last active Oct 16, 2015
Lotus JSON Body Parsing
View cURL request
curl 'http://localhost:2300/api/players' --data-binary '{"data":{"attributes":{"name":"David"},"type":"players"}}' --compressed
{"data":null}
You can’t perform that action at this time.