Get Homebrew installed on your mac if you don't already have it
Install highlight. "brew install highlight". (This brings down Lua and Boost as well)
Get Homebrew installed on your mac if you don't already have it
Install highlight. "brew install highlight". (This brings down Lua and Boost as well)
Greg Vaughn posted this cool alias the other day:
copr = "!f() { git fetch -fu origin refs/pull/$1/head:pr-$1; git checkout pr-$1; } ; f"
Preferring to be a stock-tools person, I wanted to deconstruct this to see how I'd use it off-the-shelf without the alias.
git fetch -- I'm already familiar with this command
-fu -- these two flags I'm not sure are necessary, esp. -u since the help says,
"unless you are implementing your own Porcelain you are not supposed to use
# This module represents a behaviour and when used picks from the Application configuration which implementation will be used | |
defmodule Clock do | |
@callback now() :: Integer.t | |
defmacro __using__([]) do | |
module = Application.get_env(:my_app, :Clock) | |
quote do | |
alias unquote(module), as: Clock | |
end |
# A convenient script for Elixir golfing. | |
# Provide your code and some test cases. Then run this file, e.g. "elixir golf.exs". | |
# Outputs your character length and test results. | |
# Text input, text output and return values are all handled. | |
# | |
# By Henrik Nyh (http://henrik.nyh.se) under the MIT license. | |
ExUnit.start | |
defmodule Golf.Example do |
#!bash -e | |
TOKEN= # slack token is generate from: https://api.slack.com/web | |
CHANNEL= # name of channels or group | |
MESSAGE= # message | |
NICK= # bot name | |
IS_PRIVATE= # 1 or 0 | |
if [ $IS_PRIVATE -eq 1 ]; then | |
API_TYPE=groups |
defmodule YourAppName.Search do | |
# ... | |
@doc """ | |
Queries listings. | |
""" | |
def query_listings(query, current_user) do | |
default_scope = from l in Listing, where: l.draft == false or l.user_id == ^current_user.id, order_by: [desc: l.updated_at], limit: 50 | |
id = _try_integer(query) |
This is what the [official documentation][1] says about the terminate/2
callback for a gen_server:
This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.
Reason is a term denoting the stop reason and State is the internal state of the gen_server.
Reason depends on why the gen_server is terminating. If it is because another callback function has returned a stop tuple {stop,..}, Reason will have the value specified in that tuple. If it is due to a failure, Reason is the error reason.
defmodule MasterProxy.Application do | |
alias MyApp.Endpoint, as: MyAppEndpoint | |
alias MyApp.UserSocket, as: MyAppUserSocket | |
alias MyOtherApp.Endpoint, as: MyOtherAppEndpoint | |
alias MyOtherApp.UserSocket, as: MyOtherAppUserSocket | |
alias Phoenix.LiveReloader.Socket, as: LiveReloadSocket | |
alias Plug.Cowboy |
defmodule MyApp.Migration do | |
@moduledoc """ | |
Additional helpers for PostgreSQL. | |
""" | |
import Ecto.Migration, only: [execute: 2] | |
defmacro __using__(_) do | |
quote do | |
use Ecto.Migration |