Skip to content

Instantly share code, notes, and snippets.

View ahmad19's full-sized avatar
:electron:

Ahmad hamza ahmad19

:electron:
View GitHub Profile
@ahmad19
ahmad19 / data.json
Created December 24, 2023 11:01
repo_json
{
"action": "created",
"installation": {
"id": 42355905,
"account": {
"login": "justinvoicit",
"id": 86925994,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjg2OTI1OTk0",
"avatar_url": "https://avatars.githubusercontent.com/u/86925994?v=4",
"gravatar_id": "",
@ahmad19
ahmad19 / gmail_password_create.txt
Created August 24, 2022 13:02
gmail app password creation
Account with 2-step Verification
If your Gmail account uses 2-step verification, you will need to get an app password and use that instead of your regular password. If you don't use 2-step verification, I recommend turning it on to avoid getting the emails blocked by Google.
To create an app password, go to your Google account settings and navigate to the "Security" tab. Under "Signing in to Google", click on the "App passwords" menu item (this will only be available if you have 2-step verification turned on). Next, select Other (Custom name) under the "Select app" dropdown and enter the name of your app or something else useful. Click "Generate" and your new app password will appear on the screen. Make sure you copy it before closing the window, or you won't be able to see the password again.
Now, in your Rails app mailer settings, replace the <gmail_password> with the new app password instead.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ahmad19
ahmad19 / _form.html.erb
Last active October 2, 2023 23:19
Render inline errors in Rails forms after submit and hotwire changes
<%= form_for customer, html: { id: dom_id(customer), class: 'row g-3' } do |f| %>
<% presenter = InlineErrorRenderer.new(customer, self, 'form-control-lg form-control-solid mb-3 mb-lg-0') %>
<div class='col-md-6'>
<%= f.label :full_name %>
<%= f.text_field :full_name, presenter.html_options_for(:full_name) %>
<%= presenter.error_container_for(:full_name) %>
</div>
<div class='col-md-6'>
<%= f.label :phone_number, 'Phone Number' %>
<%= f.text_field :phone_number, presenter.html_options_for(:phone_number) %>
@ahmad19
ahmad19 / floating_label.html
Last active March 19, 2021 23:56
Bootstrap 5's floating label with input group buttons
<div class="btn-toolbar mb-2" role="toolbar" aria-label="Toolbar with button groups">
<div class="col-md-10">
<div class="form-floating">
<input type="email" class="form-control" id="floatingInput" placeholder="name@example.com">
<label for="floatingInput">Search Customer</label>
</div>
</div>
<div class="col-md-2 text-center">
<div class="btn-group mt-1" role="group" aria-label="First group">
<button class="btn btn-light btn-lg btn-outline-primary" type="button">
@ahmad19
ahmad19 / config.rb
Last active February 9, 2021 11:18
Steps to allow email sending on heroku through sidekiq.
# Create Procfile which is required by heroku.
web: bin/rails server -p $PORT
worker: bundle exec sidekiq -c 2 -e staging
# REDIS
# REDISTOGO_URL for local is bydefault: redis://0.0.0.0:6379/0
# REDISTOGO_URL for heroku
# Use Redistogo heroku addon
# Addon will provide REDISTOGO_URL which should be added in the heroku config.
@ahmad19
ahmad19 / rspec_matchers_cheatsheet.rb
Last active August 3, 2022 14:31
RSpec matchers cheatsheet
# To match only few attributes of an object
# have_attributes
expect(person).to have_attributes(:name => "Jim", :age => 32)
# To match attributes of a collection
expect(notes)
.to match_array([
have_attributes(
notable_id: talent.id,
@ahmad19
ahmad19 / grouped_options.rb
Created December 29, 2020 11:43
Rails example of an ajax form with a select_tag of grouped options
<%= form_tag(submit_path, remote: true, method: :get, id: 'add_line_item') do %>
<div class="col">
<div class="form-row">
<div class="col-md-10">
<%= grouped_collection_select(:line_item, :product_id, current_user.categories, :products, :name, :id, :name, { prompt: '--Select Product--' }, { class: 'form-control form-control-sm' }) %>
</div>
<div class="col text-center">
<%= submit_tag 'Add', class: 'btn btn-outline-secondary btn-sm'%>
</div>
@ahmad19
ahmad19 / match_only_few_attributes.rb
Created December 21, 2020 18:46
Rspec expect to match only few attributes in the response body
expect(response.parsed_body['data']).to(include(
'active' => true,
'name' => 'some group',
'once_per_user' => true
))
@ahmad19
ahmad19 / put_request_as_json.rb
Created October 21, 2020 10:32
Put request with correct headers and params in order to send array as parameters in request body.
put(
"/admin/prizes.json",
headers: { 'CONTENT_TYPE' => 'application/json; charset=UTF-8' },
params: { prizes: [] }.to_json
)