Skip to content

Instantly share code, notes, and snippets.

Avatar

Alfred Reinold Baudisch alfredbaudisch

View GitHub Profile
@alfredbaudisch
alfredbaudisch / pipe_struct.ex
Last active Mar 15, 2021
Elixir: returning the value of a map or struct field using an anonymous fun with a pipe (syntax sugar)
View pipe_struct.ex
defmodule Company do
schema "companies" do
field(:name, :string)
field(:email, :string)
end
end
from(c in Company, where: c.name == "foo")
|> Repo.one()
|> (& &1.email).()
@alfredbaudisch
alfredbaudisch / kernel.ex
Created Mar 15, 2021
Elixir: using global operators in pipes
View kernel.ex
# To concat to lists, you normally do:
list = [1]
list ++ [2]
# result: [1, 2]
# How do you do that in pipelines?
# Global operators are under the Kernel module, so you can use them with the pipe operator.
list |> Kernel.++([2])
@alfredbaudisch
alfredbaudisch / up-and-running-with-edeliver-on-do.md
Created Dec 23, 2016 — forked from mattweldon/up-and-running-with-edeliver-on-do.md
Getting Elixir / Phoenix running on Digital Ocean with edeliver
View up-and-running-with-edeliver-on-do.md

Build Server

  • Go to Digital Ocean
  • Create new droplet
  • London
  • Ubuntu
  • No apps
  • Add SSH keys
@alfredbaudisch
alfredbaudisch / v2.lua
Last active May 23, 2016
Lua operator overloading
View v2.lua
-- Helpers
function v2_add()
-- foo..
end
-- Vector
local vector = {}
local vector_meta = {}
function vector:new(x, y)
@alfredbaudisch
alfredbaudisch / erlang-osx-32bits.txt
Last active Jan 7, 2016
Install Erlang for Elixir on OS X with working Observer to fix the wxe_driver.so not found error
View erlang-osx-32bits.txt
- Download Erlang source from http://www.erlang.org/download.html
- tar zxvf otp_src_18.2.1.tar.gz
- Configure for 32 bits (wxe_driver.so won't be generated for 64-bits):
- CFLAGS=-O0 ./configure --disable-hipe --enable-smp-support --enable-threads --enable-kernel-poll
- ./otp_build autoconf
- ./configure && make && sudo make install
- which erl
- Install Elixir
- iex
- :observer.start should finally work
@alfredbaudisch
alfredbaudisch / BrPhoneNumberFormatter.java
Created Sep 23, 2015
Android EditText mask for Brazilian telephone numbers. It deals with the default format (xx) xxxx-xxxx as well the newer longer one (xx) xxxxx-xxxx. Máscara de telefones brasileiros para EditText do Android: formata tanto o telefone padrão (xx) xxxx-xxxx, quanto o novo formato (xx) xxxxx-xxxx.
View BrPhoneNumberFormatter.java
/**
* Adapted to BR phone format from the class
* UsPhoneNumberFormatter by Samik Bandyopadhyay:
* http://stackoverflow.com/a/23659268/332839
*/
public class BrPhoneNumberFormatter implements TextWatcher {
final int MAX_LENGTH = 11;
//This TextWatcher sub-class formats entered numbers as (41) 1234(5)?-6789
@alfredbaudisch
alfredbaudisch / Lua.tmLanguage
Last active Dec 12, 2015
Sublime Text 2 Lua language file with support to stored functions. With it Go to Symbol captures all of the following scenarios: local stored; stored = function() end / local class = {}; local stored; class:stored = function() end / class.stored1 = function () end / local function loc(params) end / function glob(params) end
View Lua.tmLanguage
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>comment</key>
<string>Lua Syntax: version 0.8</string>
<key>fileTypes</key>
<array>
<string>lua</string>
</array>