Skip to content

Instantly share code, notes, and snippets.

Avatar

Sulman Baig sulmanweb

View GitHub Profile
@sulmanweb
sulmanweb / api-rspec.yml
Created Jul 25, 2020
RSpec Rails API GitHub Actions Workflow
View api-rspec.yml
name: CI RSpec Tests
on: [push, pull_request]
push:
paths:
- 'api/**'
pull_request:
paths:
- 'api/**'
@sulmanweb
sulmanweb / minimal-responsive-signup-page-with-tailwindcss.html
Last active Mar 1, 2020
Minimal Responsive SignUp Page with TailwindCSS
View minimal-responsive-signup-page-with-tailwindcss.html
<body class="bg-gray-100">
<div class="" id="sign-up-page">
<div class="max-w-xl mx-auto mt-2 md:mt-8 lg:mt-16">
<!-- Heading -->
<div class="bg-white p-8 shadow rounded-lg">
<!-- SVG Illustration -->
<!-- https://undraw.co/illustrations -->
<svg id="29e4b1a0-13d0-4a0f-9be2-3c3977a6a4ba" class="h-32 w-full mb-4 md:h-48" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="785" height="753.73" viewBox="0 0 785 753.73"><defs><linearGradient id="b4c3f788-9d51-49bd-96f9-c54f9fd51398" x1="452.8" y1="753.73" x2="452.8" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="gray" stop-opacity="0.25"/><stop offset="0.54" stop-color="gray" stop-opacity="0.12"/><stop offset="1" stop-color="gray" stop-opacity="0.1"/></linearGradient><linearGradient id="778ed1c4-cafd-494e-8a04-dc2b91aee6fd" x1="209.37" y1="339.46" x2="209.37" y2="101.61" xlink:href="#b4c3f788-9d51-49bd-96f9-c54f9fd51398"/><linearGradient id="92c6cb1b-63b4-4a00-
@sulmanweb
sulmanweb / .rspec
Last active Oct 4, 2019
RSpec files
View .rspec
--require spec_helper
--format documentation
@sulmanweb
sulmanweb / aws_uploader.rb
Created Sep 15, 2019
AwsUploader class to directly upload url or file to s3. It Requires HTTParty and aws_sdk gems to be installed.
View aws_uploader.rb
require 'aws-sdk'
require 'HTTParty'
## This class uploads a file to s3 with public-read access and return the public url
class AwsUploader
# s3 obj after initializing the aws sdk
attr_reader :s3
# initialization requires aws key id, secret, s3 region and s3 bucket data all are env variables
@sulmanweb
sulmanweb / RubygemsScrapper.rb
Last active Sep 14, 2019
Web Scraping Script in Ruby
View RubygemsScrapper.rb
require 'HTTParty'
require 'Nokogiri'
class RubygemsScrapper
attr_accessor :parse_page
# initialize repo for ruby gems requires query string
def initialize(q)
doc = HTTParty.get("https://rubygems.org/search?query=#{q}")
@parse_page ||= Nokogiri::HTML(doc)
@sulmanweb
sulmanweb / settings.json
Created Mar 18, 2019
VS Code Ruby Settings
View settings.json
{
"rubocop": {
"lint": true, //enable all lint cops.
"only": [/* array: Run only the specified cop(s) and/or cops in the specified departments. */],
"except": [/* array: Run all cops enabled by configuration except the specified cop(s) and/or departments. */],
"forceExclusion": true, //Add --force-exclusion option
"require": [/* array: Require Ruby files. */],
"rails": true //Run extra rails cops
},
"ruby.lint": {
@sulmanweb
sulmanweb / find_fixed_point_spec.rb
Created May 20, 2018
Find fixed point algorithm spec file
View find_fixed_point_spec.rb
RSpec.describe BinarySearch, "#find_fixed_point" do
context "should have a sorted array" do
it "searches for the fixed point" do
binary_search = BinarySearch.new
expect(binary_search.find_fixed_point([0, 2, 3, 4, 5, 6, 7, 8])).to eql 0
expect(binary_search.find_fixed_point([0, 1, 2, 4, 5, 6, 7, 8])).to eql 2
end
it "returns -1 if not found" do
binary_search = BinarySearch.new
expect(binary_search.find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8])).to eql -1
@sulmanweb
sulmanweb / find_fixed_point.rb
Created May 20, 2018
Find Fixed Point in Sorted Array Algorithm
View find_fixed_point.rb
def find_fixed_point(array)
n = array.length
high = n - 1
low = 0
while low <= high
mid = low + (high - low / 2)
if array[mid] == mid
return mid
@sulmanweb
sulmanweb / binary_search_spec.rb
Created May 19, 2018
RSpec file for binary search
View binary_search_spec.rb
require 'binary_search'
RSpec.describe BinarySearch, "#sort_func" do
context "with array searches the required" do
it "searches!" do
binary_search = BinarySearch.new
expect(binary_search.search_func([1, 2, 3, 4, 5, 6, 7, 8], 5)).to eql 4
end
it "return string if not found" do
binary_search = BinarySearch.new
View binary_search.rb
# Binary Search Algorithm
# Time Complexity = o(log n + 1)
# Precondition: List should be sorted
class BinarySearch
def search_func (array, to_search)
low = 0
high = array.length - 1
while low <= high