Skip to content

Instantly share code, notes, and snippets.

View stravid's full-sized avatar

David Strauß stravid

View GitHub Profile
@stravid
stravid / task.thor
Created November 13, 2012 12:18
Thor FTP deploy task
desc "deploy", "deploys the site via LFTP to the location specified in the environment"
def deploy
load_ftp_configuration
start_timestamp = Time.now.to_i
if system("lftp -e 'mirror -R -v #{ENV['PUBLIC_DIRECTORY']} #{ENV['FTP_TARGET_DIRECTORY']}; bye' -u #{ENV['FTP_USER']},#{ENV['FTP_PASSWORD']} #{ENV['FTP_SERVER']}")
puts "Deploy finished. (Duration: #{Time.now.to_i - start_timestamp} seconds)"
else
puts 'Deploy aborted, something went wrong.'
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
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}"
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
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 June 21, 2016 07:24
Ruby JSON API Stack

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

Tedian.ApplicationRoute = Ember.Route.extend
setupController: ->
controller = @controllerFor("sidebar")
controller.set "tasks", @store.find("task")
controller.set "projects", @store.find("project")
controller.set "timeEntries", @store.find("timeEntry")
Tedian.TimeEntry.findActive().then (timeEntry) ->
controller.set "activeTimeEntry", timeEntry
@stravid
stravid / application.controller.js
Last active December 20, 2015 10:31
Ember Data Auto-Update Test Case
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
@stravid
stravid / app.js
Last active December 20, 2015 08:49
Ember.js Beispiel Anwendung für Screenguide Artikel
App = Ember.Application.create();
App.Project = Ember.Object.extend({
title: null,
features: null,
estimateSum: function() {
var features = this.get('features');
return features.reduce(
function(total, feature) {
@stravid
stravid / cURL request
Last active October 16, 2015 08:39
Lotus JSON Body Parsing
curl 'http://localhost:2300/api/players' --data-binary '{"data":{"attributes":{"name":"David"},"type":"players"}}' --compressed
{"data":null}