Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

AnotherMax

Member
  • Content Count

    12
  • Joined

  • Last visited

Posts posted by AnotherMax


  1. I could be miss understanding but your asking why is there more then one row in the database or that when you refresh the page it inserts two records at once?

     

    Everytime you run the browser / load this up it will insert a new row into the database. Maybe you want a constraint in the database to not have a row with the same name and age?


  2. I don't really know any JQuery any more but if you want to programmtically add/remove something based on a boolean value it should be quite straight forward like so: This uses formated strings, so you can kinda add variables into strings using `${variable_name}` or a ternary operater which are really nice to use: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

    function get_image_name(filename, is_checked) {
      // Returns the file name with 'F' attached if is_checked is true, 
      // otherwise just the filename with '.png' appeneded.
      return `${filename}${(is_checked) ? 'F' : ''}.png`  // Backticks allow for formatted strings
    }
    
    x = get_image_name("picture_1", true)  // Returns --> picture_1F.png
    
    y = get_image_name("picture_1", false)  // Returns --> picture_1.png

    You can ofcouse modify the 'F' to be what you want etc or even add it as an extra parameter.

    Though thinking about it, this may or may not work depending on how you get the 'current' filename. As if you get it from the 'src' you'd need ot strip out the 'F.png', To do that you'd want to first remove the '.png' as thats consitent could use: str.replace(".png", "") -> returns new string without '.png', then add a check to see if the magical 'F' is the last index in the string, if it is then you can replace that then you'll have the original file name without the prefix.

     


  3. 2 hours ago, Hi P said:

    I feel so screwed up, web app seems to be where employment is at, but I don't have a bit of an interest on it :(

    Yeah, it seems to be whats happening, you can still get just backend dev jobs but they are just harder to find. You can however in python use templating to generate static html pages like: Jinja or check out this: https://wiki.python.org/moin/Templating

    I was hired doing just backend but started doing frontend, not that I super wanted to but it has grown on me. (we use VueJS which is picking up traction)


  4. Assuming all '.py' files are in the same directory, and 'file_to_import.py' is simply made up of a bunch of function I'd do:

    from file_to_import import function_name_1, function_name_2
    from file_to_import import *  # Imports all functions from 'file_to_import'

    I wouldn't do the import with the ` * ` as it's a bit ambiguous.

     

    If you have a directory structure like:

    - main.py
    - utils
      \ - thingy.py
      

    If you want to import 'thingy.py' functions into the 'main.py' you can do:

    from utils.thingy import function_name_1, function_name_2

  5. It looks like you're using this: https://www.npmjs.com/package/firebase/v/3.1.0

    Perhaps try and incude just the things you need (This would make the website download less which is good: 

    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-auth.js"></script>
    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-database.js"></script>
    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-storage.js"></script>

     

    Alternativly try using doing it this way, take a look at Step 3 and From the CDN. https://firebase.google.com/docs/web/setup#add_firebase_to_your_app


  6. Hey,

     

    I spent a couple hours this morning creating the extension. I've never made one before and it was pretty fun!

    I've published it on the marketplace too! (Its called 'WhatFile')

    https://marketplace.visualstudio.com/items?itemName=MaxHorwood.whatfile

    The README has what you need to set in your settings.

     

    It was surprisingly easy to write this, it was more of a challenge to upload it :D

    If you wanna write an extension I'd recommend looking at: https://code.visualstudio.com/api/get-started/your-first-extension

    Max


  7. String query = "INSERT INTO table1(Emp_no,Date,salary) VALUES (?, ?, ?)";
    
    PreparedStatement pStatement;
    try {
      // getConnection() is DriverManager.getConnection(); I have things set up in seperate classes
      pStatement = getConnection().prepareStatement(query);
    
      pStatement.setInt(1, empid);
      // you should be able to do setDate() if thats how your DB is set up
      pStatement.setString(2, localDate);
      pStatement.setInt(3, w_amount);
    
      pStatement.executeUpdate();
    } catch (SQLException ex) {
      Logger.getLogger(DBInterface.class.getName()).log(Level.SEVERE, null, ex);
    }

    I've done this before. This is what I did.

     

     

     


  8. 83 Lines. Python 2.7.13.

    I needed a program that could copy 1 file into a bunch of directories which are all in the same directory. Couldn't find anything online so I made my own and wanted to share :)

    Additionally, I wanted to make a program with a GUI. So here you go!! :D

    For users who CBA to actually try it but want to see the sexy GUI:

    2c7b45aacb87f046c722b12d7d0cf5ab.png

     

    
    from Tkinter import *
    from tkFileDialog import askopenfilename
    from tkFileDialog import askdirectory
    import os
    import shutil
    
    def fileName1():
        filename = askopenfilename()
        labelText1.set(filename)
        return
    
    def copyFile(src, dest): # Copies file to dest
        try:
            shutil.copy(src, dest)
        # eg. src and dest are the same file
        except shutil.Error as e:
            print('Error 1: %s' % e)
        # eg. source or destination doesn't exist
        except IOError as e:
            print('Error 2: %s' % e.strerror)
    
    def main():
        fileToCopy = labelText1.get()
    
        if os.path.dirname(fileToCopy):
            isFolderFound = True
            if e.get() != "":
                if os.path.exists(e.get()):
                    isFolderFound = True
                else:
                    isFolderFound = False
            else:
                isFolderFound = False
    
            if isFolderFound:
                directory = os.listdir(dirToCopyTo.get()) # Stores all files and folders
                for files in directory:
                    # Files just returns folder name so add on to the DIR in the entry box
                    files = dirToCopyTo.get()+"/"+files
                    if os.path.isdir(files): # If dir (folder) then copyFile
                        copyFile(fileToCopy, files)
                        
                labelText2.set("Done")
            else:
                labelText2.set("Folder not found")
        else:
            labelText2.set("Pick a file")
    
    app = Tk()
    app.title("Copy file into all DIR")
    app.geometry('370x100+550+340')
    
    b1 = Button(app, text="Pick a File", command=fileName1, width=25)
    b1.grid(row=0, column=0, pady=5, padx=5)
    
    labelText1 = StringVar()
    labelText1.set("<----")
    e1 = Entry(app, textvariable=labelText1,width=25)
    e1.grid(row=0, column=1, pady=5, padx=5)
    
    def test():
        folderDir = askdirectory()
        dirToCopyTo.set(folderDir)
    
    Button(app, text="Folder Directory", command=test, width=25).grid(row=1, column=0)
    
    dirToCopyTo = StringVar()
    dirToCopyTo.set("")
    
    e = Entry(app, text=dirToCopyTo, width=25)
    e.grid(row=1, column=1, pady=5, padx=5)
    
    labelText2 = StringVar()
    labelText2.set("-----")
    label2 = Label(app, textvariable=labelText2)
    label2.grid(row=2, column=1, pady=5, padx=5)
    
    
    b3 = Button(app, text="Copy File", command=main, width=25)
    b3.grid(row=2, column=0, pady=5, padx=5)
    
    app.resizable(0,0)
    app.mainloop()
    
    

    There should be no bugs (No promises)

×