Skip to content

Instantly share code, notes, and snippets.

View gamache's full-sized avatar
🤙

pete gamache gamache

🤙
View GitHub Profile
@gamache
gamache / safe_task.ex
Created March 24, 2016 19:25
SafeTask proof of concept: make a Task's raises, throws, and exits happen locally
defmodule SafeTask do
def async(func) do
safe_func = fn ->
try do
{:ok, func.()}
rescue
e -> {:error, e}
catch
:exit, x -> {:exit, x}
t -> {:throw, t}
@gamache
gamache / language-and-locale-codes.json
Created March 14, 2016 18:53
Language (`xx`) and locale identifier (`xx-yy`) codes, in JSON format
[
{"desc": "Abkhaz", "code": "ab"},
{"desc": "Afar", "code": "aa"},
{"desc": "Afrikaans", "code": "af"},
{"desc": "Akan", "code": "ak"},
{"desc": "Albanian", "code": "sq"},
{"desc": "Amharic", "code": "am"},
{"desc": "Arabic", "code": "ar"},
{"desc": "Aragonese", "code": "an"},
{"desc": "Armenian", "code": "hy"},
@gamache
gamache / conntest_example.ex
Last active April 10, 2023 08:15
Phoenix.ConnTest appears not to pass request body to controller
# router.ex
defmodule Myapp.Router do
use Myapp.Web, :router
pipeline :api do
plug :accepts, ["json"]
end
scope "/", Myapp do
pipe_through :api
@gamache
gamache / validating.md
Last active November 6, 2021 10:01
Validating Data in Elixir with ExJsonSchema

priv/schema.json

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Events API Schema",

  "definitions": {

    "event_collection": {
# test/myapp_test.exs
defmodule MyAppTest do
use ExUnit.Case
test "the truth" do
IO.inspect self
assert 1 + 1 == 2
end
test "the whole truth" do
@gamache
gamache / gist:65232738d68d398784d2
Last active February 8, 2017 21:41
keybase.md
### Keybase proof
I hereby claim:
* I am gamache on github.
* I am gamache (https://keybase.io/gamache) on keybase.
* I have a public key ASApD3qhoE9_IY1NmZwNBQgR9Rs1_DrrYoSw7eQkd1F3Wgo
To claim this, I am signing this object:
### Keybase proof
I hereby claim:
* I am gamache on github.
* I am gamache (https://keybase.io/gamache) on keybase.
* I have a public key whose fingerprint is 1E3A D3A7 A62D 5CEE 5EFE C0AB 1C59 EDEE 13C6 C4F9
To claim this, I am signing this object:
@gamache
gamache / gist:190c1efc7184b856a2b1
Created June 4, 2014 13:47
fixing Homebrew on OS X Yosemite

This worked for me.

  1. Change the first line of /usr/local/Library/brew.rb to: #!/usr/bin/env ruby.
  2. cd $(brew --repository)
  3. git commit -am 'use env ruby'.
  4. OLD_REF = $(git log | head -1 | sed 's/commit //')
  5. git reset --hard HEAD^
  6. git checkout $OLD_REF
  7. brew update
@gamache
gamache / gist:6962760
Last active December 25, 2015 10:39
Running method-cache-test on MRI Ruby 2.1.0dev.
$ ruby --version
ruby 2.1.0dev (2013-10-13 trunk 43273) [x86_64-darwin13.0.0]
$ ruby method-cache-test.rb
user system total real
defined methods, not busting cache:
0.310000 0.010000 0.320000 ( 0.311989)
method_missing dispatch, not busting cache:
@gamache
gamache / gist:6962596
Last active December 25, 2015 10:38
Running method-cache-test.rb on Ruby 2.0.0-p195.
$ ruby --version
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]
$ ruby method-cache-test.rb
user system total real
defined methods, not busting cache:
0.270000 0.000000 0.270000 ( 0.273828)
method_missing dispatch, not busting cache: