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 / comunas.json
Last active April 4, 2023 18:48
Comunas de Chile (seed Ruby on Rails, JSON) - (see also https://github.com/gonzalo-bulnes/chilean_cities)
[
{
"name": "Arica",
"code": "15101",
"provincia": "Arica",
"region": "Arica y Parinacota",
"region_number": "XV",
"region_iso_3166_2": "CL-AP"
},
{
# acid-template.rb
git :init
gitignore = run("curl https://gist.github.com/raw/3875160/5d2745ee9bcae0bb4addf4bc701d3fa9a48ce187/.gitignore")
file ".gitignore", gitignore
if yes?("Do you use RVM? (yes|no")
if yes?("Do you want to create a .rvmrc file for the project? (yes|no)")
# RVM
current_ruby = %x{rvm list}.match(/^=>\s+(.*)\s\[/)[1].strip
desired_ruby = ask("Which RVM Ruby would you like to use? [#{current_ruby}]")
es:
errors:
messages:
not_found: "no encontrado"
already_confirmed: "ya ha sido confirmado"
not_locked: "no está bloqueado"
devise:
sessions:
link: 'Ingresar'
@gonzalo-bulnes
gonzalo-bulnes / work_place_spec.rb
Created April 10, 2013 23:28
Using lambda functions to test exception raising with RSpec.
require 'spec_helper'
describe WorkPlace do
# This is the simplest (best) way to test a dependent: :destroy option
it "has one address and ensures it's destroyed when destroyed itself" do
should have_one(:address).dependent(:destroy)
end
# ... however the use this example does of lambda {} to encapsulate the code
#Load in rails via:
# config/initializers/core_extensions.rb
#Forcibly require our core extensions after rails has loaded
Dir.glob(Rails.root.join('lib', 'core_ext', '*.rb')).each { |extension| require extension }
@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
@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 / 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 / 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
---
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>