- Numbers: Integers and Floats
- Atoms: :named_constant
- Binaries: strings are binaries. <<104>> is “h”
- Maps: %{key: value}. Can use strings or atoms for keys. But only atoms allow map.key; else use map[key]
- Tuples: {value,value…}. To access – elem(tuple, 0). To add: put_elem(tuple, 0, “value”)
- Lists: [value, value…]
- Functions: fn(args) -> … end. To call: fn.(args)
- Character Lists: ‘h’ is [104]
- Keyword Lists: [{:atom, value}…] == [atom: “value”,…]
- Structs: %{key: value}
- Range: 0..42
- Regex: ~r/pattern/
Setting up Elixir with Atom on Linux
Sublime is a pretty nice editor for working with Elixir, but I just can’t get the autocomplete plugin to work. So, giving Atom a try.
Install the following packages:
atom-elixir – https://atom.io/packages/atom-elixir
language-elixir – https://atom.io/packages/language-elixir
linter (apm install linter) – https://atom.io/packages/linter
linter-elixirc – https://atom.io/packages/linter-elixirc
script – https://atom.io/packages/script
I use script to build within Atom (shift-ctrl-b). The only issue is that it seems to use the top-level folder of your project as a base path. So, if you try to do something like Code.load_file(“file.exs”) in one of your nested directories, it’ll try to load it from the top level directory.
Addendum for Mac
brew install elixir
brew install erlang
Set elixir path for autocomplete-elixir (if using Atom):
/usr/local/bin/elixir
Parsing jQuery Unobtrusive Validation Parameters
Client-side parsing of unubtrusive jQuery validation parameters. Assuming we are setting up an unobtrusive validator named “validatorname” and want to pass “parameterfromserver” from the the server:
$.validator.unobtrusive.adapters.add('validatorname', ['parameterfromserver'], function(options) {
options.rules['validatorname'] = {
parameterfromserver: options.params['parameterfromserver']
};
options.messages['validatorname'] = options.message;
});
$.validator.addMethod('validatorname', function(value, element, parameters) {
var hereIsOurParameter = parameters.parameterfromserver;
});