Skip to content

Instantly share code, notes, and snippets.

View paulcsmith's full-sized avatar

Paul Smith paulcsmith

View GitHub Profile
@paulcsmith
paulcsmith / gist:4a9c014b5702e10ab904
Created January 14, 2015 22:42
SkyLabels Start SASS template
.sky-label {
input, textarea { /* How the input looks without focus or text */ }
label { /* How the input looks without focus or text */ }
}
.sky-label-focused, .sky-label-has-text {
input, textarea { /* How the inputs look while focused or with text (and blurred) */ }
label {}
}
defmodule AnnouncementChannelTest do
use ConstableApi.TestWithEcto, async: false
alias Phoenix.Socket
alias Phoenix.Socket.Message
alias ConstableApi.Repo
alias ConstableApi.Announcement
alias ConstableApi.AnnouncementChannel
test "announcements:index returns announcements with ids as the key" do
@paulcsmith
paulcsmith / gist:dcb8adb3749cfec00960
Created March 11, 2015 21:01
Nicer looking type
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
@paulcsmith
paulcsmith / comment_view.ex
Last active August 29, 2015 14:17 — forked from jeregrine/comment_view.ex
Rendering JSON with views
defmodule MyApp.CommentView do
use MyApp.Web, :view
@attributes ~W(id name inserted_at)
def render("index.json", %{data: comments}) do
for comment <- comments, do: render("show.json", %{data: comment})
end
def render("show.json", %{data: comment}) do
comment
@paulcsmith
paulcsmith / gist:2615513d0602915fb98b
Created March 19, 2015 21:27
Complex Ecto Queries with joins and deep preload
def with_sorted_comments do
from a in Announcement,
left_join: c in assoc(a, :comments),
left_join: u in assoc(c, :user),
order_by: [asc: c.inserted_at],
preload: [:interests, :user, comments: {c, user: u}]
end
"<?xml version=\"1.0\" encoding=\"utf-8\"?><cfdi:Comprobante xsi:schemaLocation=\"http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd\" version=\"3.2\" folio=\"22\" LugarExpedicion=\"NOGAL 10 , SAN JOSE DE LOS CEDROS, 05200, DELEGACION CUAJIMALPA, DISTRITO FEDERAL, MEXICO\" NumCtaPago=\"NO IDENTIFICADO\" TipoCambio=\"1.00\" Moneda=\"Peso Mexicano\" fecha=\"2014-01-29T20:41:07\" sello=\"gO/DyxBs7kneK2dRySKmKshc1ddFXj+XcoPUrlgHYNyGeeuXGHW81URpiy20wIMpUmtZf8yne+5+jHMTqachVghB4IRkJwUNiFNPmc5K/vxiY/VWzalzQtrkBKZh7LWs/yrinvoiP1H4h8t/yOsiw+8NRwSDfcV6g70b3jnZRKg=\" formaDePago=\"PAGO EN UNA SOLA EXHIBICION\" noCertificado=\"00001000000301474075\" certificado=\"MIIEdzCCA1+gAwIBAgIUMDAwMDEwMDAwMDAzMDE0NzQwNzUwDQYJKoZIhvcNAQEFBQAwggGKMTgwNgYDVQQDDC9BLkMuIGRlbCBTZXJ2aWNpbyBkZSBBZG1pbmlzdHJhY2nDs24gVHJpYnV0YXJpYTEvMC0GA1UECgwmU2VydmljaW8gZGUgQWRtaW5pc3RyYWNpw7NuIFRyaWJ1dGFyaWExODA2BgNVBAsML0FkbWluaXN0cmFjacOzbiBkZSBTZWd1cmlkYWQgZGUgbGEgSW5mb3JtYWNpw7NuMR8wHQYJKoZIhvcNAQkBFhBhY29kc0BzYXQuZ29iL
@paulcsmith
paulcsmith / view.ex
Created July 27, 2015 19:28
Nice way to automatically render with the correct action name
def render(conn, assigns \\ []), do: render(conn, action_name(conn), assigns)
@paulcsmith
paulcsmith / brunch-config.js
Created July 28, 2015 15:32
Using nice import syntax using Phoenix and Brunch
exports.config = {
// See http://brunch.io/#documentation for docs.
files: {
javascripts: {
joinTo: 'js/app.js',
// To use a separate vendor.js bundle, specify two files path
// https://github.com/brunch/brunch/blob/stable/docs/config.md#files
// joinTo: {
// 'js/app.js': /^(web\/static\/js)/,
// 'js/vendor.js': /^(web\/static\/vendor)/
defmodule MyApp.Fixtures do
alias MyApp.Repo
alias MyApp.User
def fixture(:user) do
%User{name: "Daniel Berkompas", email: "test@example.com"}
end
# Example: create(:user)
def create(record) do
So the proposed solution is to change production code to be "testable" and making production code to call Application configuration for every function call? This doesn't seem like a good option as it's including a unnecessary overhead to make something "testable".
It is improving the design of your code.
A test is a user of your API like any other code you write. One of the ideas behind TDD is that tests are code and no different from code. If you are saying "I don't want to make my code testable", you are saying "I don't want to decouple some modules" or "I don't want to think about the contract behind these components".
Just to clarify, there is nothing wrong with "not wanting to decouple some modules". You don't want to decouple every time you call the URI module, for example. But if we are talking about something as complex as an external API, a SSH connection or such, defining a explicit contract and passing the contract as argument is going to make your code wonders and make it easier to manage your