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.rb
Created August 3, 2019 11:20
Simple ruby date range splitter
class DateRangeSplitter
include Enumerable
def initialize(date_from, date_to, max_days, end_inclusive: true)
@date_from = date_from
@date_to = date_to
@max_days = max_days
@end_inclusive = end_inclusive
generate_split_dates
end
@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 / Guidelines for our standard development enviroment.md
Last active October 10, 2023 20:56
This document outlines the standard development environment in devsinc

1- IDE

We generally don't use cloud9/rubymine or any other special IDE for development(you can opt for any IDE, but that will mean no support from seniors for any issues relating it and that might lead to un-neccessary time waste thats why it is highly preferred to not use such IDEs). You are encouraged to use sublime of VSCode(see below for both).

Sublime:

Use sublime 4, install it(google or use this link for ubuntu) Here I will outline some basic configuration for sublime3 we usually use.

i- settings tweaks In sublime go to preferences->setting and place these in user settings tab along with other settings.

@ziaulrehman40
ziaulrehman40 / ubuntu machine setup for rails.md
Last active August 21, 2023 10:29
Ubuntu setup for rails

Basic use libraries installation

sudo apt update
sudo apt install unace unrar zip unzip p7zip-full p7zip-rar sharutils gnupg2 rar uudeview mpack arj cabextract file-roller

Actual Development Setup

Essentials

@ziaulrehman40
ziaulrehman40 / postgres app multiple versions.md
Last active March 28, 2023 14:00
Using multiple postgresql version with appropoiate psql and other pg tools version on mac with postgresapp

Using multiple postgresql version with appropoiate psql and other pg tools version on mac with postgresapp

First make sure no postgres instance is configured to run on startup. And you get nothing when you run this command: which -a psql This is to make sure you don't have anything related to postgres in your PATH, which can conflict. If you do get some hits with above command, you have to manually either remove the installed versions of postgres or just fix PATH and remove ref to that path which has these binaries(psql, pg_dump etc)

For me, i was using brew installed postgres, i had to just comment out a PATH editing line which was inserted by brew in my .bash_profile

Ok, after this we are ready. Now things are simple:

@ziaulrehman40
ziaulrehman40 / VPS rails server setup.md
Last active December 13, 2022 09:37
Server setup on ubuntu VPS(DigitalOcean, EC2 or any other) for rails

Excellent GoRails Article(which is main source for this guide too). I did benefited from lot of other resources online as well.

Creating droplet on DigitalOcean(DO):

(Skip this if you are not using DO, and create your own VPS instance on the service of your choice. Steps below may still be helpful.)

There are few options for this step, DO provide us some pre built images for lot of platforms in which they have pre-installed nginx, node and other related dependencies for each image. Rails one is little outdated, I tried that but didn't go very well for me, you can give it a shot if you have enough time. For this guide we will go with bear bone ubuntu 18.04 server. While creating the droplet, you will be asked to set an ssh key, just generate an ssh key with ssh-keygen on your local system and copy contents of .pub file into the textbox provided.

@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 / sublime packages I use.md
Last active March 12, 2021 11:14
subime packages for rails dev
A File Icon
All Autocomplete
Better CoffeeScript
Bootstrap 3 Autocomplete
BracketHighlighter
Cucumber Step Finder
Cucumber
Dockerfile Syntax Highlighting
Emmet
@ziaulrehman40
ziaulrehman40 / CircleCI 2.0 Parallel builds SimpleCov coverage report merging locally overview.md
Last active August 30, 2020 15:10
CircleCI 2.0 Parallel builds SimpleCov coverage report merging locally

Simplecov aggregated coverage report from CircleCI 2.0 parallel builds (focused on storing locally/within CI containers as artifacts)

Problem Statement

We have Rails application which is running tests on circleCI 2.0, we have simplecov configured to track the coverage of our test suite. Now the problem is with parallelism enabled, we have partial coverage reports in all different containers according to the tests those containers ran.

We obviously want to have consolidated simplecov coverage report which actually shows us overall coverage report.

@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