Skip to content

Instantly share code, notes, and snippets.

View leonmezu1's full-sized avatar

Leonardo Mezu leonmezu1

View GitHub Profile
@rubyandcoffee
rubyandcoffee / Bootstrap - Rails 7
Last active June 1, 2024 06:57
Bootstrap with Rails 7
Adding Bootstrap to Rails 7
Reference: https://www.linkedin.com/pulse/rails-7-bootstrap-52-importmap-md-habibur-rahman-habib/
INSTRUCTIONS
1. Add the following to Gemfile:
gem "bootstrap"
gem "sassc-rails"
@rahsheen
rahsheen / rspec_mock_net_http.rb
Created November 30, 2017 19:33
Easily Mock Net::HTTP with Rspec
require 'rails_helper'
RSpec.describe MyWorker, type: :job do
include ActiveJob::TestHelper
let(:sqs_msg) { double AWS::SQS::ReceivedMessage,
id: 'fc754df7-9cc2-4c41-96ca-5996a44b771e',
body: 'test',
delete: nil }
@sheharyarn
sheharyarn / api_controller.rb
Last active January 18, 2021 15:13
API Authentication with Devise in Rails
class API::BaseController < ApplicationController
def index
render json: { active: true }
end
def authenticate
if user = User.authenticate(request.headers['X-AUTH-TOKEN'])
sign_in(user, store: false)
@hackjutsu
hackjutsu / upstream.md
Last active December 11, 2023 07:44
[set upstream] What does '--set-upstream' do? #tags: git
git branch --set-upstream-to <remote-branch>
# example
git branch --set-upstream-to origin feature-branch

# show up which remote branch a local branch is tracking
git branch -vv

sets the default remote branch for the current local branch.

@sheharyarn
sheharyarn / create_image_attachment.rb
Last active January 18, 2021 15:13
Polymorphic Paperclip class with unique partial ActiveRecord index on :default_image
# db/migrations/xxxxxxxxxxxxxx_create_image_attachment.rb
class CreateImageAttachments < ActiveRecord::Migration[5.0]
def change
create_table :image_attachments do |t|
t.belongs_to :imageable, polymorphic: true
t.attachment :data
t.boolean :default, default: false
t.timestamps
end
@zulhfreelancer
zulhfreelancer / heroku_pg_db_reset.md
Last active January 29, 2024 10:09
How to reset PG Database on Heroku (for Rails app)?

It's important to note that running this reset will drop any existing data you have in the application

How to reset PG Database on Heroku?

  • Step 1: heroku restart
  • Step 2: heroku pg:reset DATABASE (no need to change the DATABASE)
  • Step 3: heroku run rake db:migrate
  • Step 4: heroku run rake db:seed (if you have seed)

One liner

@eliotsykes
eliotsykes / rails_new_help_output.md
Last active March 31, 2024 17:09
"rails new" options explained

Run rails new --help to view all of the options you can pass to rails new:

$ bin/rails new --help
Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]                                      # Path to the Ruby binary of your choice
                                                         # Default: /Users/eliot/.rbenv/versions/2.2.0/bin/ruby
@blairanderson
blairanderson / simple_form_textarea_rows_columns.md
Created January 14, 2015 01:57
Simple_form Textarea Rows Columns

You need to do this

<%= f.input :message, :input_html => {:rows => 10} %>
<%= f.input :description, :as => :text, :input_html => { 'rows' => 5, 'cols' => 10 } %>
@pstoica
pstoica / OnBlurComponent.jsx
Last active August 1, 2023 21:00
onBlur for entire react element
function OnBlurComponent({ onBlur }) {
const handleBlur = (e) => {
const currentTarget = e.currentTarget;
// Check the newly focused element in the next tick of the event loop
setTimeout(() => {
// Check if the new activeElement is a child of the original container
if (!currentTarget.contains(document.activeElement)) {
// You can invoke a callback or add custom logic here
onBlur();
@sheharyarn
sheharyarn / api_controller.rb
Last active April 27, 2022 08:53
Render API Errors in Rails
class APIController < ApplicationController
include JSONErrors
# ...
end