Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Tinio aptinio

  • Angeles City, Philippines
View GitHub Profile
@evancz
evancz / data-interchange.md
Last active Dec 8, 2020
Why do I have to write JSON decoders in Elm?
View data-interchange.md

A vision for data interchange in Elm

How do you send information between clients and servers? What format should that information be in? What happens when the server changes the format, but the client has not been updated yet? What happens when the server changes the format, but the database cannot be updated?

These are difficult questions. It is not just about picking a format, but rather picking a format that can evolve as your application evolves.

Literature Review

By now there are many approaches to communicating between client and server. These approaches tend to be known within specific companies and language communities, but the techniques do not cross borders. I will outline JSON, ProtoBuf, and GraphQL here so we can learn from them all.

@jessejanderson
jessejanderson / macros.md
Last active Oct 24, 2020
Don't Write Macros (but do learn how they work)
View macros.md
@timriley
timriley / _pagination.slim
Created Jan 12, 2016
Rodakase/ROM pagination
View _pagination.slim
nav.pagination
- unless first_page?
span.first
a href=url_for_page(1)
| « First
span.prev
a href=url_for_page(prev_page) rel="prev"
| ‹ Prev
- if prev_gap?
span.page.gap
View enum.rb
# for use by collection_select and friends, to link a human-readable label with a db-friendly symbolic value
# todo: ActiveRecord macros for setters (for allowing multiple values or just one)
# Usage:
# Table name: snacks
# id :integer
# ice_cream :string
# class Snack < ActiveRecord::Base
# FLAVORS = Enum.new [
# [:vanilla, "Vanilla"],
# [:chocolate, "Chocolate"],
@timruffles
timruffles / dyanmic_or_di_elixir.md
Last active Jun 11, 2020
Approaches to dependency-injection/dynamic dispatch in elixir
View dyanmic_or_di_elixir.md

In many production systems you'll want to have one module capable of talking to many potential implementations of a collaborator module (e.g a in memory cache, a redis-based cache etc). While testing it's useful to control which module the module under test is talking to.

Here are the approaches I can see. The two points that seem to divide the approaches are their tool-ability (dialyzer) and their ability to handle stateful implementations (which need a pid).

Passing modules

Modules are first class, so you can pass them in. Used in EEx, where passed module must implement a behaviour.