Skip to content

Instantly share code, notes, and snippets.

View toranb's full-sized avatar

Toran Billups toranb

View GitHub Profile
@toranb
toranb / leex_to_heex.ex
Last active July 27, 2022 21:56
inline conditional css comparison of leex and heex
##### phx live view 0.16 with leex
def render(assigns) do
~L"""
<button class="<%= if @foo && @bar && @baz do %>text-blue-600<% else %>text-red-600<% end %>">hello</button>
"""
end
##### phx live view 0.16 with heex -inline edition
@toranb
toranb / app.js
Created July 4, 2020 15:07 — forked from nicolasblanco/app.js
Stripe.js elements integration inside a Elixir LiveView (Bootstrap styles)
// Code handling the card payment
const payWithCard = function (stripe, card, clientSecret, liveView) {
stripe
.confirmCardPayment(clientSecret, {
payment_method: {
card: card,
},
})
.then(function (result) {
if (result.error) {
@toranb
toranb / jedi-for-python.txt
Created January 15, 2019 14:39
Python for go-to-definition
pip install jedi
then -in your vimrc
```
nmap <Leader>j :call InvokeJumpToByType()<CR>
function! InvokeJumpToByType()
let filetype=&ft
if filetype == 'python'
exe ':call jedi#goto_definitions()'
@toranb
toranb / postgres.txt
Created December 23, 2018 14:05
First time install of postgres on macOS Mojave
1) Install homebrew if you haven't already
https://brew.sh/
2) Install postgres
brew install postgresql
3) Start the database
@toranb
toranb / wait-for-redux.js
Last active November 1, 2018 21:13
custom ember helper to wait for redux to be in a given state
import { Promise } from 'rsvp';
import { next } from '@ember/runloop';
import { registerWaiter } from '@ember/test';
import { getContext } from '@ember/test-helpers';
export async function waitForRedux(key, value) {
return new Promise(async (resolve) => {
let counter = 1;
registerWaiter(() => counter === 0);
const { owner } = getContext();
@toranb
toranb / hydrate_state_from_filesystem.ex
Created October 28, 2018 17:39
Simple GenServer callback to create a map w/ {key, value} pairs by looking at the filesystem
@impl GenServer
def handle_call({:all}, _timeout, _state) do
{:ok, files} = :file.list_dir(@database)
state =
Enum.map(files, fn (key) ->
value =
case File.read(file_name(@database, key)) do
{:ok, contents} -> :erlang.binary_to_term(contents)
_ -> nil
end
@toranb
toranb / verbose-some.exs
Created October 14, 2018 17:39
My first implementation of some in elixir
defmodule MyEnum do
def some([], _func), do: []
def some([head | tail], func) do
case func.(head) do
true ->
true
false ->
case some(tail, func) do
true ->
true
@toranb
toranb / functions-in-elixir.exs
Created September 27, 2018 12:40
functions defs can have multiple implementations in elixir
defmodule Foo do
def my_func({name}) do IO.puts("#{name}") end
def my_func({name, number}) do IO.puts("#{name} #{number}") end
end
@toranb
toranb / pinned-values-as-params.exs
Last active September 27, 2018 13:04
showing how pinned values and pattern matching work in elixir
defmodule Robot do
def speak(name, phrase) do
fn
(^name) -> "hello! #{name}, #{phrase}"
(_) -> "sorry ... don't know this name"
end
end
end
@toranb
toranb / proposal.md
Created June 26, 2018 22:54
Over mocking under delivering

#Abstract

The Ember community has a strong testing culture, but advanced topics like the intersection of integration and isolation testing can be as confusing as they are controversial. To make matters worse we are often tricked into believing that a mock library has the answer to all of our problems, making it difficult to evaluate when to use mocks (or even avoid them).

This talk will give you a fresh perspective on the use and abuse of mock objects, explore why this topic is crucial for test suite reliability, and equip developers with strategies to make these distinctions without the guesswork.

#Details

For years now I've had varying degrees of success with mock objects but until recently I didn't have a narrative in which to tell the story of "good mock/bad mock"