Skip to content

Instantly share code, notes, and snippets.

View rapPayne's full-sized avatar
:octocat:
Working from home

Rap Payne rapPayne

:octocat:
Working from home
View GitHub Profile
@rapPayne
rapPayne / gist:5281455eafc48184c35be0903a017bf9
Created September 21, 2017 16:37
Regex for simple package tracking numbers
^\d[A-Z]\d{16}$|^\d{14,15}$|^9[2-4]\d{2}( ?\d{4}){4} ?\d{2}$
@rapPayne
rapPayne / Landing.js
Last active March 23, 2019 22:49
React Native vs Flutter - React Native statefull component
import React, { Component } from 'react'; // <-- 1
import { Button, Image, SafeAreaView, ScrollView, Text, View } from 'react-native';
import { store } from './store/store'; // <-- 2
import { DatePicker } from './DatePicker'; // <-- 3
import { FilmBrief } from './FilmBrief'; // <-- 3
import { FilmDetails } from './FilmDetails'; // <-- 3
import { ShowingTimes } from './ShowingTimes'; // <-- 3
export class Landing extends Component { // <-- 4
constructor(props) { // <-- 5
@rapPayne
rapPayne / Landing.dart
Last active March 24, 2019 14:14
React Native vs Flutter - Flutter stateful widget
import 'package:flutter/material.dart'; // <-- 1
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart'; // <-- 2
import 'store/Actions.dart'; // <-- 2
import 'store/AppState.dart'; // <-- 2
import 'FilmBrief.dart'; // <-- 3
import 'FilmDetails.dart'; // <-- 3
import 'DatePicker.dart'; // <-- 3
import 'ShowingTimes.dart'; // <-- 3
@rapPayne
rapPayne / Landing.js
Last active March 24, 2019 14:43
React Native vs Flutter - React Native's rendering
render() {
const {showings,films,selected_date,selected_film,showFilmDetails}= {...this.state}; // <-- 9
return (
<SafeAreaView> // <-- 10
<ScrollView> // <-- 11
<View> // <-- 12
<View style={styles.header}> // <-- 12
<Image source={require(`./assets/daam.png`)} style={styles.logo} /> // <-- 13, 14
<Title>Dinner And A Movie</Title>
</View>
@rapPayne
rapPayne / Landing.dart
Last active March 24, 2019 14:34
React Native vs Flutter - Flutter's build method
@override
Widget build(BuildContext context) {
return StoreProvider<AppState>(
store: this.store,
child: StoreConnector<AppState, AppState>(converter: (store) {
return store.state;
},
builder: (context, callback) {
if (store.state.showFilmDetails) // <-- 9
return showFilmDetails(this.store.state.selectedFilm); // <-- 9
@rapPayne
rapPayne / callbackSig.dart
Last active June 3, 2019 22:44
Futures - Signature of a callback
void myCallback(Foo theIncomingData) {
 doSomethingWith(theIncomingData);
}
@rapPayne
rapPayne / async.dart
Last active April 29, 2019 13:11
Futures - Async before
Bar someFunction() {
  Foo theIncomingData = someFunction();
return new Bar();
}
@rapPayne
rapPayne / async.dart
Last active March 30, 2019 19:27
Futures - Async after
Future<Bar> someFunction() async {
Foo theIncomingData = await somethingThatReturnsAFuture();
return new Bar();
}
@rapPayne
rapPayne / futures.md
Last active March 30, 2019 19:41
Futures - Table of Futures examples
Type of future When it's ready, I'll have a ...
Future<String> ... string
Future<Foo> ... Foo
Future> ... Map whose keys are Strings and whose values are dynamic.
@rapPayne
rapPayne / AsynCallback.dart
Last active June 3, 2019 22:52
To get a value out of an async callback, you set an external variable
class FooState extends State<FooComponent> {
String _firstName; // <-- A variable known by the whole class
Widget build(BuildContext context) {
// return a widget
}
void _myCallback(String someVar) {
_firstName = someVar; // <-- Getting a value OUT of an async callback
}
}