Skip to content

Instantly share code, notes, and snippets.

View alfredbaudisch's full-sized avatar

Alfred Reinold Baudisch alfredbaudisch

View GitHub Profile
@alfredbaudisch
alfredbaudisch / pipe_struct.ex
Last active March 15, 2021 12:45
Elixir: returning the value of a map or struct field using an anonymous fun with a pipe (syntax sugar)
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 March 15, 2021 12:29
Elixir: using global operators in pipes
# 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 December 23, 2016 18:03 — 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
@alfredbaudisch
alfredbaudisch / v2.lua
Last active December 21, 2023 05:14
Lua operator overloading
-- 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 January 7, 2016 12:07
Install Erlang for Elixir on OS X with working Observer to fix the wxe_driver.so not found error
- 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 September 23, 2015 00:38
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.
/**
* 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 December 12, 2015 06:48
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
<?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>