|OT| Programming - console.log("I know Kung-Fu!");

BlackRainbowFT

Mouse Accelerated Member
Apr 17, 2019
408
909
93
35
Switzerland
Anyone here familier with building websites with java, jsp, database connection and all that nice stuff? I have an assignment but I've constantly been behind that I'm just so lost, the teacher just dumps assignments on us so feel like I'm not learning the important stuff.
Teacher? I might be misremembering but I thought you were trying to learn on your own!

I'm not a Java expert... so I can't really help you, sorry. I know my way around both Access and SQ/MySQL but I use them so infrequently that I rely on cheat sheets (same goes for Regex, JSON parsing, etc.).
 
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
Teacher? I might be misremembering but I thought you were trying to learn on your own!

I'm not a Java expert... so I can't really help you, sorry. I know my way around both Access and SQ/MySQL but I use them so infrequently that I rely on cheat sheets (same goes for Regex, JSON parsing, etc.).
I actually enrolled in a app development program last fall!:D So I will have a shiny degree and all, well hopefully considering how much problem I have.XD Having the classes online thanks to covid really isn't helping me learn AND the classes are in French. But I do hope it is giving me enough for a foundation that I can manage to learn and do projects on my own much better.
 
  • Like
Reactions: BlackRainbowFT

BlackRainbowFT

Mouse Accelerated Member
Apr 17, 2019
408
909
93
35
Switzerland
I actually enrolled in a app development program last fall!:D So I will have a shiny degree and all, well hopefully considering how much problem I have.XD Having the classes online thanks to covid really isn't helping me learn AND the classes are in French. But I do hope it is giving me enough for a foundation that I can manage to learn and do projects on my own much better.
Then good luck to you! I think you've made the right choice by enrolling in such a program... it'll help you on staying focused on clearly defined goals!
 
  • Hug
Reactions: Le Pertti
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
I'm starting to work on the last project in my class and I am going to do an app for iPhone. I'm going to use React Native. My question is since I am guessing Xcode would be quite good to use for that but I am not at all familiar with it, mostly just used VS Code. Any of you familiar with both that can tell me if it is a good idea to do the switch?
 

Copons

MetaMember
Nov 12, 2018
419
1,021
93
Brighton, UK
copons.wordpress.com
I'm starting to work on the last project in my class and I am going to do an app for iPhone. I'm going to use React Native. My question is since I am guessing Xcode would be quite good to use for that but I am not at all familiar with it, mostly just used VS Code. Any of you familiar with both that can tell me if it is a good idea to do the switch?
Not a mobile dev, but I think it's fine to stick with VSCode as editor, and only use Xcode for testing the app (IIRC React Native has its own way of launching the Xcode device emulator?) or eventually publishing it to the app store.

Either way, code editors are in most cases a personal preference.
If you are comfortable with VSCode, and it gives you a good dev workflow, there's rarely need to switch to anything else.
Of course if you want to try other editors, go for it! :)
 

spiel

Junior Member
Apr 17, 2019
35
77
18
I'm starting to work on the last project in my class and I am going to do an app for iPhone. I'm going to use React Native. My question is since I am guessing Xcode would be quite good to use for that but I am not at all familiar with it, mostly just used VS Code. Any of you familiar with both that can tell me if it is a good idea to do the switch?
I use React Native at work, I can't remember the last time I opened Xcode beyond setting up code signing. Ideally, most of the work will be done in Javascript land, you only occasionally need to touch native code if debugging/working with advanced, platform-specific stuff.

Copons is right, you can launch the app on the iOS simulator and Android emulator from the command line.
 
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
Copons spiel Thanks for the input! I think the main reason I want to go for Xcode is that to be familiar with it, but also because since last month iOS apps need to use Xcode. Meaning I don't think it is enough to just sign code. I'm not sure .

