Skip to content

Instantly share code, notes, and snippets.

View bigardone's full-sized avatar
🏠
Working from home

Ricardo García Vega bigardone

🏠
Working from home
View GitHub Profile
@raorao
raorao / ets_cache.ex
Last active October 21, 2024 19:20
Simple ETS based cache with TTL
defmodule RequestCache do
@moduledoc """
Simple ETS-based cache.
"""
use GenServer
@type t :: %{ttl: integer, invalidators: %{}}
@type cache_key :: any
@type cache_value :: any
@kipcole9
kipcole9 / Map.Helpers
Last active October 24, 2023 22:13
Helpers for Elixir Maps: underscore, atomise and stringify map keys
defmodule Map.Helpers do
@moduledoc """
Functions to transform maps
"""
@doc """
Convert map string camelCase keys to underscore_keys
"""
def underscore_keys(nil), do: nil
@klaftertief
klaftertief / reactiveconf-2016-lightning-talk.md
Last active April 2, 2024 20:17
An API search engine in Elm for Elm, proposal for a Lightning Talk at ReactiveConf 2016

An API search engine in Elm for Elm

Elm is a statically typed functional language that compiles to JavaScript. It's well-known for its developer experience: the compiler provides nice error messages, the package system enforces semantic versioning for all published packages and makes sure every exposed value or type has some documentation and type annotations.

Type Safe JSON Decoding in Elm

The power of a Static Typed language can seem magical at first. But the goal here is to take a tiny peak behind that curtain.

Elm's implementation of JSON parsing is type safe and how it achieves that can seem like a mystery. Even though I got the code to work, it took me a while to fully understand how it works.

I'm writing it down here for 2 reasons. To help others gain a greater understanding of Types and so I don't forget what I learned.

Word of Caution

@hopsor
hopsor / ftp.ex
Last active February 16, 2021 07:18
ftp download using elixir and erlang interop
defmodule Reporter do
def progress(last_data, file_name, {size_type, chunk_size}) do
IO.inspect({last_data[:downloaded], "#{last_data[:rate]} MB/s", file_name, size_type, chunk_size})
new_timestamp = :os.system_time(:milli_seconds)
timestamp_diff = new_timestamp - last_data[:last_timestamp]
case chunk_size do
:unknown ->
downloaded = 0
@neoeinstein
neoeinstein / Auth0.elm
Last active March 2, 2017 08:22
Elm Example for interoperating with Auth0. Note that much of this was culled out of an existing code-base, so may need some minor edits to work correctly for you. Presumes that Elm.Main is transpiled into elm.js
module Auth0
( AuthenticationState(..), AuthenticationError, AuthenticationResult
, Options, defaultOpts
, LoggedInUser, UserProfile, Token
, showLock, showLockSignal
, mapResult
) where
@kcurtin
kcurtin / ex_unite_case_template.ex
Last active February 26, 2016 16:39
Using case templates to setup your database for integration tests with elixir and ecto.
defmodule DBTransactions do
use ExUnit.CaseTemplate
setup_all do
Ecto.Adapters.SQL.begin_test_transaction(Repo)
on_exit fn ->
Ecto.Adapters.SQL.rollback_test_transaction(Repo)
end
end
@thbar
thbar / up-and-running-with-edeliver-on-do.md
Created January 29, 2016 22:40 — forked from mattweldon/up-and-running-with-edeliver-on-do.md
Getting Elixir / Phoenix running on Digital Ocean with edeliver

Build Server

  • Go to Digital Ocean
  • Create new droplet
  • London
  • Ubuntu
  • No apps
  • Add SSH keys
@ustun
ustun / eslint-auto.el
Created January 12, 2016 23:59
run eslint --fix on emacs file save
;;; runs eslint --fix on the current file after save
;;; alpha quality -- use at your own risk
(defun eslint-fix-file ()
(interactive)
(message "eslint --fixing the file" (buffer-file-name))
(shell-command (concat "eslint --fix " (buffer-file-name))))
(defun eslint-fix-file-and-revert ()
(interactive)
@henrik
henrik / deploying_phoenix_on_dokku.md
Last active February 24, 2025 17:33
Deploying Elixir's Phoenix Framework on Dokku.

Deploying Phoenix on Dokku

Worked 2015-09-08 for Phoenix 1.0.1 on Dokku 0.3.25.

These instructions assume you've set up Dokku. If not, go find a tutorial for that part. My notes for setting it up on Digital Ocean.

On your local machine, in the app's repo

Create a Dokku app: