Skip to content

Instantly share code, notes, and snippets.

Avatar

Amr Yousef amrfarid140

View GitHub Profile
View test results
00:00 +0: Firestore (setUpAll)
00:00 +1: Firestore getDocumentsWithFirestoreSettings
00:01 +2: Firestore getDocumentsFromCollection
00:02 +3: Firestore getDocumentsFromCollectionGroup
00:02 +4: Firestore increment
00:05 +5: Firestore includeMetadataChanges
00:06 +6: Firestore runTransaction
00:08 +7: Firestore pagination
00:11 +8: Firestore pagination with map
00:13 +9: Firestore FieldPath.documentId
@amrfarid140
amrfarid140 / main.dart
Last active Oct 11, 2019
Basic BLoC example
View main.dart
import 'package:flutter_web/material.dart';
import 'package:flutter_web_ui/ui.dart' as ui;
import 'dart:async';
void main() async {
await ui.webOnlyInitializePlatform();
runApp(MyApp());
}
abstract class MyHomePageAction {
@amrfarid140
amrfarid140 / main.dart
Last active Sep 8, 2019
Basic Stateful Widget
View main.dart
import 'package:flutter_web/material.dart';
import 'package:flutter_web_ui/ui.dart' as ui;
void main() async {
await ui.webOnlyInitializePlatform();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
View RTCClient.kt
package me.amryousef.homedoor.common
import android.app.Application
import android.content.Context
import org.webrtc.Camera2Enumerator
import org.webrtc.EglBase
import org.webrtc.IceCandidate
import org.webrtc.MediaConstraints
import org.webrtc.PeerConnection
import org.webrtc.PeerConnectionFactory
@amrfarid140
amrfarid140 / AppDatabase.ts
Created Jul 11, 2018
Database schema definition
View AppDatabase.ts
import Dexie from "dexie";
import { IRepositroy } from "./models/Repository";
export class AppDatabase extends Dexie {
public repos: Dexie.Table<IRepositroy, number>;
constructor() {
super("sample-database");
this.version(1).stores({
repos: "++id,name,html_url,description"
});
@amrfarid140
amrfarid140 / Dao.ts
Created Jul 11, 2018
Data access object
View Dao.ts
import { Observable, Observer } from "rxjs";
import { AppDatabase } from "./AppDatabase";
import { IRepositroy } from "./models/Repository";
export class Dao {
private db: AppDatabase;
private observablesList: Array<Observer<IRepositroy[]>> = [];
constructor() {
this.db = new AppDatabase();
}
@amrfarid140
amrfarid140 / ApiService.ts
Created Jul 11, 2018
A service that uses Axios to fetch list of Facebook repositories
View ApiService.ts
import axios from "axios";
import { Observable, Observer } from "rxjs";
import { IRepositroy } from "./models/Repository";
export class ApiService {
private readonly baseUrl = "https://api.github.com/";
public getRepos(): Observable<IRepositroy[]> {
return Observable.create(async (observer: Observer<IRepositroy[]>) => {
try {
const response = await axios.get<IRepositroy[]>(
`${this.baseUrl}orgs/facebook/repos`
@amrfarid140
amrfarid140 / ViewRepositoriesUseCase.ts
Last active Jul 11, 2018
Use case to manage viewing Facebook repositories
View ViewRepositoriesUseCase.ts
import { Observable, of } from "rxjs";
import { flatMap } from "rxjs/operators";
import { ApiService } from "../data/ApiService";
import { Dao } from "../data/Dao";
import { IRepositroy } from "../data/models/Repository";
export class ViewRepositoriesUseCase {
private readonly apiService: ApiService;
private readonly dataDao: Dao;
View AppViewModel.ts
import { action, observable } from "mobx";
import { IRepositroy } from "../data/models/Repository";
import { ViewRepositoriesUseCase } from "../domain/ViewRepositoriesUseCase";
export class AppViewModel {
@observable public items: IRepositroy[] = [];
@observable public errors: string[] = [];
private readonly useCase: ViewRepositoriesUseCase;
constructor(useCase: ViewRepositoriesUseCase) {
this.useCase = useCase;
this.prepare();
@amrfarid140
amrfarid140 / App.tsx
Created Jul 11, 2018
Main View for the web app
View App.tsx
import { observer } from 'mobx-react';
import * as React from 'react';
import { AppViewModel } from './AppViewModel';
@observer class App extends React.Component< {model: AppViewModel} ,{}> {
public render() {
return (
<div>
<button onClick={this.props.model.refresh} >Refresh List</button>
<button onClick={this.props.model.clearData} >Clear List</button>
You can’t perform that action at this time.