Skip to content

Instantly share code, notes, and snippets.

@chrismccord
chrismccord / gist:3801696
Created September 28, 2012 19:30
Rake Task to kill postgres test and development database connections
  desc "Kill test and development postgres database connections"
  task :pg_terminate => :environment do

    dbs = []
    dbs << ActiveRecord::Base.configurations["development"]["database"]
    dbs << ActiveRecord::Base.configurations["test"]["database"]
    db_names = "#{dbs.map{|name| "'#{name}'"}.join(", ")}"

    terminated = false
@chrismccord
chrismccord / catch_all_action.ex
Created September 18, 2015 00:06
catch-all action
defmodule MyApp.Web do
def controller do
quote do
use Phoenix.Controller
use MyApp.CatchAllController
...
end
end
end
broadcast! socket, "insert_img", %{
url: url,
start: params["start"],
end: params["end"]
}
@chrismccord
chrismccord / gist:1507045
Created December 21, 2011 18:13 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@chrismccord
chrismccord / upgrade.md
Last active August 29, 2015 14:26
Phoenix 0.15.x to 0.16.0 upgrade instructions

Phoenix dep

Update your phoenix dep:

def deps do
 [...,
  {:phoenix, "~> 0.16"},
  ...]
end
@chrismccord
chrismccord / phoenix-0.15-upgrade.md
Last active August 29, 2015 14:25
Phoenix upgrade instructions 0.14.x to 0.15.0

Sockets and Channels

A new socket behaviour has been introduced to handle socket authentication in a single place, wire up default channel assigns, and disconnect a user's multiplex connection as needed.

First things first, create a UserSocket module in web/channels/user_socket.ex and move all your channel routes from web/route.ex to the user socket: (replace MyApp with your application module)

0.14.x - web/router.ex:

defmodule MyApp.Router do
   ...
defmodule MyApp.Password do
@moduledoc """
Handles password authentication, encryption, and decryption
"""
@doc """
Encrypte the password String
"""
def encrypt(raw_password) do
set-option -g default-command "reattach-to-user-namespace -l zsh"
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Setup 'v' to begin selection as in Vim
bind-key -t vi-copy v begin-selection
bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"
@chrismccord
chrismccord / gist:4a62780056b08c60542d
Last active August 29, 2015 14:21
Phoenix Upgrade Instructions 0.13.0 to 0.13.1
@chrismccord
chrismccord / gist:def6f4dc444b6a8f8d8b
Last active August 29, 2015 14:14
Phoenix Upgrade Instructions 0.8.x to 0.9.0

Endpoint

Plug.Static added an :only option which greatly improves performance by skipping disk reads at runtime. Replace your Plug.Static lines in endpoint.ex with the following configuration:

  plug Plug.Static,
    at: "/", from: :my_app,
    only: ~w(css images js favicon.ico robots.txt)

Router / Controller