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 / 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 / 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 / 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 / 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 / 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 / CircleCI 2.0 Parallel builds coverage report to codeclimate.md
Created December 21, 2018 08:58
CircleCI 2.0 Parallel builds SimpleCov coverage report for CodeClimate reporting

First of all you have to follow my other gist here: https://gist.github.com/ziaulrehman40/1516c0bb940b6ee653b57387cee4e62d In that gist, follow the second solution which is: Use deploy step in simple CircleCI 2.0 build

After that is done and everything seems working. Than there is very little needing to be done.

We will use CodeClimate's new way of reporting, which is cc-test-reporter, this is a binary to work with any kind of projects. Before this we had specific gem and other language specific solutions. Those are deprecated. And gem doesn't work with simplecov > 0.13

Ok, enough talk, now straight to action, following is the circleci config i used:

@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 / PDF.js rails integration notes for S3 hosted files.md
Last active September 4, 2018 06:44
Integrate PDF.js plugin in rails apps to properly display PDFs hosted on S3 in iframe on ipads/iphones, solving problem that ipads only display frist page of pdf

Integrate PDF.js plugin in rails apps

PDF.js is a plugin for displaying pdfs in webpages, it solves a problem on ipads too(indirectly) where ipads and iphones only render first page of the pdf and users can't scroll pdfs rendered in iframes.

pdfjs_rails is the gem which we are going to use for integrating PDF.js in rails.

This gem is pretty old and not maintained, its last commit in master was 5 years ago(at the time of writing). But nevertheless it works and you can easily get you pdfs working in iPads and iPhone. tada!

There are only a few steps which i had to perform to get it working for S3 hosted files on non-public buckets.

@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 / 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.