Skip to content

Instantly share code, notes, and snippets.

View ziaulrehman40's full-sized avatar
🎯
Focusing

Zia Ul Rehman ziaulrehman40

🎯
Focusing
  • Devsinc
  • Lahore
View GitHub Profile
@ziaulrehman40
ziaulrehman40 / date_range_splitter_spec.rb
Created August 3, 2019 11:24
Specs for date range splitter
require "rails_helper"
RSpec.describe DateRangeSplitter, type: :service do
describe "#generate_split_dates" do
it "#splits dates properly exclusive in ranges" do
from = DateTime.now
to = from + 53.days
splitter = DateRangeSplitter.new(from, to, 10, end_inclusive: false)
splitter.each do |from_d, to_d|
check_against = to_d == to ? 3 : 10
@ziaulrehman40
ziaulrehman40 / CheckboxAdapter.jsx
Created November 24, 2019 13:16
Shopify-polaris components wrappers for react-final-form
import React from 'react'
import { Checkbox } from '@shopify/polaris'
export default function CheckboxAdapter({ input, meta, ...rest }) {
return (
<Checkbox
{...input}
{...rest}
error={meta.touched && meta.error}
onChange={(value) => {
@ziaulrehman40
ziaulrehman40 / Rubocopconfig.md
Last active October 8, 2022 14:35
Rubocop config

Add following to Gemfile

group :development, :test do
  gem 'rubocop'
  gem 'rubocop-performance'
  gem 'rubocop-rails'
  gem 'rubocop-minitest' # or gem 'rubocop-rspec' depending on your test suite
end
@ziaulrehman40
ziaulrehman40 / tranform_enums.rb
Last active June 24, 2024 06:39
Ruby codemod: transformto rails 7.2 enum syntax with validate options to avoid argumentErrors on assignment
# Transforms
# From: enum name: values
# To: enum :name, values, validate: { allow_nil: true }
# Also removes _ from prefix and suffix for the new syntax to avoid un-intended bugs
# You can modify this tranformer in transform_enum method as per your needs
# USAGE:
# 1. gem install parser
# 2. run this file providing a single file or parent folder like: ruby tranform_enums.rb myApp/app/models OR ruby tranform_enums.rb myApp/app/models/user.rb