But yeah I do get up the iOS simulator and all through terminal, but when I try to open the iOS project in Xcode I get a few "files missing" things. I've followed a few different guides so I think I have installed a bunch of different stuff for react native so might be some conflicts going on.
 
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
Copons spiel I've figure out where things went wrong, I can install cocoapods fine but when I try to run pod install inside the iOS folder the install aborts and says it crashed. So it doesn't install all the dependencies. Any experience with that and what could be causing something like that?


Code:
pertti@Perttis-Mac-mini ios % pod install                 
Analyzing dependencies
Fetching podspec for [ICODE]DoubleConversion[/ICODE] from [ICODE]../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec[/ICODE]
Fetching podspec for [ICODE]RCT-Folly[/ICODE] from [ICODE]../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec[/ICODE]
Fetching podspec for [ICODE]glog[/ICODE] from [ICODE]../node_modules/react-native/third-party-podspecs/glog.podspec[/ICODE]
/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0/lib/ffi/library.rb:275: [BUG] Bus Error at 0x0000000100814000
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.arm64e-darwin20]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:                   
     * ~/Library/Logs/DiagnosticReports                                     
     * /Library/Logs/DiagnosticReports                                     
   for more details.                                                       
Don't forget to include the above Crash Report log file in bug reports.
It seems to crash there.
 
Last edited:

spiel

