Skip to content

Instantly share code, notes, and snippets.

Avatar

streetsmartdev

View GitHub Profile
View KT-API-4-CompleteMultipleAsync.kt
fun main(args: Array<String>) {
val methodTime = measureTimeMillis {
val apiResult = runBlocking(Dispatchers.Default) {
val asyncResult1 = async { callApi() }
val asyncResult2 = async { callApi() }
val asyncResult3 = async { callApi() }
listOf(asyncResult1, asyncResult2, asyncResult3).awaitAll()
}
println(apiResult)
}
View KT-API-3-MeasureTime1Call.kt
fun main(args: Array<String>) {
val methodTime = measureTimeMillis {
val apiResult = runBlocking(Dispatchers.Default) {
val asyncResult = async { callApi() }
asyncResult.await()
}
println(apiResult)
}
println("Time: ${methodTime}ms")
View KT-API-2-CoroutineAsync.kt
fun main(args: Array<String>) {
val apiResult = runBlocking(Dispatchers.Default) {
val asyncResult = async { callApi() }
asyncResult.await()
}
println(apiResult)
}
fun callApi(): String {
View KT-API-1-SimpleOkHttp.kt
val client = OkHttpClient()
val okRequest = Request.Builder()
.url("https://httpbin.org/get")
.build()
val responseResource: Response = client.newCall(okRequest).execute()
return responseResource.use {
responseResource.body?.string()!!
View RN-HL-3-HorizontalFlatList.js
import React, { Component } from "react";
import { FlatList, Text } from "react-native";
import { Card } from "react-native-elements";
const data = [
{
imageUrl: "http://via.placeholder.com/160x160",
title: "something"
},
{
View RN-HL-2-FlatList.js
import React, { Component } from "react";
import { FlatList, Text } from "react-native";
import { Card } from "react-native-elements";
const data = [
{
imageUrl: "http://via.placeholder.com/160x160",
title: "something"
},
{
View RN-HL-1-Card.js
import React, { Component } from "react";
import { Text } from "react-native";
import { Card } from "react-native-elements";
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
data: data
};
@streetsmartdev
streetsmartdev / RN-RNav-10-RootNavigatorUpdate.js
Created Sep 3, 2017
RN-RNav - 10 - Updating RootNavigator
View RN-RNav-10-RootNavigatorUpdate.js
import React from "react";
import {StackNavigator} from "react-navigation";
import LoginScreen from "./external/Login";
import Internal from "./internal";
export default StackNavigator(
{
External: {screen: LoginScreen},
Internal: {screen: Internal}
},
View RN-RNav-9-ResetOnLogin.js
...
import {NavigationActions} from "react-navigation";
class LoginScreen extends React.Component {
render() {
const reset = NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: "Internal" })]
});
return (
@streetsmartdev
streetsmartdev / RN-RNav-8-NavigationHelper.js
Created Sep 3, 2017
RN-RNav- 8 - Implement navigationOptions and call them in individual screens
View RN-RNav-8-NavigationHelper.js
// NavigationHelper.js -----------------------------------------------
import React from "react";
import {Platform} from "react-native";
import {Ionicons} from '@expo/vector-icons';
export const getNavigationOption = (title, icon) => ({
title,
...Platform.select({
ios: {
tabBarIcon: ({tintColor}) => (