Skip to content

Instantly share code, notes, and snippets.

@dnlserrano
dnlserrano / prepare-commit-msg
Created Jul 7, 2017
prepare-commit-msg git hook
View prepare-commit-msg
#!/bin/sh
ticket=$(git symbolic-ref --short HEAD | sed 's/.*\/\([a-zA-Z]*\)-\([0-9]*\).*/JIRA \1-\2/g')
original_msg=$(cat $1)
echo "\n\n$ticket\n$original_msg" > $1
@dnlserrano
dnlserrano / pr.md
Created Aug 2, 2016 — forked from piscisaureus/pr.md
Checkout github pull requests locally
View pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@dnlserrano
dnlserrano / api_controller.rb
Last active Jan 19, 2021
Custom Authentication Controllers
View api_controller.rb
class ApiController < ApplicationController
# define which model will act as token authenticatable
acts_as_token_authentication_handler_for Login
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :null_session
respond_to :json
skip_before_filter :verify_authenticity_token, if: :json_request?
@dnlserrano
dnlserrano / create.json.jbuilder
Last active Oct 18, 2017
Custom Token Authentication SessionController with DRY Authenticatable Logout
View create.json.jbuilder
json.success true
json.data do
json.auth_token @user.authentication_token
json.message "login successful"
end
@dnlserrano
dnlserrano / create.json.jbuilder
Last active Aug 29, 2015
Custom Token Authentication SessionsController
View create.json.jbuilder
json.success true
json.data do
json.auth_token @user.authentication_token
end