Junior Member
Apr 17, 2019
35
77
18
Hmm no, not experienced that particular error. Are you running this on a clean React Native project? (just to figure out if it's a newly installed dependency causing the error) Maybe try upgrading Ruby.

Edit: are you using a Mac with an M1 chip by any chance?
 
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
Hmm no, not experienced that particular error. Are you running this on a clean React Native project? (just to figure out if it's a newly installed dependency causing the error) Maybe try upgrading Ruby.

Edit: are you using a Mac with an M1 chip by any chance?
Ah yeah precisely ! I'm on the new Mac mini with the M1. Haven't really had any problems thus far so never occurred to me that might be the issue.
 
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
Update Ruby and ffi as suggested in this comment, with any luck that should resolve that particular error.
Seems there was an issues with trying to update ruby, but I managed it now and it downloaded everything!:D BUT now that I open the correct workspace in Xcode, there is hundreds and hundreds of errors haha. Think I need to just get started and stick with vscode and move onto Xcode later.
 
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
Today was the first day of the project I'm doing instead of an internship in my school. Started following a tutorial how to build a React native app using Firebase. Now have a register and login function on the app. Its a start!:D Have like 40 days to make an app that is so cool and impressive that a panel of experts think I deserve to graduate. No pressure haha
 
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
I have to say that the instant update from working with expo and react native is such useful thing! The first time I did the tutorial I didn't pay much attention to having instant feedback so it was a broken mess. So I'm redoing it now and constantly having my phone open with the code running and the moment something doesn't work I can go back and look through code. Sometimes it can be something simple as a typo. Such a nice feeling having something you made, running as intended on your phone!
 
  • Like
Reactions: Pommes and spiel
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
JavaScript:
const savePostData = (downloadURL) => {
        firebase.firestore()
        .collection('posts')
        .doc(firebase.auth().currentUser.uid)
        .collection("userPosts")
        .add({
            downloadURL,
            caption,
            createdAt: firebase.firestore.FieldValue.serverTimestamp()
        }).then((function(){
            this.props.navigation.dispatch(StackActions.popToTop());
            //props.navigation.popToTop()
        }))
    }
I have this problem where the serverTimestamp gives me an error and I don't know why? Ive been googling and it seems right to me?

This is the error

 

Swenhir

Spaceships!
Apr 18, 2019
3,354
7,142
113
JavaScript:
const savePostData = (downloadURL) => {
        firebase.firestore()
        .collection('posts')
        .doc(firebase.auth().currentUser.uid)
        .collection("userPosts")
        .add({
            downloadURL,
            caption,
            createdAt: firebase.firestore.FieldValue.serverTimestamp()
        }).then((function(){
            this.props.navigation.dispatch(StackActions.popToTop());
            //props.navigation.popToTop()
        }))
    }
I have this problem where the serverTimestamp gives me an error and I don't know why? Ive been googling and it seems right to me?

This is the error

Well, from the top of my head and googling the API quickly it seems like it returns as being undefined, meaning you missed a step in there. Is FieldValue supposed to have some sort of initialization? Is serverTimestamp supposed to be initialized itself? I don't know this at all but that's the usual issue.

I for instance see that people are using this as part of a set() call.
 
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
Well, from the top of my head and googling the API quickly it seems like it returns as being undefined, meaning you missed a step in there. Is FieldValue supposed to have some sort of initialization? Is serverTimestamp supposed to be initialized itself? I don't know this at all but that's the usual issue.

I for instance see that people are using this as part of a set() call.
Ah yeah I'm using Add since I'm adding a whole new entry into the database. I was also reading that article as you posted before haha, I tried set also.XD

So frustrating, the tutorial that Im following does the same but for him it works.
 

Swenhir

Spaceships!
Apr 18, 2019
3,354
7,142
113
Ah yeah I'm using Add since I'm adding a whole new entry into the database. I was also reading that article as you posted before haha, I tried set also.XD

So frustrating, the tutorial that Im following does the same but for him it works.
This is the sort of stuff that turned me off programming to be honest with you. Still, reading the error message, you have a few things to go on. The syntax is good, the issue is that the parent member appears to be undefined. Is there something that is supposed to happen to it, or do you have a way to debug and look at its state before you call it?
 
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
JavaScript:
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/database';
import 'firebase/firestore';
import 'firebase/storage';



const firebaseConfig = {
    apiKey: "1234567",
    authDomain: "2345678",
    projectId: "1234567",
    storageBucket: "123456",
    messagingSenderId: "1234567",
    appId: "1234567",
    measurementId: "1234567"
  };


  //firebase.initializeApp(firebaseConfig)

  export default !firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app().firestore();
Maybe there is something wrong with how I implement firebase? Ive seen several other ways to do it, but this is the only way that works for me at the moment. I know too little to even know how else to do it.
 

Swenhir

Spaceships!
Apr 18, 2019
3,354
7,142
113
JavaScript:
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/database';
import 'firebase/firestore';
import 'firebase/storage';



const firebaseConfig = {
    apiKey: "1234567",
    authDomain: "2345678",
    projectId: "1234567",
    storageBucket: "123456",
    messagingSenderId: "1234567",
    appId: "1234567",
    measurementId: "1234567"
  };


  //firebase.initializeApp(firebaseConfig)

  export default !firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app().firestore();
Maybe there is something wrong with how I implement firebase? Ive seen several other ways to do it, but this is the only way that works for me at the moment. I know too little to even know how else to do it.
I'm afraid to say that I really don't know much about javascript and those APIs in general, so I could only offer those vague ideas. I do wonder what you have in the way of logs and debugs tools. For instance, can you try to access that structure you have in increasing levels of depth to see where the initialization fails?
 
  • Like
Reactions: Le Pertti

spiel

Junior Member
Apr 17, 2019
35
77
18
Maybe there is something wrong with how I implement firebase? Ive seen several other ways to do it, but this is the only way that works for me at the moment. I know too little to even know how else to do it.
I'm not familiar with firebase but from what I can see:
  • First of all you are possibly exporting two different things in your firebase file depending on firebase.apps.length. firebase.initializeApp() returns a Firebase App instance, while firebase.app().firestore() returns the Firestore service, and both have different apis.
  • Actually, there's no need to handle firebase.apps.length if you only need to initialise Firebase once. I imagine your local Firebase module could look something like this:
JavaScript:
// assuming this is located at src/firebaseApp.js
import firebase from "firebase/app";
// your other code here

// Initialize Firebase
const firebaseApp = firebase.initializeApp(firebaseConfig);

export default firebaseApp;
And in other parts of your code you can just import it easily
JavaScript:
import firebaseApp from "./firebaseApp";

firebaseApp.firestore().collection(...)
  • You can't get FieldValue on the firestore returned by your Firebase App instance. Instead, you have to access it from the npm module. I don't get it either, it just do be like that sometimes.
JavaScript:
// note that one is from the package and the other one is from your initialised Firebase App instance
import firebase from "firebase/app";
import firebaseApp from "./firebaseApp";

// this is ok
console.log(firebase.firestore.FieldValue.serverTimestamp());
// this is not. FieldValue is undefined here, so now it's trying to get serverTimestamp from undefined, resulting in that unhelpful error
console.log(firebaseApp.firestore.FieldValue.serverTimestamp());
 
Last edited:
  • Like
Reactions: Le Pertti
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
spiel Its getting little over my head everything now haha, but the length thing is something I added into the initialise because there were an error that I was initialising firebase too many times, so as I gather, it checks that it isn't running and then initialises it?



IT WORKS! I did as you suggested, have a firebaseApp for everything else but called firebase/app just for that.

I did my firebase file like this and it still works fine?

JavaScript:
const firebaseApp = !firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app().firestore();

export default firebaseApp
 
Last edited:

spiel

Junior Member
Apr 17, 2019
35
77
18
spiel Its getting little over my head everything now haha, but the length thing is something I added into the initialise because there were an error that I was initialising firebase too many times, so as I gather, it checks that it isn't running and then initialises it?
My understanding is that the firebaseApp module would be cached (more info on module caching in Nodejs) so firebase.initializeApp() gets called only once no matter how many times you import firebaseApp. Maybe it depends on how your app is set up. To be sure, you can do a console.log(firebase.apps.length) at the last line in that file and check if that gets printed multiple times/is greater than 1 in a single session of the app. But anyway, if it works, it works :grinning-face:
 
  • Hug
Reactions: Le Pertti
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
Now I have a weird problem! I have a camera function and when I take a photo it goes to a save photo screen, but first there is no image to save, so when I cancel and take another photo and go to the save screen it tries to save the photo from the first take!

right now my code is very simple and have it like this;

JavaScript:
const [image, setImage] = useState(null);

const takePhoto = async () => {
    if(camera){
        const data = await camera.takePictureAsync(null)
        setImage(data.uri);
        
    }
    navigation.navigate('Save', {image})
  }
 
OP
Le Pertti

Le Pertti

0,60% PC Gamer 100% Xbox Bro
Oct 10, 2018
5,067
10,595
113
42
Paris, France
perttiteurajarvi.com
JavaScript:
import React, { Component } from 'react';
import { Text, View, TouchableOpacity} from 'react-native';
import * as Font from 'expo-font';
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5'

import { NavigationContainer } from '@react-navigation/native';

import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();
const Settings = createStackNavigator();


import firebaseApp from './tools/firebase'

import { Provider } from 'react-redux'
import { createStore, applyMiddleware } from 'redux'
import rootReducer from './redux/reducers'
import thunk from 'redux-thunk'
const store = createStore(rootReducer, applyMiddleware(thunk))

import LandingScreen from './components/auth/Landing'
import RegisterScreen from './components/auth/Register'
import LoginScreen from './components/auth/Login'
import MainScreen from './components/Main'
import AddScreen from './components/main/Add'
import SaveScreen from './components/main/Save'

import SettingsScreen from './components/settings/Settings'
import PreferencesScreen from './components/settings/Preferences'




export class App extends Component {
  constructor(props){
    super(props);
    this.state = {
      loaded: false,
    }
  
  }
  state = {
    fontsLoaded: false,
  };
 

  async loadFonts() {
    await Font.loadAsync({
      // Load a font [ICODE]Montserrat[/ICODE] from a static resource
      CormorantGaramond: require('./assets/fonts/Cormorant_Garamond/CormorantGaramond-LightItalic.ttf'),

      // Any string can be used as the fontFamily name. Here we use an object to provide more control
      'CormorantGaramond-SemiBold': {
        uri: require('./assets/fonts/Cormorant_Garamond/CormorantGaramond-SemiBold.ttf'),
        display: Font.FontDisplay.FALLBACK,
      },
    });
    this.setState({ fontsLoaded: true });
  }

 
  componentDidMount(){
    firebaseApp.auth().onAuthStateChanged((user) => {
      if(!user){
        this.setState({
          loggedIn: false,
          loaded: true,
        })
      }else {
      this.setState({
        loggedIn: true,
        loaded: true,
      })
      }
      
    })
    this.loadFonts();
  }

 

  render() {
    
    const {navigation} = this.props;
    const {loggedIn, loaded} = this.state;
    if(!loaded){
      return(
        <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center'}}>
          <Text>Loading</Text>
        </View>
      )
    }
    
    if(!loggedIn){
      
      return (
        <NavigationContainer>
          <Stack.Navigator initialRouteName="Landing">
            <Stack.Screen name="Landing" component={LandingScreen} options={{ headerShown: false}}></Stack.Screen>
            <Stack.Screen name="Register" component={RegisterScreen} options={{ headerShown: false}}></Stack.Screen>
            <Stack.Screen name="Login" component={LoginScreen} options={{ headerShown: false}}></Stack.Screen>
          </Stack.Navigator>
        </NavigationContainer>
      );
    }
    
  
    function LogoTitle() {
      return (
        <Text
        style={{
          fontSize: 50,
          fontFamily: 'CormorantGaramond',
          //fontWeight: "bold"
          }}
[QUOTE][/QUOTE]
            Thirstily</Text>
      );}
      function Root(){
        return (
      <Settings.Navigator  mode="modal">
        
            <Settings.Screen
              name="Preferences"
              component={PreferencesScreen}
           />
            
            <Settings.Screen
              name="Settings"
              component={SettingsScreen}
            />
            </Settings.Navigator>
      );
      }
  return (
    
    <Provider store={store}>
      <NavigationContainer>
            <Stack.Navigator initialRouteName="Main"
              screenOptions={{
                headerShown: true,
                headerTitle: props => <LogoTitle {...props} />,
                headerStyle: {
                  //backgroundColor: '#f4511e',
                  height: 120
                },
              
              
                headerLeft: () => (
                  <TouchableOpacity
                  onPress={() =>  navigation.navigate('Root', { screen: 'Preferences'})}>
                  <FontAwesome5
                  name="address-card"
                  style={{ color: "#aaa", fontSize: 25, marginLeft: 10}} />
                  </TouchableOpacity>
              
                ),
                
                headerRight: () => (
                  <TouchableOpacity
                  onPress={() => navigate('Settings')}>
                  <FontAwesome5
                  name="screwdriver"
                  style={{ color: "#aaa", fontSize: 25, marginRight: 10}} />
                  </TouchableOpacity>
                
                ),
                
                }} >
            <Stack.Screen name="Main" component={MainScreen}/>
            <Stack.Screen name="Add" component={AddScreen} navigation={this.props.navigation}/>
            <Stack.Screen name="Save" component={SaveScreen} navigation={this.props.navigation}/>
            <Stack.Screen name="Root" component={Root} options={{ headerShown: false }}/>
            </Stack.Navigator>
          
      </NavigationContainer>
      
   </Provider>
  
  
  )
 
};
}

export default App

I've been stuck on this so long! I can't seem to get a screen to come, the Preferences and Settings that are in the header. I just get a variation of navigation errors or with this code it is "undefined is not an object(evaluating 'navigation.navigate')

I have less than two weeks to finish the project and I've been way too stuck on this! T_T
 

EdwardTivrusky

See You Hyper-Toxic Computer Cowboy
Dec 8, 2018
4,091
7,690
113
Sometimes all it takes to solve a problem is to talk about it to someone else even if they know nothing about the subject.
For me it seems to kick something in my subconscious, maybe something with having to verbalise the issue help arrange thoughts, i dunno.

Well done, Meta for solving Le Pertti's coding problem! Headpats all round!