Skip to content

Instantly share code, notes, and snippets.

@chrismccord
chrismccord / gist:1507045
Created Dec 21, 2011 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts
View gist:1507045

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 / gist:3801696
Created Sep 28, 2012
Rake Task to kill postgres test and development database connections
View gist:3801696
  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
View gist:5301821
# remove any bad refs
git remote prune origin
# pipe into bash and auto-delete any branches that have been merged into master!
git log master --pretty=format:'%d' | grep '^ (origin' | tr -d ' ()' | sed 's/origin\//git push origin :/'
@chrismccord
chrismccord / gist:5519310
Last active Dec 17, 2015
"I have a table that shows the 10 most recent entries and then via Sync new ones get added. Is there an easy way to remove existing entries to keep the total at 10?"
View gist:5519310
# Assuming your partial is named 'list_row' and your model is 'Todo'
class Sync.TodoListRow extends Sync.View
maxRows: 10
afterInsert: ->
$rows = @$el.siblings("tr")
$rows.first().remove() if $rows.length > @maxRows
@chrismccord
chrismccord / gist:6000108
Created Jul 15, 2013
Wrap eredis connection
View gist:6000108
defmodule ERedis do
@name :eredis_connection
def start do
{:ok, pid} = :eredis.start_link
:global.register_name(@name, pid)
end
def connection do
@chrismccord
chrismccord / gist:6298006
Last active Jan 8, 2017
Rails callback/listener approach to shared service object behavior from controllers
View gist:6298006
class CommentsController < ApplicationController
def create
CommentCreator.new(current_user, params[:comment], self).create
end
private
def create_successful(comment)
@chrismccord
chrismccord / gist:6349128
Last active Dec 21, 2015
Access protocol only for specific record
View gist:6349128
defrecord User, email: nil
defmodule Access.User do
def access(record, attr), do: apply(elem(record, 0), attr, [record])
end
user = User.new(email: "foo@bar.com")
iex> user[:email]
"foo@bar.com"
@chrismccord
chrismccord / gist:6723644
Created Sep 27, 2013
zsh vi mode status
View gist:6723644
vim_ins_mode="[INS]"
vim_cmd_mode="[CMD]"
vim_mode=$vim_ins_mode
function zle-keymap-select {
vim_mode="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}"
zle reset-prompt
}
zle -N zle-keymap-select
@chrismccord
chrismccord / gist:7806146
Created Dec 5, 2013
Elixir 0.11 record bug
View gist:7806146
# This worked on 0.10
defmodule Records do
defmacro __using__(_) do
quote do
defrecord A, name: "chris"
defrecord B, id: nil, nested: A.new
end
end
View gist:8446557
defmodule Example do
defmacro __using__(_options) do
quote do
Module.register_attribute __MODULE__, :attr, accumulate: true, persist: false
import unquote(__MODULE__)
end
end
defmacro append(attr) do