Skip to content

Instantly share code, notes, and snippets.

Verifying that "mtanzi.id" is my Blockstack ID. https://onename.com/mtanzi

Keybase proof

I hereby claim:

  • I am mtanzi on github.
  • I am mtanzi (https://keybase.io/mtanzi) on keybase.
  • I have a public key ASDEbRpP1XELT_rOda2RNjcP_XNFOM9SojWcNVz28SIzBAo

To claim this, I am signing this object:

@mtanzi
mtanzi / quick_sort.ex
Created June 11, 2015 11:02
Quick sort in elixir
defmodule Math do
def sort([h | t]) do
sort(for x <- t, x < h, do: x) ++ [h] ++ sort(for x <- t, x >= h, do: x)
end
def sort([]), do: []
end
@mtanzi
mtanzi / AuthHeaders.ex
Last active August 29, 2015 14:22
Plug used inside the phoenix controller to extract the encoded credential from the `authorization` header
defmodule MyApp.Plugs.AuthHeaders do
import Plug.Conn
import Phoenix.Controller
require Logger
@doc """
This Plug extract the `authentication` header from the connnaction
and extrac the tocken containing the credentials. If the header has
ther correct format it calls the `validate` function otherwise it
will return a 401 error.
@mtanzi
mtanzi / README.md
Last active August 29, 2015 14:21 — forked from joakimk/README.md

This runs a build for a small elixir (phoenix) project in about 40 seconds by caching as much of the compiled files as possible. It's not been run for very long so I don't know if it caches too much or of there is any other issues.

It should be generic enough to work on any elixir app using mix.

@mtanzi
mtanzi / README.md
Last active August 29, 2015 14:21 — forked from joakimk/README.md

This runs a build for a small elixir (phoenix) project in about 40 seconds by caching as much of the compiled files as possible. It's not been run for very long so I don't know if it caches too much or of there is any other issues.

It should be generic enough to work on any elixir app using mix.

@mtanzi
mtanzi / README.md
Last active August 29, 2015 14:21 — forked from joakimk/README.md

This runs a build for a small elixir (phoenix) project in about 40 seconds by caching as much of the compiled files as possible. It's not been run for very long so I don't know if it caches too much or of there is any other issues.

It should be generic enough to work on any elixir app using mix.

@mtanzi
mtanzi / auth_plug.ex
Last active August 29, 2015 14:21 — forked from mprymek/auth_plug.ex
# Simple Phoenix authentication plug
#
# - based on Plug's session store
# - redirects unauthenticated requests to login page "/login/<request url>"
# - /static/... requests are not authenticated
# - authentication is valid as long as session is valid (you can change this behaviour easily)
# Because we need session to be fetched BEFORE this plug, we must put this to router.ex:
#----------------------------
@mtanzi
mtanzi / haml2erb.rb
Created June 6, 2013 23:54
Script that use herbalizer (https://github.com/danchoi/herbalizer) to convert the haml file present in the views directory into erb.
Dir["#{Rails.root}/app/views/**/*.haml"].each do |file|
file_name = file.split("/").pop
file_dir = file.split("/")[0..-2]
value = %x(~/herbalizer #{file})
new_file = File.join(file_dir, file_name.gsub("haml", "erb"))
File.open(new_file, 'w') do |f|
f.write(value)
NO_COLOR='\e[0m' #disable any colors
BLACK='\e[0;30m'
RED='\e[0;31m'
GREEN='\e[0;32m'
YELLOW='\e[0;33m'
BLUE='\e[0;34m'
MAGENTA='\e[0;35m'
CYAN='\e[0;36m'
WHITE='\e[0;37m'