Skip to content

Instantly share code, notes, and snippets.

@laracasts
laracasts / ApiTester.php
Last active August 29, 2015 13:58
Example
<?php
use Faker\Factory as Faker;
abstract class ApiTester extends TestCase {
/**
* @var int
*/
protected $times = 1;
@jamesarosen
jamesarosen / ember-data-notes.md
Last active October 9, 2016 17:55
Ember-Data Relationships and Legacy APIs

This post is one in a series on converting a Backbone app to Ember. See also Ember-Data Notes.

Recently, our team has been trying to get Ember-Data to work with an API that does not conform to the json:api standard. The experience has been mostly good, but we've really struggled with the relationships. We have a Customer model that has many pastInvoices and a single monthToDateInvoice. The URL for past invoices is /billing/invoice?explicit_customer_id={{customerId}}; for month-to-date, it's /billing?no_list=true&explicit_customer_id={{customerId}}. The JSON that the API returns for a customer does not include any link to those URLs.

First Attempt: InvoiceAdapter

Our first attempt was to create an InvoiceAdapter that understood how to fetch invoices from those URLs:

// app/billing/invoices/adapter.js:
@Sweet-Bob
Sweet-Bob / adapters-post.js
Created August 11, 2016 18:03
[Ember.js] Custom API request
import RESTAdapter from 'ember-data/adapters/rest';
export default RESTAdapter.extend({
/**
* @param {DS.Model} model
* @param {JSON} serializedCommentData
* @returns {*}
*/
postComment(model, serializedCommentData) {
@coreyhaines
coreyhaines / UserAlert.elm
Created January 27, 2017 22:18
User Alerts
module Shared.UserAlert exposing (UserAlert, Msg, show, startShowAlertAnimation, startHideAlertAnimation, default, update, view)
import Helpers exposing (classes)
import Shared.Animation as Animation
import Html exposing (Html, div, span, text)
import Html.Attributes exposing (class)
import Task
type UserAlert
@nqthqn
nqthqn / Ports.elm
Created August 30, 2017 19:28
Porting to Js
port module Ports exposing (..)
import Json.Encode
type alias Key =
String
type alias Value =
@maxhoffmann
maxhoffmann / Main.elm
Last active February 8, 2018 23:57
Token HTTP Authentication in Elm
import Html.App as Html
import Html exposing (..)
import Html.Events exposing (..)
import Task
import Http
import Json.Decode as Json exposing ((:=))
-- Model
@gampleman
gampleman / Collection.elm
Created March 30, 2018 09:44
A module that abstracts over common collection types
module Collection
exposing
( Collection
, isEmpty
, length
, head
, tail
, take
, drop
, slice
@developit
developit / example.js
Last active December 25, 2018 22:01
mongoose-resource
import mongooseResource from '../lib/mongoose-resource';
import Foo from '../models/foo'; // a mongoose Model
export default mongooseResource('foo', Foo);
# supervisor
#
# Author: Günter Grodotzki <gunter@grodotzki.co.za>
# Version: 2015-04-25
#
# - set param "SUPERVISE=enable" to activate
# - chmod +x supervise.sh
#
packages:
yum:
@rupertlssmith
rupertlssmith / GameState.elm
Last active July 21, 2023 01:09
Exploring State Machines with phantom types in Elm
module GameState
exposing
( Game(..)
, GameDefinition
, PlayState
, loading
, updateGameDefinition
, updatePlayState
, updateScore
, toReady