Skip to content

Instantly share code, notes, and snippets.

View tricon's full-sized avatar

David Aaron Fendley tricon

View GitHub Profile
@h4cc
h4cc / struct_matching.exs
Created July 28, 2017 07:34
Example how matching on elixir structs will make code more robust and refactorable with less possible errors at runtime.
# This is our struct with some fields.
defmodule User do
defstruct name: "julius", role: :user
end
defmodule UserManager do
# Matching on %User{} will ensure we will get a user.
@iloveitaly
iloveitaly / capybara_fill_stripe_elements.rb
Created March 4, 2017 21:21
Fill in a Stripe Elements (https://stripe.com/docs/elements) credit card field using capybara
def fill_stripe_elements(card)
using_wait_time(15) { within_frame('stripeField_card_element0') do
card.to_s.chars.each do |piece|
find_field('cardnumber').send_keys(piece)
end
find_field('exp-date').send_keys("0122")
find_field('cvc').send_keys '123'
find_field('postal').send_keys '19335'
end }
@roadrunner2
roadrunner2 / 0 Linux-On-MBP-Late-2016.md
Last active April 20, 2025 18:57
Linux on MacBook Pro Late 2016 and Mid 2017 (with Touchbar)

Introduction

This is about documenting getting Linux running on the late 2016 and mid 2017 MPB's; the focus is mostly on the MacBookPro13,3 and MacBookPro14,3 (15inch models), but I try to make it relevant and provide information for MacBookPro13,1, MacBookPro13,2, MacBookPro14,1, and MacBookPro14,2 (13inch models) too. I'm currently using Fedora 27, but most the things should be valid for other recent distros even if the details differ. The kernel version is 4.14.x (after latest update).

The state of linux on the MBP (with particular focus on MacBookPro13,2) is also being tracked on https://github.com/Dunedan/mbp-2016-linux . And for Ubuntu users there are a couple tutorials (here and here) focused on that distro and the MacBook.

Note: For those who have followed these instructions ealier, and in particular for those who have had problems with the custom DSDT, modifying the DSDT is not necessary anymore - se

@tiagopog
tiagopog / account.ex
Last active April 11, 2019 06:15
Elixir - Processes (spawn, send, receive, Async, Agent)
defmodule Account do
defstruct name: nil, amount: 0
def start(%Account{} = account) do
spawn fn -> run(account) end
end
defp run(account) do
account = receive do
{:debit, value} -> %{account | amount: account.amount - value}
@bitwalker
bitwalker / config.ex
Created July 19, 2016 23:00
Useful config wrapper for Elixir
defmodule Config do
@moduledoc """
This module handles fetching values from the config with some additional niceties
"""
@doc """
Fetches a value from the config, or from the environment if {:system, "VAR"}
is provided.
An optional default value can be provided if desired.
@subfuzion
subfuzion / curl.md
Last active April 19, 2025 09:46
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@scottsb
scottsb / casesafe.sh
Last active January 16, 2024 08:47 — forked from Hais/workspace.sh
Create and manage a case-sensitive disk-image on macOS (OS X).
#!/bin/bash
# ---------------------------------------------------------
# Customizable Settings
# ---------------------------------------------------------
MOUNT_POINT="${CASE_SAFE_MOUNT_POINT:-${HOME}/casesafe}"
VOLUME_PATH="${CASE_SAFE_VOLUME_PATH:-${HOME}/.casesafe.dmg.sparseimage}"
VOLUME_NAME="${CASE_SAFE_VOLUME_NAME:-casesafe}"
VOLUME_SIZE="${CASE_SAFE_VOLUME_SIZE:-60g}"
@danhper
danhper / waterfall.ex
Created January 16, 2016 03:17
Avoiding conditional assignments in Elixir
defmodule Waterfall do
def conditional_chain(value, []), do: value
def conditional_chain(value, [{condition, fun}|rest]) when is_function(fun) do
value = if condition,
do: apply_fun(fun, value, condition),
else: value
conditional_chain(value, rest)
end
defp apply_fun(fun, value, condition) when is_function(fun) do
@fishcakez
fishcakez / simple_sup.ex
Last active March 22, 2018 17:28
Examples of supervision trees for `:simple_one_for_one` supervisors
defmodule SimpleSup do
@moduledoc """
This file shows methods for starting a configurable number of children under
a `:simple_one_for_one` supervisor.
When the supervision tree is first started all methods behave the same, `size`
children are started and the `:starter` returns `:ignore`. However if the
restart limit for those children is reached the `:simple_one_for_one`
supervisor will be restarted and then the `:starter`. It is possible that the
`:simple_one_for_one` is restarted successfully but the `:starter` fails to
@anonymoussc
anonymoussc / README.md
Created August 7, 2015 10:12
AngularJS custom directives animations

##AngularJS custom directives animations

$animate method's signatures:

$animate.addClass(element, className); $animate.removeClass(element, className);

Both functions receive the element parameter that will have a class added or removed and the className class that will be used and return a promise that is resolved once the animation has completed itself or has been cancelled.