Skip to content

Instantly share code, notes, and snippets.

View stravid's full-sized avatar

David Strauß stravid

View GitHub Profile
@stravid
stravid / 1.rb
Last active August 29, 2015 14:03
Invoice Push Update Application
require 'sinatra'
require 'json'
current_invoice_id = 0
invoices = {}
before do
content_type :json
end
@stravid
stravid / number-to-currency-test.js
Created July 24, 2014 12:07
Testing Handlebars Helper with Ember CLI
import numberToCurrency from '../../helpers/number-to-currency';
module('number-to-currency Handlebars Helper');
test('convert invalid input to zero', function() {
equal('€ 0,00', numberToCurrency._rawFunction(null));
equal('€ 0,00', numberToCurrency._rawFunction(undefined));
});
test('handle single digit input', function() {
---
- name: apply common configuration to all servers
hosts: all
remote_user: deployer
sudo_user: deployer
sudo: yes
vars:
- ansible_sudo_pass: secret
tasks:
- debug: msg={{ansible_sudo_pass}}
@stravid
stravid / Brocfile.js
Last active August 29, 2015 14:06
Creating a Datepicker Ember Addon
// Rest of the file
app.import('bower_components/momentjs/moment.js');
app.import('bower_components/pikaday/pikaday.js');
app.import('bower_components/pikaday/css/pikaday.css');
module.exports = app.toTree();
require 'rubygems'
require 'bundler/setup'
require 'rom'
require 'rom-sql'
ROM.setup(:sql, 'postgres://localhost/datsu_development')
class Players < ROM::Relation[:sql]
register_as :players
dataset :players
require 'rubygems'
require 'bundler/setup'
require 'rom'
require 'rom-sql'
ROM.setup(:sql, 'postgres://localhost/datsu_development')
class Players < ROM::Relation[:sql]
register_as :players
dataset :players
require 'rubygems'
require 'bundler/setup'
require 'rom'
require 'rom-sql'
ROM.setup(:sql, 'postgres://localhost/datsu_development')
class Players < ROM::Relation[:sql]
register_as :players
dataset :players
@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}
@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 / 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