GithubHelp home page GithubHelp logo

techgaun / elixir-tips-tricks Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 5 KB

Just random tips and tricks while working with elixir [& phoenix and other libs/frameworks]

License: MIT License

elixir phoenix erlang elixir-tips

elixir-tips-tricks's Introduction

elixir-tips-tricks

Just random tips and tricks while working with elixir [& phoenix and other libs/frameworks]

Disable compiling of dependency in mix

{:my_dep, …, compile: false}

Run only particular tests

Use @tag :wip in the test you want to run

defmodule MyTest do
  use ExUnit.Case
  
  test "first test" do
    assert 1 == 1
  end
  
  @tag :wip
  test "second test" do
    assert 3 != 5
  end
end
mix test --only wip

Build composable queries with Inquisitor

Check the Inquisitor repository if you're looking for building composable queries for Ecto.

iex shortcuts

  • c "somefile.exs" - compile the file
  • r SomeModule - reload the module
  • h some_func - get help for the function
  • v [n] - access session history

Get query and post params excluding others in params (phoenix)

conn.body_params # gives params from POST
conn.query_params # query string parameters

Run multiple mix tasks

MIX_ENV=test mix do deps.get, test

Update particular dependency

mix deps.update <dep_name>

Turn off layout on Phoenix.Controller.render/3

render conn, "index.html", %{layout: false}
# with plug
plug :put_layout, false

# pipe it
conn |> put_layout(false) |> render(...)

Increase stacktrace

:erlang.system_flag(:backtrace_depth, 20)

# with phoenix
# config/env.exs
config :phoenix, :stacktrace_depth, 20

Observer on remote erlang node

$ iex --name [email protected] --cookie iam_not_so_awesome -S mix phoenix.server  # in api server

# on separate shell
$ iex --name [email protected] --remsh [email protected] --cookie iam_not_so_awesome
iex([email protected])1> :observer.start

You can pass args down to erlang via erl flag. Example: --erl "-kernel inet_dist_listen_min 9001 inet_dist_listen_m 9001"

Change default compile output directory

Based on this, you can specify a keyword list arg build_path to override the default _build directory.

Example:

def project do
    [app: :my_app,
    version: "0.0.1",
    elixir: "~> 1.2",
    build_embedded: Mix.env == :prod,
    start_permanent: Mix.env == :prod,
    build_path: "custom_build_dir",
    deps: deps]
end

Emmet tab support for eex in Atom

Open your preferences and select keymaps. It should open keymaps.cson. Add the following in that file:

'atom-text-editor[data-grammar="text html elixir"]:not([mini])':
    'tab': 'emmet:expand-abbreviation-with-tab'

The grammar can be obtained for any files by opening console (ctrl+shift+i) and type the following with the appropriate file open in your editor:

document.getElementsByTagName('atom-text-editor')

elixir-tips-tricks's People

Contributors

techgaun avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

nginz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.