Skip to content

Instantly share code, notes, and snippets.

View sulmanweb's full-sized avatar

Sulman Baig sulmanweb

View GitHub Profile
# @note: This service is used to call the OpenAI API to generate a response to a message
# @note: The API key is stored in the credentials file
# @param message [String] The message to generate a response for
# @param model [String] The model to use for the response [gpt-3.5-turbo, gpt-3.5-turbo-0301]
# @return [String] The generated response
# @example
# ChatgptService.call('What is your name?', 'gpt-3.5-turbo')
# => "\n\nI am an AI language model created by OpenAI, so I don't have a name. You can call me OpenAI or AI assistant."
# API Docs: https://platform.openai.com/docs/api-reference/chat/create
class ChatgptService
@sulmanweb
sulmanweb / error.bash
Created November 1, 2022 11:56
Error while bin/setup
/var/run/postgresql:5432 - accepting connections
[platform-postgresql] Granting SUPERUSER to toptal role
ALTER ROLE
[platform-postgresql] Set development environment
Top level ::CompositeIO is deprecated, require 'multipart/post' and use `Multipart::Post::CompositeReadIO` instead!
Top level ::Parts is deprecated, require 'multipart/post' and use `Multipart::Post::Parts` instead!
WARNING: Zeitwerk defines the constant Karafka after the directory
/Users/sulmanweb/.gem/gems/karafka-sidekiq-backend-1.4.6/lib/karafka
@sulmanweb
sulmanweb / export_transaction_service.rb
Last active September 7, 2022 06:53
Export User Transactions in CSV and upload to Active Storage or send as attachment in email #rails
# frozen_string_literal: true
# app/services/export_services/export_transaction_service.rb
# Example:
# ExportServices::ExportTransactionService.new({ user: User,last}).call
# ExportServices::ExportTransactionService.new({ user: User.last, from_date: '2022-01-01', to_date: '2022-09-01'}).call
module ExportServices
# ExportTransactionService
class ExportTransactionService
# initialize the service with user, from_date and to_date and setting transactions accordingly
@sulmanweb
sulmanweb / email_job.rb
Created September 7, 2022 03:05
Send Emails using SendGrid SDK for Ruby in Rails using Dynamic SendGrid Email Templates
# frozen_string_literal: true
require 'sendgrid-ruby'
#### Example Call
# EmailJob.new.perform(
# @user.id,
# { name: @user.name },
# ENV.fetch('EXPORT_TEMPLATE', nil),
# [
@sulmanweb
sulmanweb / click_button.dart
Created June 21, 2022 09:16
Flutter Assignment 1
import 'package:flutter/material.dart';
class ClickButton extends StatelessWidget {
final VoidCallback onPressedHandler;
const ClickButton({Key? key, required this.onPressedHandler})
: super(key: key);
@override
Widget build(BuildContext context) {
@sulmanweb
sulmanweb / create_document.rb
Created January 7, 2022 11:50
ActiveStorage, Ruby on Rails 7, GraphQL and RSpec
# app/graphql/mutations/create_document.rb
module Mutations
class CreateDocument < Mutations::BaseMutation
description "Create a document"
argument :doc, ApolloUploadServer::Upload, required: true, description: "The document to upload"
field :document, Types::Objects::DocumentType, null: false
field :code, Types::Enums::CodeEnum, null: false
@sulmanweb
sulmanweb / create_document.rb
Last active February 29, 2024 12:25
ActiveStorage file uploading in GraphQL API in Rails
# app/graphql/types/objects/document_type.rb
module Mutations
class CreateDocument < BaseMutation
description "creates a document for the user in the system"
argument :doc, ApolloUploadServer::Upload, required: true
field :document, Types::Objects::DocumentType, null: false
@sulmanweb
sulmanweb / api-rspec.yml
Created July 25, 2020 15:53
RSpec Rails API GitHub Actions Workflow
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 March 1, 2020 09:51
Minimal Responsive SignUp Page with TailwindCSS
<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 October 4, 2019 09:59
RSpec files
--require spec_helper
--format documentation