Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Mike Pyts mikepyts

🎯
Focusing
  • Odessa, Ukraine
View GitHub Profile
View Access webcam video stream in Flutter for Web
// ignore: avoid_web_libraries_in_flutter
import 'dart:html';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
void main() => runApp(WebcamApp());
class WebcamApp extends StatelessWidget {
@override
Widget build(BuildContext context) => MaterialApp(
View custom_scrollview.dart
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter_issues/custom_scrollable.dart' as custom_scrollable;
/// A widget that scrolls.
///
/// Scrollable widgets consist of three pieces:
View main.dart
import 'dart:math';
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:math' as math;
import 'dart:ui';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/painting.dart';
View custom_scrollbar.dart
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter_issues/custom_scrollable.dart' as custom_scrollable;
/// A widget that scrolls.
///
/// Scrollable widgets consist of three pieces:
View custom_scollable.dart
import 'dart:async';
import 'dart:math' as math;
import 'dart:ui';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/painting.dart';
View DataHolders.kt
// Data holders
val temperatureData = mutableListOf<Float>()
val pressureData = mutableListOf<Float>()
val timeData = mutableListOf<Float>()
// Convert data from BigQuery JsonTable to data arrays
fun processData(tableData: JsonTable) {
tableData.rows.forEach {
it.f.forEachIndexed { index, element ->
when (index) {
View BigQueryDataClasses.kt
// Data classes for JSON deserialization
data class JsonTable(@SerializedName("rows") val rows: List<Row>) {
data class Row(@SerializedName("f") val f: List<F>) {
data class F(@SerializedName("v") val v: String)
}
}
View pullTableData.kt
// Get table
fun pullData() {
when (token) {
"Empty" -> {
authenticateAndAuthorize()
}
else -> {
doAsync {
val apiCall = gcpService.getTable("Bearer $token", 15).execute()
Log.d("JSON", apiCall.body().toString())
@mikepyts
mikepyts / RetrofitSetUp.kt
Created Apr 13, 2019
Shows set up of Retrofit interface
View RetrofitSetUp.kt
// Retrofit interface
interface GCPService {
@GET("/bigquery/v2/projects/weather-231121/datasets/WeatherDataSet/tables/WeatherDataTable/data")
fun getTable(@Header("Authorization") token: String, @Query("startIndex") startIndex: Int): Call<JsonObject>
}
// Retrofit builder
private val retrofitBuilder = Retrofit.Builder()
.baseUrl("https://content.googleapis.com")
.addConverterFactory(GsonConverterFactory.create())
@mikepyts
mikepyts / GoogleApi.kt
Created Apr 13, 2019
Authentificate and authorize to Google APIs
View GoogleApi.kt
// Access scopes
private val accessScope = listOf("https://www.googleapis.com/auth/cloud-platform.read-only")
private var token = "Empty"
// Receive Google OAuth 2 token for API access
private fun authenticateAndAuthorize() {
doAsync {
val googleCredential = GoogleCredential
.fromStream(ctx.assets.open("service-account.json"))
.createScoped(accessScope)