Skip to content

Instantly share code, notes, and snippets.

View apgapg's full-sized avatar
😉
Still not born...

Ayush P Gupta apgapg

😉
Still not born...
View GitHub Profile
@apgapg
apgapg / behavior_subject_extension.dart
Created September 24, 2020 03:29
Extension on Behavior Subject to add data or error safely without explicitly checking for subject close
import 'package:rxdart/subjects.dart';
extension BehaviorSubjectX<T> on BehaviorSubject<T> {
/// Add [data] only when stream is not closed
///
/// No data is added if stream is closed
void addDataSafely(T data) {
if (!isClosed) {
return sink.add(data);
} else {
@apgapg
apgapg / jsconfig.json
Created September 14, 2020 05:36
Adding path alias in vs code to resolve @ (for src/) in imports
{
"include": [
"./src/**/*"
],
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@/*": [
"./*"
]
@apgapg
apgapg / ReadFileStream.dart
Created August 20, 2020 13:05
Read file as Stream in dart
void readFileStream() {
Stream<List<int>> stream = new File('./assets/user.json').openRead();
StringBuffer buffer = new StringBuffer();
stream
.transform(utf8.decoder)
.listen((data) {
buffer.write(data);
},
onDone: () => print(buffer.toString()),
onError: (e) => print(e));
@apgapg
apgapg / scrap.dart
Created July 19, 2020 07:25
Scrap data from website
void initChaptersTitleScrap() async {
final rawUrl =
'https://unacademy.com/course/gravitation-for-iit-jee/D5A8YSAJ';
final webScraper = WebScraper('https://unacademy.com');
final endpoint = rawUrl.replaceAll(r'https://unacademy.com', '');
if (await webScraper.loadWebPage(endpoint)) {
final titleElements = webScraper.getElement(
'div.Week__Wrapper-sc-1qeje5a-2 > a.Link__StyledAnchor-sc-1n9f3wx-0 '
'> div.ItemCard__ItemInfo-xrh60s-1 '
'> h6.H6-sc-1gn2suh-0',
@apgapg
apgapg / deploy.yml
Last active October 7, 2023 16:23
Github Workflow for Building, Releasing Flutter web app to Github Pages and Firebase Hosting
# This is a basic workflow to help you get started with Actions
name: Build, Release app to Github Pages and Firebase Hosting
# name: Test, Build and Release apk
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- master
@apgapg
apgapg / my_stream_builder.dart
Created April 20, 2020 14:16
Wrapper of StreamBuilder for managing error and loading on its own. Fully customisable
import 'package:flutter/material.dart';
import 'package:workozy_app/widgets/helper/stream_error_widget.dart';
import 'package:workozy_app/widgets/helper/stream_loading_widget.dart';
typedef OnData<T> = Widget Function(T data);
typedef OnError = Widget Function(dynamic e);
typedef OnLoading = Widget Function();
class MyStreamBuilder<T> extends StatelessWidget {
MyStreamBuilder({
@apgapg
apgapg / main.yml
Created April 20, 2020 10:01
Github Action for Flutter Build, Test, Release and Upload app
# This is a basic workflow to help you get started with Actions
name: Test, Build, Release Demo app to Azure Storgae
# name: Test, Build and Release apk
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
@apgapg
apgapg / logging_interceptor.dart
Created April 9, 2020 05:37
Logging interceptor for dio, flutter
import 'dart:async';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
/// [LoggingInterceptor] is used to print logs during network requests.
/// It's better to add [LoggingInterceptor] to the tail of the interceptor queue,
/// otherwise the changes made in the interceptor behind A will not be printed out.
/// This is because the execution of interceptors is in the order of addition.
class LoggingInterceptor extends Interceptor {
@apgapg
apgapg / user_repository_impl.dart
Created March 21, 2020 10:10
Firebase user repository implementation for flutter firebase auth
import 'dart:async';
import 'dart:convert';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:connectit_app/data/local/prefs/prefs_helper.dart';
import 'package:connectit_app/data/model/result.dart';
import 'package:connectit_app/data/model/user.dart';
import 'package:connectit_app/data/repo/user/google_login_repository.dart';
import 'package:connectit_app/di/injector.dart';
import 'package:connectit_app/utils/log_utils.dart';
@apgapg
apgapg / NetworkError.vue
Created January 7, 2020 06:12
Error Card in Vue, Vuetify
<template>
<v-container fluid>
<v-card outlined>
<v-container class="py-8">
<div class="d-flex justify-center mb-4">
<v-icon size="40">mdi-emoticon-sad-outline</v-icon>
</div>
<p class="title text-center my-0 py-0 grey--text text--darken-3">Oops! Something totally went wrong</p>
<p class="subtitle-1 red--text text-center my-0 py-0">{{error}}</p>