Skip to content

Instantly share code, notes, and snippets.

View gvaughn's full-sized avatar
:atom:
Never trust an atom. They make up everything.

Greg Vaughn gvaughn

:atom:
Never trust an atom. They make up everything.
View GitHub Profile
@gvaughn
gvaughn / gist:33d8a61d5cea03691732
Last active August 29, 2015 14:03 — forked from jimbojsb/gist:1630790
source highlighting in presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@gvaughn
gvaughn / copr.md
Created July 18, 2014 16:15 — forked from chrismo/copr.md

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 
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gvaughn
gvaughn / clock.ex
Created September 30, 2015 15:27 — forked from CrowdHailer/clock.ex
Creating boundary modules for elixir applications. These have their implementation set during the configuration step. In this example we switch clock between system clock and a dummy clock
# 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
@gvaughn
gvaughn / golf.exs
Created November 24, 2015 18:27 — forked from henrik/caddy.exs
A convenient script for Elixir golfing.
# 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
@gvaughn
gvaughn / slackpost.sh
Created May 11, 2016 21:43 — forked from mattak/slackpost.sh
post message to slack
#!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
@gvaughn
gvaughn / ecto_postgres_fulltext_search_querying_example.ex
Created October 4, 2017 22:34 — forked from pmarreck/ecto_postgres_fulltext_search_querying_example.ex
How to set up postgres fulltext search triggers, index, and tsvector column on Elixir/Phoenix, with Ecto querying, including ranking and sorting by rank
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)
@gvaughn
gvaughn / discussion.md
Created June 28, 2018 16:32 — forked from jadeallenx/discussion.md
When does terminate/2 get called in a gen_server?

When does terminate/2 get called in a gen_server?

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.

@gvaughn
gvaughn / application.ex
Created November 23, 2018 17:18 — forked from cblavier/application.ex
Cowboy 2.5 proxy, used to bind a single port (on Heroku) for umbrella Phoenix applications. It supports HTTPS and websockets properly.
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
@gvaughn
gvaughn / ecto_postgresql_migration.ex
Created February 2, 2019 01:41 — forked from ibarchenkov/ecto_postgresql_migration.ex
Ecto migration helpers for PostgreSQL.
defmodule MyApp.Migration do
@moduledoc """
Additional helpers for PostgreSQL.
"""
import Ecto.Migration, only: [execute: 2]
defmacro __using__(_) do
quote do
use Ecto.Migration