Skip to content

Instantly share code, notes, and snippets.

View n-at-han-k's full-sized avatar
🚀

Nathan Kidd n-at-han-k

🚀
View GitHub Profile
@n-at-han-k
n-at-han-k / strftime_cheatsheet.rb
Last active May 12, 2024 07:13
Ruby strftime cheatsheet 💎⏰
# Additional reference here:
# https://strftime.org
require 'active_support/core_ext/integer/inflections' # To use .ordinalize() outside of rails
date = Time.now
date.strftime('%a %d %b %Y')
# => Sun 08 Sep 2024
@coderberry
coderberry / create_with_callbacks.rb
Last active July 21, 2024 11:56
FactoryBot#create with ActiveRecord Callbacks
# freeze_string_literal: true
module CreateWithCallbacks
extend ActiveSupport::Concern
# Mimic the FactoryBot `create` method but with callbacks. All traits and overrides are applied.
#
# @example with traits and attributes
# source_course = create_with_callbacks!(
# :course,
@henryivesjones
henryivesjones / postgresql_date_timestamp_interval_cheat_sheet.md
Created February 14, 2023 16:56
PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

Working with DATE, TIMESTAMP, and INTERVAL in PostgreSQL can be confusing. In this article I will go over the three date/time related data types, and the two most useful date/time functions: DATE_PART and DATE_TRUNC. Finally, I will provide some real life examples of how these types and functions can be used within queries.

Types

PostgreSQL Date/Time Documentation

DATE

The DATE type contains the year, month, and day of a date. It is not possible to do any type of time related functions on a DATE without first converting it to a TIMESTAMP. Subtracting two DATE values from one another results in an INT representing the # of days between.

TIMESTAMP

The TIMESTAMP type contains a year, month, day, hour, minute, second, and microsecond. This is the type that I most often use.

@john-hamnavoe
john-hamnavoe / rails_7_pagy_ransack.md
Last active July 16, 2024 15:42
How I set up pagy and ransack for simple rails 7 application

Introduction

Adding pagy and ransack in rails so can have search function, paging and sorting on table of date on index controller. We also will use kredis to make it easy to store users last search/sort etc. between pages.

Install

Gemfile:

gem "pagy" gem "ransack"

@zealot128
zealot128 / simple_form.rb
Created August 13, 2022 14:50
Rails simple_form Tailwind Daisy UI config
# frozen_string_literal: true
#
# Uncomment this and change the path if necessary to include your own
# components.
# See https://github.com/heartcombo/simple_form#custom-components to know
# more about custom components.
# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
#
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
@leastbad
leastbad / action_mailbox.md
Last active July 27, 2024 17:28
Action Mailbox: The Missing Manual

This is all you really need to know in order to make Action Mailbox work in development.

  1. Fire up ngrok http 3000 and make note of your subdomain for steps 3 and 8.
  2. Create a Mailgun account because they offer sandbox addresses; grab your domain from the Dashboard.
  3. Go into Receiving and create a catch-all route pointing to: https://XXX.ngrok.io/rails/action_mailbox/mailgun/inbound_emails/mime
  4. Add your Mailgun API key to your credentials:
action_mailbox:
 mailgun_api_key: API KEY HERE
@eiwi1101
eiwi1101 / some_view.html.haml
Last active June 12, 2024 20:00
A table helper file for HAML templates that allows you to make tables of a data collection painfully easy.
%h1 All Users
- table_for User.all do
- column "Username" => :username
- column "Email" => ->(m) { mail_to m.email }
- column "Notes" => :notes
@ChuckJHardy
ChuckJHardy / example_activejob.rb
Last active July 20, 2024 12:15
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
@raghubetina
raghubetina / ransack.md
Last active May 31, 2024 16:36
Ransack Cheatsheet

Ransack Cheatsheet

The Ransack gem provides us with a powerful, flexible, easy-to-integrate search/filter form.

Installation

In your Gemfile, include

gem 'ransack'