Skip to content

Instantly share code, notes, and snippets.

View zenbakiak's full-sized avatar

Juan Carlos Mercado Alpizar zenbakiak

View GitHub Profile
@ArturT
ArturT / api_controller.rb
Last active July 20, 2023 06:44
How to rescue ActionDispatch::Http::MimeNegotiation::InvalidType in API controller for Rails 6.1+ and render nice JSON error. Learn more how you could run RSpec/Minitest tests faster in Rails app https://docs.knapsackpro.com/2020/how-to-speed-up-ruby-and-javascript-tests-with-ci-parallelisation
# This is example how to rescue from exception ActionDispatch::Http::MimeNegotiation::InvalidType
# and show nice JSON error in your API
module API
class BaseController < ActionController::API
def process_action(*args)
super
rescue ActionDispatch::Http::MimeNegotiation::InvalidType => exception
# set valid Content-Type to be able to call render method below
request.headers['Content-Type'] = 'application/json'
render status: 400, json: { errors: [exception.message] }
@dvf
dvf / change-codec.md
Last active May 2, 2024 17:10
Enable High Quality mode on your headphones (Updated for macOS Catalina)

If you're using a high-end bluetooth headset on your Macbook Pro it's likely your mac is using an audio codec which favors battery efficiency over high quality. This results in a drastic degradation of sound, the SBC codec is the likely culprit, read more about it here.

Find out what codec you're using

  1. Play a song on your headphones
  2. Option (⌥) click the Bluetooth button at the top of your screen Inspect the Bluetooth Coded
  3. If you're using AAC or aptX, you can stop here—those are the highest quality codecs.

Change your codec to AAC or aptX

@joewils
joewils / currency.rb
Last active March 7, 2022 20:05
USD currency formatting filter for Liquid templates
# Custom text filters
module TextFilter
# USD Currency
def currency(input)
return sprintf('$%0.2f',input).gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
end
end
# Globally register custom text filters
Liquid::Template.register_filter(TextFilter)
@vitorbritto
vitorbritto / rm_mysql.md
Last active April 23, 2024 14:21
Remove MySQL completely from Mac OSX

Remove MySQL completely

  1. Open the Terminal

  2. Use mysqldump to backup your databases

  3. Check for MySQL processes with: ps -ax | grep mysql

  4. Stop and kill any MySQL processes

  5. Analyze MySQL on HomeBrew:

    brew remove mysql
    
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@alex-zige
alex-zige / gist:82037e8588ec813e944f
Last active August 29, 2015 14:02
Mac OSX 10.10 RVM & Ruby

Fix Brew

Brew still using 1.8 ruby verison. but OSX 10.10 ship with 2.0.0 so symoblinking for now.

$ sudo mkdir -p /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin
$ sudo ln -s /usr/bin/ruby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

Brew update

@alex-zige
alex-zige / gist:5795358
Last active June 8, 2023 07:49
Rails Rspec API Testing Notes

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views
@amedrz
amedrz / gist:3933285
Last active October 11, 2015 22:58
README template

Project dependencies

Specify app's low-level dependencies and its versions, e.g. Ruby, Rails, Spree, RefineryCMS, Node.js...

Setup Development Environment

Specify all the necessary steps to successful setup the app in a development machine.

Such steps would include how to:

@amejiarosario
amejiarosario / rails_migration_cheatsheet.md
Created June 18, 2012 21:40
Rails Migration - Cheatsheet
@saranyan
saranyan / active_merchant.rb
Created December 20, 2011 16:38
PayPal IPN using Active merchant
if Rails.env.production?
PAYPAL_ACCOUNT = 'production@gmail.com'
else
PAYPAL_ACCOUNT = 'development@gmail.com'
ActiveMerchant::Billing::Base.mode = :test
end