Skip to content

Instantly share code, notes, and snippets.

View gonzalo-bulnes's full-sized avatar

Gonzalo Bulnes Guilpain gonzalo-bulnes

View GitHub Profile
@gonzalo-bulnes
gonzalo-bulnes / Rakefile
Created February 23, 2015 14:32
Split the test suite using RSpec tags.
# Rakefile
begin
require 'rspec/core/rake_task'
desc 'Provide private interfaces documentation'
RSpec::Core::RakeTask.new(:spec)
namespace :spec do
desc 'Provide public interfaces documentation'
@gonzalo-bulnes
gonzalo-bulnes / Rakefile
Last active August 29, 2015 14:15
(Update: I've packaged this gist into a gem to make its use easier, see: https://github.com/gonzalo-bulnes/dredd-rack.) Add validation against an API blueprint to a Ruby test suite (by defining a Rake task).
# Rakefile
# Add Rainbow to the app dependencies. That's optional, but the result is worth it.
require 'rainbow'
# ...
# Validate an API against its API blueprint
#
# The API blueprints are expected to be stored in `doc/` and
@gonzalo-bulnes
gonzalo-bulnes / .bash_profile
Created September 30, 2014 14:58
Bash configuration to get its prompt to display the current Git branch.
# ...
# Add these lines at the end of your ~/.bash_profile
# Git functions (used to define a custom prompt)
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
@gonzalo-bulnes
gonzalo-bulnes / safe_merge.sh
Last active August 16, 2022 15:44
Some merging rules to make collaboration easier through repository order. Think of rebasing as updating the context in which you write your feature, see also: https://gonzalo-bulnes.github.io/blog/gardening_with_git/context-from-scratch.html
# safe merge
#
# merge the branch XXXXXXXX-add-example-feature into master
# make sure the feature is properly tested and
# doesn't break anything in its original context
git checkout XXXXXXXX-add-example-feature
rake # the test suite MUST NOT raise any error
# make sure your local copy of master is up-to-date
@gonzalo-bulnes
gonzalo-bulnes / sessions_controller.rb
Last active August 24, 2017 09:41
A SimpleTokenAuthentication-compatible JSON version of Devise::SessionsController. (UPDATE: For a discussion about this gist and a better version of it, please see https://github.com/gonzalo-bulnes/simple_token_authentication/issues/48#issuecomment-42133939)
# app/controllers/sessions_controller.rb
class SessionsController < Devise::SessionsController
# This controller provides a JSON version of the Devise::SessionsController and
# is compatible with the use of SimpleTokenAuthentication.
# See https://github.com/gonzalo-bulnes/simple_token_authentication/issues/27
def create
# Fetch params
---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text" xml:lang="en">{{ site.root_desc }}</title>
<link type="application/atom+xml" href="http://paulstamatiou.com/feed/" rel="self"/>
<link type="text" href="http://paulstamatiou.com" rel="alternate"/>
<updated>{{ site.time | date_to_xmlschema }}</updated>
@gonzalo-bulnes
gonzalo-bulnes / XXXXXXXXXXXXX_add_authentication_token_to_users.rb
Last active March 6, 2019 15:15
(Update: I've packaged this gist into a gem to make its use easier, see: https://github.com/gonzalo-bulnes/simple_token_authentication.) Add token authentication to your Rails API. Follows the José Valim recomendations and is fully compatible with Devise (tokens are created the first time users sign in). See https://gist.github.com/josevalim/fb7…
# db/migrate/XXXXXXXXXXXXX_add_authentication_token_to_users.rb
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
add_index :users, :authentication_token, :unique => true
end
end
@gonzalo-bulnes
gonzalo-bulnes / api_steps.rb
Last active February 3, 2021 16:49 — forked from aeden/api_steps.rb
A set of Cucumber steps to test and document API behaviour (with verbose and DRY step definitions for an example resource).Deeply inspired in @aeden API steps, see http://vimeo.com/30586709
# features/step_definitions/api_steps.rb
# These steps are very deeply inspired in the Anthony Eden (@aeden) API steps.
# See http://vimeo.com/30586709
# Given
Given /^I send and accept JSON$/ do
header 'Accept', 'application/json'
@gonzalo-bulnes
gonzalo-bulnes / custom_form_builder.rb
Last active December 21, 2015 03:59
A sweet transition from Bootstrap 2.3 to Bootstrap 3 using a Simple Form custom form builder.
# lib/custom_form_builder.rb
# See https://github.com/plataformatec/simple_form#custom-form-builder
class CustomFormBuilder < SimpleForm::FormBuilder
def input(attribute_name, options = {}, &block)
if options[:wrapper_html]
options[:wrapper_html].merge! class: 'form-group'
else
options[:wrapper_html] = { class: 'form-group' }
end
@gonzalo-bulnes
gonzalo-bulnes / logger.rb
Last active December 17, 2015 07:18
A logger for the TBK gem. This logger doesn't calculate the `TBK_MAC` value but allows you to set it manually instead. See https://github.com/gonzalo-bulnes/tbk/issues/2 for context. See also https://github.com/kiel-cristian/tbk-rails .
# encoding: utf-8
# lib/tbk/webpay/logger.rb
# Copyright (c) 2013 Acid Ltda <www.acid.cl>
# Copyright (c) 2013 Gonzalo Bulnes Guilpain <gonzalo@acid.cl>
# Copyright (c) 2013 Cristián Carreño <kiel@acid.cl>
#
# This code is distributed under the same license than TBK-Rails,
# see https://github.com/kiel-cristian/tbk-rails for details.
module TBK