Skip to content

Instantly share code, notes, and snippets.

@videlalvaro
videlalvaro / fold_example.erl
Created April 27, 2015 14:24
blog post example
%% compile and run fold_example:test().
%% Records used here were taken from RabbitMQ's source code.
-module(fold_example).
-compile(export_all).
-record('P_basic',
{content_type,
content_encoding,
headers,
@zabirauf
zabirauf / ROP.ex
Created March 26, 2015 07:48
Railway Oriented Programming macros in Elixir
defmodule ROP do
defmacro try_catch(args, func) do
quote do
(fn ->
try do
unquote(args) |> unquote(func)
rescue
e -> {:error, e}
end
@rahilb
rahilb / authenticator.lua
Created March 18, 2015 14:41
lua token authenticator for nginx
-- an openresty/nginx authenticator that checks bearer tokens with
-- an ID service for use with `access_by_lua_file` nginx directive
local http = require "resty.http"
local hc = http:new()
function abandon_request(status_code, response_body)
ngx.header["WWW-Authenticate"] = "Bearer"
ngx.status = status_code
ngx.say(response_body)
@alanpeabody
alanpeabody / settings.ex
Last active August 29, 2015 14:16
embedding elixir structs step 6
defmodule App.Models.Settings do
defstruct [
newsletter: false,
publish_profile: true,
email_notifications: true
]
defmodule Type do
@behaviour Ecto.Type
alias App.Models.Settings
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@rbishop
rbishop / README.md
Last active April 11, 2025 17:56
A super simple Elixir server for sending Server Sent Events to the browser.

Generate a new Elixir project using mix and add cowboy and plug as dependencies in mix.exs:

  defp deps do
    [
      {:cowboy, "~> 1.0.0"},
      {:plug, "~> 0.8.1"}
    ]
  end
@akiatoji
akiatoji / Clojure_on_RaspberryPi_OSX.md
Last active December 3, 2022 21:15
Running Clojure on Raspberry Pi with OS X

Clojure on Raspberry Pi with OS X

"Clojure running on Raspberry Pi" sounded so cool that I just had to give it a try.

Install JDK

  • Download ARM JDK from Oracle and instlal on Raspberry Pi
  • Change visudo to contain the following
@bloodyowl
bloodyowl / gist:41b1de3388c626796eca
Last active April 20, 2020 03:27
es6 event-emitter
var DEFAULT_MAX_LISTENERS = 12
function error(message, ...args){
console.error.apply(console, [message].concat(args))
console.trace()
}
class EventEmitter {
constructor(){
this._maxListeners = DEFAULT_MAX_LISTENERS
@hamidreza-s
hamidreza-s / Erlang - ClearConsole.erl
Created April 12, 2014 05:25
How to clear the Erlang shell.
%% move cursor to beginning of the line
io:format("\e[H").
%% clear the console
io:format("\e[J").
%% both
io:format("\e[H\e[J").
@pragdave
pragdave / gist:5997018
Created July 15, 2013 01:57
Two implementations of flatten/1
# The simplest version is probably to use list concatenation. However,
# this version ends up rebuilding the list at each step
defmodule UsingConcat do
def flatten([]), do: []
def flatten([ head | tail ]), do: flatten(head) ++ flatten(tail)
def flatten(head), do: [ head ]
end
# This version is more efficient, as it picks successive head values
# from a list, adding them to `result`. The trick is that we have to