Skip to content

Instantly share code, notes, and snippets.

View ovy9086's full-sized avatar

Ovidiu Latcu ovy9086

View GitHub Profile
/* eslint-disable @typescript-eslint/no-unused-vars */
// Reading
// Narrowing - https://www.typescriptlang.org/docs/handbook/2/narrowing.html
// Generics - https://www.typescriptlang.org/docs/handbook/2/functions.html#generic-functions
// Assignment
// Create a function executeHttpRequest that takes an argument of type HttpOptions (from the previous assignment) or a string representing a URL.
// - The function should return a Promise that resolves to a generic type T, which defaults to string.
// - If the argument is a string, it should be treated as a URL and the function should perform a GET request to that URL.
// - If the argument is of type HttpOptions, it should perform an HTTP request based on the provided options.
// Reading
// Union Types - https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types
// Literal Types - https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types
// Discriminated Uninons - https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
// Assignemnt
// Create a type HttpOptions that represents options for an HTTP request.
// The type should include:
// - A required url property of type string.
// - An optional headers property which is an object with string keys and string values.
type Mutation{
createEntry(entry: Entry!):EntryOutput!
}
input Entry {
geoToken: String!
amount: Float!
userId: String
picks: [Pick!]!
}
import React, { Component, PureComponent, useState } from 'react';
import {
Text,
StyleSheet,
View,
Button,
TouchableHighlight,
} from 'react-native';
export const Counters = () => {
...
render() {
return (
<View>
...
<CounterDisplay
style={styles.counter1}
value={this.state.counter1}
onPress={this.onCounterPress}
/>
...
<CounterDisplay
style={styles.counter1}
value={this.state.counter1}
onPress={value => alert(value)}
/>
<CounterDisplay
style={styles.counter2}
value={this.state.counter2}
onPress={value => alert(value)}
...
<CounterDisplay style={styles.counter1} value={this.state.counter1} />
<CounterDisplay style={styles.counter2} value={this.state.counter2} />
...
const styles = StyleSheet.create({
counter1: { width: 50, alignItems: "center", backgroundColor: "red" },
counter2: { width: 50, alignItems: "center", backgroundColor: "yellow" }
});
class CounterDisplay extends Component {
render() {
return (
<View {...this.props}>
<Text>{this.props.value}</Text>
</View>
);
}
}
...
export class Counters extends Component {
state = {
counter1: 0,
counter2: 0
};
render() {
return (
<View>
<Button
title={"Increase counter 1"}
Flowable.combineLatest(
locationStream.filter { it.accuracy < 20 },
azimuthStream,
combineLocationAndAzimuth())
.throttleLast(5, TimeUnit.SECONDS)
.flatMap { userData -> restApi.postUserData(userData) }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
//API response received