• Breaking News

    Saturday, April 17, 2021

    How can this code work?? (React JS) Ask Programming

    How can this code work?? (React JS) Ask Programming


    How can this code work?? (React JS)

    Posted: 17 Apr 2021 04:16 PM PDT

    https://i.imgur.com/zeXu4wV.png

    Basically it's calling a function without giving it a parameter

    submitted by /u/Someone9339
    [link] [comments]

    Determining programming language syntax

    Posted: 17 Apr 2021 03:50 PM PDT

    Hi all! I've decided I want to write a programming language (nothing big and professional, just an experiment with something like LLVM to make compiler development as easy as possible). I'm currently working on determining the syntax of my ideal language, so I can afterwards start to implement it piece-by-piece. This is an example code snippet in my imaginary language, with some cooking instructions it implements as a comment: ```

    Instructions

    1. Heat a large skillet on medium-high heat, start cooking the pasta

    2. Finely slice or mince the garlic and finely chop the parsley

    3. Add the oil and garlic to the skillet and gently cook it until it's lightly golden brown

    4. Add the red pepper flakes to the skillet and turn down the heat to let its flavor infuse the oil

    5. When the pasta has finished cooking, drain it, and reserve at least around a cup of the cooking water

    6. Now add the drained pasta with some of the cooking water to the skillet and toss vigorously

    7. At the very last second add the parsley, to preserve its freshness

    Terminal(write) pasta(add) [tossed]pasta(toss) [drained]pasta [cooked]water [infused]skillet(add, heat-) [lightly golden]skillet(cook) [heated]skillet(heat->[medium-high]temperature), [raw]pasta(cook) garlic(slice) oil red pepper flakes parsley(slice) `` I want the language to be as in-redundant and "compiler magical" as I can possibly achieve in my free time. I'm still working out the details of the language syntax (this is just the first idea I came up with, and many definitions for e.g.addortoss` are missing), but in the meantime I'd be curious to hear some feedback from you guys. It helps reading from the inside out ^^

    submitted by /u/4669201609102990671
    [link] [comments]

    What is the difference between a repository and a server? What exactly is "artifactory"?

    Posted: 17 Apr 2021 06:53 PM PDT

    I'm learning more about servers and how they work (for hosting websites, for example). I am aware that GitHub and the git technology can have repositories, but I do not understand how this contrasts with a server. What is the difference between the two?

    Also, in many places I've worked at, I noticed that they make use of "Artifactory." What is this, exactly? Is that a repository? How does it work?

    Thank you

    submitted by /u/imstillmb
    [link] [comments]

    Language for an app with GUI and audio signal processing?

    Posted: 17 Apr 2021 04:53 AM PDT

    Hello!

    I'm interested in developing an app for my bachelor's degree and I had an idea of using some addressable led strips that are connected to a microcontroller, and using a selected audio channel from a PC to make the strips respond in real-time to the said audio signal using Fourier Transformations to get the frequency from sound amplitude, to be able to map intensity/colors on low/mid/high frequencies.

    This would be representation of what it would look like. It's similar to an Adobe After Effects plugin Trapcode Sound Keys

    I have an app in mind that would work on Windows, and maybe also different types of OS, since my professor uses macOS, and I'd also like to make some sort of GUI for it. What would be the best language to use in order to accomplish the development of this app? I had C++ or Java in mind, but searching the internet I got more confused than actually finding something.

    A bit of background, I have a pretty good experience in microcontrollers/processors and hardware related stuff from past projects, so I'd be more than happy if you'd have any other suggestions other than the best recommended programming language to use for the app.

    submitted by /u/DoodleImage
    [link] [comments]

    Doing hackerrank exam to get into coding school

    Posted: 17 Apr 2021 08:24 PM PDT

    Hi all

    Has anyone had to do a hackerrank exam to get into coding school? I checked around and people on reddit said hackerrank is only good for job preparation, the data structures and algorithms not programming as a whole.

    Has anyone done a test on hackerrank that just requires you to do normal programming exercises to assess candidates? In this 6 day selection bootcamp we are required to do basic python coding exercises in the first 3 days, next 2 days is a group project and in the 6th day we do an exam on hackerrank.

    submitted by /u/mraees93
    [link] [comments]

    How to get website to run correctly on Hostinger

    Posted: 17 Apr 2021 07:11 PM PDT

    Hi, I am very new to web development so please bear with me, I do however know a fair amount of python and html so I'm not utterly hopeless in general programming.

    Context: I followed this tutorial by Traversy media:(https://youtu.be/jD7FnbI76Hg), and got to the final
    fully functioning product that works with localhost.

    Issue: I bought a domain name:(http://azdev.club/) and a subscription to Hostinger:(https://www.hostinger.com/), uploaded the files and it all works apart from the chatroom.

    My theory of what is happening: the site failed in exactly the same way when I just ran the index.html file without using localhost, but when using vscode to execute the commands:(npm install, npm run dev) and used:(http://localhost:3000/) to access the site, it worked perfectly.

    So the way I see it, Hostinger is not running the public equivalent of localhost:3000, but that's just my take.

    If you need to see any source code or screenshots, just ask.

    Thank you.

    submitted by /u/SoddenFilly
    [link] [comments]

    Loop back to the beginning

    Posted: 17 Apr 2021 05:58 AM PDT

    How can I loop back to the beginning, when my player hit one of the white squares? I have tried to loop, but I don't know where I can set the while loop, to restart the game from Scratch. Loop back, and start to move from the beginning. In other words, restart the game.

    import turtle import math

    wn = turtle.Screen() wn.bgcolor("blue") wn.tracer(3)

    player = turtle.Turtle() player.color("red") player.shape("circle") player.penup() player.speed(0) player.setposition(-225, 50)

    square = turtle.Turtle() square.color("white") square.shape("square") square.penup() square.speed(0) square.setposition(-200, 100)

    square_2 = turtle.Turtle() square_2.color("white") square_2.shape("square") square_2.penup() square_2.speed(0) square_2.setposition(-250, 50)

    speed = 0.4

    def turnleft(): player.left(90)

    def turnright(): player.right(90)

    turtle.listen() turtle.onkey(turnleft, "Left") turtle.onkey(turnright, "Right")

    while True: player.forward(speed)

    d = math.sqrt(math.pow(player.xcor()-square.xcor(),2) + math.pow(player.ycor()-square.ycor(),2)) if d < 20: square.q() d = math.sqrt(math.pow(player.xcor()-square_2.xcor(),2) + math.pow(player.ycor()-square_2.ycor(),2)) if d < 20: square_2.q() 
    submitted by /u/OkWriting3326
    [link] [comments]

    How can I convert a java int[][][] as a jni jobjectarray to a c++ int[][][] (and back)

    Posted: 17 Apr 2021 12:46 PM PDT

    I'm working on a Java project that falls back on native c++ code. I will give a Java 3D integer array as a jni jobjectarray to the native code. Before I can process this array, I must convert it to a c++ 3D integer array. Vectors aren't an option because the array will be parsed to a CUDA file, and CUDA doesn't support vectors or anything else with a dynamic size. I saw how I can convert a 1D array, but I don't know how to do this with multidim. arrays.

    Every help will be appreciated

    submitted by /u/Jirne_VR
    [link] [comments]

    How do I check if user exists in db given an email and a number and then create it or update it?

    Posted: 17 Apr 2021 04:04 PM PDT

    I wrote this code that does not work since it has some syntax errors among other things but I think the functionality I'm looking for can be seen in it. I basically need to check if given an email or a phone, the user exists and, if it does, return it.

    Then, if the user inputs both their email and phone, I need to get the user if it exists, update it if one of the fields is different, create it if it doesn't exist and, if there're two users (one with the same phone, another one with the same email) return none.

    How can I improve this so that it actually works?

    ``` def create(self, validated_data): filters = {} if email = validated_data.get('email') or telefono = validated_data.get('telefono'): filters["email"] = email filters["telefono"] = telefono

     try: go = Cliente.objects.get(foo='bar') except Cliente.DoesNotExist: go = None elif email := validated_data.get('email') and telefono := validated_data.get('telefono'): filters["email"] = email filters["telefono"] = telefono try: go = Cliente.objects.get(foo='bar') except Cliente.DoesNotExist: cliente, _ = Cliente.objects.update_or_create(**filters) return user except Cliente.MultipleObjectsReturned: go = None 

    ```

    This is the models: ``` class Food(models.Model): nombre = models.CharField(max_length=100, unique=True) cant = models.IntegerField(default=0)

    def __str__(self): return self.nombre 

    class Order(models.Model): fecha = models.DateField(auto_now_add=True) email = models.EmailField(max_length=200, null=True) telefono = models.IntegerField(null=True) food= models.ManyToManyField('Food', related_name='order', blank=True) cantidad = models.IntegerField(default=0)

    def __str__(self): return self.food 

    class User(models.Model): email = models.EmailField(max_length=200, unique=True, blank=False) telefono = models.IntegerField(unique=True, blank=False)

    def __str__(self): return self.email 

    ```

    This is the serializers: ``` class UserSerializer(serializers.ModelSerializer):

    class Meta: model = User fields = '__all__' extra_kwargs = { 'email': {'required': True}, 'telefono': {'required': True} } def create(self, validated_data): user = User.objects.create( email=validated_data['email'], telefono=validated_data['telefono'] ) user.save() return user 

    class FoodSerializer1(serializers.ModelSerializer):

    class Meta: model = Food fields = ('nombre',) nombre = serializers.CharField(validators=[ UniqueValidator( queryset=models.Food.objects.all(),lookup='iexact' )]) 

    class FoodSerializer(serializers.ModelSerializer):

    class Meta: model = Food fields = ('nombre', 'cant') nombre = serializers.CharField(validators=[ UniqueValidator( queryset=models.Food.objects.all(),lookup='iexact' )]) 

    class OrderSerializer(serializers.ModelSerializer):

    class Meta: model = Order fields = ('fecha','food','telefono','email') def validate(self, data): email = data.get('email') telefono = data.get('telefono') if not email and not telefono: raise serializers.ValidationError("Se requiere email o telefono") return data def create(self, validated_data): filters = {} if email = validated_data.get('email') or telefono = validated_data.get('telefono'): filters["email"] = email filters["telefono"] = telefono try: go = User.objects.get(foo='bar') except User.DoesNotExist: go = None elif email := validated_data.get('email') and telefono := validated_data.get('telefono'): filters["email"] = email filters["telefono"] = telefono try: go = User.objects.get(foo='bar') except User.DoesNotExist: user, _ = User.objects.update_or_create(**filters) return user except User.MultipleObjectsReturned: go = None 

    ```

    submitted by /u/uppsalas
    [link] [comments]

    How to optimize OpenMP parallel program?

    Posted: 17 Apr 2021 03:48 PM PDT

    I'm working on parallelizing the n-queens problem using OpenMP but my sequential program is just as fast.

    Can someone look at my code and tell me what I am doing wrong or give me some pointers? Thank you.

    Below is my parallel program.

    // Parallel version of the N-Queens problem. #include <iostream> #include <omp.h> #include <time.h> #include <sys/time.h> // Timing execution double startTime, endTime; // Number of solutions found int numofSol = 0; // Board size and number of queens #define N 11 void placeQ(int queens[], int row, int column) { for(int i = 0; i < row; i++) { // Vertical if (queens[i] == column) { return; } // Two queens in the same diagonal if (abs(queens[i] - column) == (row- i)) { return; } } // Set the queen queens[row] = column; if(row == N-1) { #pragma omp atomic numofSol++; //Placed the final queen, found a solution #pragma omp critical { std::cout << "The number of solutions found is: " << numofSol << std::endl; for (int row = 0; row < N; row++) { for (int column = 0; column < N; column++) { if (queens[row] == column) { std::cout << "X"; } else { std::cout << "|"; } } std::cout << "\n" << std::endl; } } } else { // Increment row for(int i = 0; i < N; i++) { placeQ(queens, row + 1, i); } } } // End of placeQ() void solve() { #pragma omp parallel num_threads(30) #pragma omp single { for(int i = 0; i < N; i++) { // New task added for first row and each column recursion. #pragma omp task { placeQ(new int[N], 0, i); } } } } // end of solve() int main(int argc, char*argv[]) { startTime = omp_get_wtime(); solve(); endTime = omp_get_wtime(); // Print board size, number of solutions, and execution time. std::cout << "Board Size: " << N << std::endl; std::cout << "Number of solutions: " << numofSol << std::endl; std::cout << "Execution time: " << endTime - startTime << " seconds." << std::endl; return 0; } 
    submitted by /u/cryingwhiledoingmath
    [link] [comments]

    Sorting patient objects by BMI - Is it logical to use Linked Lists/Trees/Graphs? PYTHON

    Posted: 17 Apr 2021 03:10 PM PDT

    Hey guys. I wanted to ask this question to people who are professionally experienced to see if it was logical from a professional perspective to be using Linked lists/trees/graphs to achieve the goal of sorting patients (as objects) by their BMI. I feel like this could be easily and much more simply achieved with lists rather than sticking one after the other in a linked list and then trying to sort them. Also in this situation, I am not allowed to use any libraries or built in modules (except csv to extract the data), and I'm not allowed to use any build in data structures other than lists. So would this make sense from a professionals point of view?

    Thanks!

    submitted by /u/JJosuke434
    [link] [comments]

    How would you price this Program? (Details inside)

    Posted: 17 Apr 2021 02:27 PM PDT

    Hello there

    I have written a program that can assist me with my current job. It is a GUI that can calculate the price of a number of subscriptions, options and discounts. It displays an itemized list in a format that can be sent to a customer during written interactions such as live chat, messaging or e-mail replies.

    We already have a web-based tool that does something similar, but there is currently no program that can output a list so we have to write those out manually over and over. I believe my program is superior to the current solution because it accepts custom discounts as well as discounts in percentages and can keep track of a lot more subscriptions/options. It also allows one to make selections much faster.

    There are several hundred employees who may be able to benefit from using this program. Allowing them to work faster and make more sales.

    I am considering making this program available to my company and am wondering how to price it. It took me about two weeks to write, but would probably only have taken me three days if I had known how to do everything beforehand. I am considering asking for about three business days worth of compensation if I make the program available to everyone. My boss is authorized to grant such requests.

    What are your thoughts on this?

    Some factors I am considering:

    If my company does consider purchasing the program, it will probably have to be analyzed by out IT-Department. The program is written in Autohotkey and I doubt that anyone there has any experience with this programming language so it may be dismissed out of hand. This may make the programe unavailable to me as well. The program is, in my opinion, no security risk as it does not create, access or edit any files, does not connect to any web-pages or networks and does not interact with any other software at all.

    If they do adopt the program, they will have to allocate some of my time to keep the program up to date.

    submitted by /u/bluegreyaw
    [link] [comments]

    While learning android development I had a question (see description)

    Posted: 17 Apr 2021 06:44 AM PDT

    I just started learning android studio from a site and had a question.

    "The code"

    *public class MainActivity extends Activity { .... protected void onStart(){ super.onStart(); } } *

    So what does super.onStart(); refers to? Does it refers to the onStart(); method in Activity class?

    submitted by /u/omkar555o
    [link] [comments]

    How do I approach the following (optimization)

    Posted: 17 Apr 2021 12:33 PM PDT

    Hello, I have the following numbers to match: {13: 262, 14: 215, 15: 102} The goal is to get these numbers exactly or more like 15:105 but it is not allowed to have a number less than this.

    I have the following dictionary which contains the summands with extra information:

    The summand , the Id of the summand, the impact on other things (this should be minimized) and the numbers it impacts.

    Examples: (extracts of the dictionaries)

    13: {(2,576),0, [13, 14, 15]), ((4, 119), 0, [13]), ((3, 121), 0, [13]), ((3, 153), 0, [13]), ((1, 219), 0, [13]), ((3, 328), 0, [13]), ((1, 444), 0, [13]), ((4, 551), 0, [13]), ((5, 568), 0, [13]), ((3, 2), 6, [13, 14, 15, 16, 17]), ((2, 7), 4, [13, 14, 15, 16, 17])

    14: {((6, 560), 0, [13, 14, 15]), ((2, 576), 0, [13, 14, 15]), ((2, 117), 0, [14]), ((3, 188), 0, [14]), ((8, 377), 0, [14]), ((3, 2), 6, [13, 14, 15, 16, 17]), ((2, 7), 4, [13, 14, 15, 16, 17])}

    15: {((6, 560), 0, [13, 14, 15]), ((2, 576), 0, [13, 14, 15]), ((1, 207), 0, [15]), ((6, 291), 0, [15]), ((3, 2), 6, [13, 14, 15, 16, 17]), ((2, 7), 4, [13, 14, 15, 16, 17]), ((2, 11), 4, [13, 14, 15, 16, 17])}

    So what is my plan:

    So some Id's of the wishes are matching obviously because if they impact 13, 14, 15 they are on every dictionary. I want to find the summands, who summed up have the lowest cost, which is the impact * number it impacts minus the numbers who should be matched. I've thought about backtracking or bipartite matching, but I'm pretty clueless. (I'm using python)

    submitted by /u/Anonymushacker8
    [link] [comments]

    Acceptable to use tutorials for a project?

    Posted: 17 Apr 2021 03:14 AM PDT

    Final project needs finishing and I am not as good at programming yet. Due to that, I am having to rely on tutorials about features I want to implement. I am not copying it word by word, just seeing how it's done and trying to do it my way as much as possible but the logic remains the same. I mean, there are only so many ways you can add 1 to 1.

    Anywho, I wanted to know if this can get me in trouble? How do I reference those tutorials in the project?

    submitted by /u/redditorbyaccident
    [link] [comments]

    Do you maintain different Table for your web app and Mobile app (Android+ ios ) Payment

    Posted: 17 Apr 2021 08:54 AM PDT

    We're building a mobile app using react native for android and ios and would like to be able to collect payment for a real-world service. Since it's a mobile app, we had assumed we would be restricted if you don't use google or apple pay for in-app payments right?

    We want to use stripe for the web app, for the mobile app want to use google and apple payment.

    Is there have any better way to make it simple.

    submitted by /u/TheGopherBro
    [link] [comments]

    Need help making an .exe file from my javafx .jar file

    Posted: 17 Apr 2021 04:41 AM PDT

    I'm sorry for the noob question, but I really don't know what to do. I've been developing a javafx GUI-application for my programming course and I want to turn it into an .exe file so other people could use it. I've been searching the internet for answers but haven't had that much luck.

    When I tried to make an .msi file with jpackage and install it, it did make an .exe file. But when I try to click said .exe file, a black screen appears and immediately disappears.

    I don't know if it is related, but if I try to run my .jar file from the command line with the following command: java -jar MyJarName.jar, it gives me the following error: Error: Could not find or load main class src.MainClassName Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

    But it works if I add the following to the command: java --module-path c:\devel\javafx\lib --add-modules javafx.controls,javafx.fxml -jar MyJarName.jar

    Here's the command I tried with jpackage: jpackage --module-path c:\devel\javafx\lib --add-modules javafx.controls,javafx.fxml --input . --main-jar MyJarName.jar --main-class src.MainClassName --type exe --win-console --win-dir-chooser --win-shortcut --icon MyIcon.ico

    What am I doing wrong? Any help would be appreciated. Also sorry for my English, I'm not a native speaker.

    submitted by /u/PythonIsSnake
    [link] [comments]

    Should I learn a low - mid level programming language?

    Posted: 17 Apr 2021 08:20 AM PDT

    I am currently working in a small (startup) company on PHP, Laravel and MySQL. I am 8 months into it. And moreover, I started as a non-coder. I was studying Electrical Engineering, because I could get the option for dual degree (EE and IT).

    The thing is I am going crazy to learn new stuff. It's not that I cant eat or sleep, but I get hyper excited. But, I have a different level of learning. Meaning, unless I am completely filled with the fundamentals or a maximum portion of it, I cannot accept that I have learnt something. Since that is not always possible, most of the time, I let go of a few stuff, and sometimes I just get a complete idea of something automatically, out of the blue. I dont know how it happens but it does.

    But, the thing is, I get demotivated when someone in Stackoverflow or Reddit or even Quora answers some of my questions in a detailed (fundamental) manner, but I didnt think of it in that way. It is not at all jealousy. But that s/he has a better understanding of things, that I am not, and so it may impact how I work in the future, and may not be able to do things in a different way, or I may not be able to do it at all.

    I recently started learning Python, as I was interested in it. But again, Python is very much easy, compared to old languages, and I am not aware of the fundamentals of Python- like how it was built (using another programming language). I have plans to learn Djange, then AWS , then some Artificial Intellegence.

    But, before I do that, should I learn a low to mid level language like C++ or C#. I am more interested in C#, but I need some guidance if at all I should go for it.

    submitted by /u/AsishPC
    [link] [comments]

    Vscode Intellisense for external js files

    Posted: 17 Apr 2021 03:11 AM PDT

    As the title. In the screenshot i have the directory where all the files are, the code inside the html page which references the script and calls it. The html code works fine but i want the vscode intellisense to suggest "sayboo2()" knowing that the First.js is a source of intellisense suggestions. Spent a bit of time on this and cant figure it out. I tried to add a path to it in the jsconfig.json but that didnt seem to be what vscode needed.

    The jsconfig.json looks like this inside

    { 

    "compilerOptions": { "module": "commonjs", "target": "es6" }, "include": ["First.js"] // Used to be ["*"] }

    //I also tried omitting the include directive but that didn't work either 

    One of you guys will see this and be like "oh you idiot, you just do X, so easy". Please put me out of my misery with "yes it can be done like this", or "nope not possible at present".

    I'm getting burned bad because i was developing on windows 10 with visual studio and it just worked, but now i'm on ubuntu with VScode and i cant figure it out at all.

    Thanks in advance

    Screenshot - This shows the files and folder structure of the project at present

    submitted by /u/starcrafter84
    [link] [comments]

    Shape Recognition Project

    Posted: 17 Apr 2021 05:56 AM PDT

    Newbie here — I'm interested in (eventually) creating an app that gathers data from .pdf files using shape recognition. Does anyone have any suggestions in terms of languages that I might find most useful, relevant APIs or resources with more info about how I could approach this?

    submitted by /u/renderten
    [link] [comments]

    Log data onto map

    Posted: 17 Apr 2021 05:09 AM PDT

    Hello everyone I'm currently developing a app using android studio and java. I'm just wondering how instead of logging something I would like to display it on a map like a location.

    submitted by /u/ConM44
    [link] [comments]

    lisp interpreter vs template language vs compiler

    Posted: 17 Apr 2021 01:06 AM PDT

    I'm hoping this hasn't been asked before since I couldn't find anything but I was curious what the differences between a compiler, lisp interpreter and template language are? I know of liquid as an example of a template language, but could you make a compiler that does the same thing? I would appreciate if anyone could help me understand the differences similarities!

    submitted by /u/pb7d77
    [link] [comments]

    Why it took me close to 5 hours to complete this simple Tic Tac Toe game in C?

    Posted: 17 Apr 2021 04:05 AM PDT

    I think it took me too long to finish this simple Tic Tac Toe game in C (close to 5 hours). Apart from making the initial planning (flow chart), most of the time was spent on debugging. At first my functions were doing more than one specific thing (a lesson learned there), so I changed several things, taking out from the functions and including those pieces of code into the main() directly.

    Is there something that I can do to speed up the process of building a program like this and make things more legible when debugging?

    This is my flow chart.

    This is my code.

    This is a demo of the program running:

     _____ _ _____ _____ |_ _(_) ___ |_ _|_ _ ___ |_ _|__ ___ | | | |/ __| | |/ _` |/ __| | |/ _ \ / _ \ | | | | (__ | | (_| | (__ | | (_) | __/ |_| |_|\___| |_|\__,_|\___| |_|\___/ \___| Player 1 is playing (X), Player 2 is playing (O) | | 1 | 2 | 3 _____|_____|_____ | | 4 | 5 | 6 _____|_____|_____ | | 7 | 8 | 9 | | Player 1 - select a position: 

    Thanks.

    submitted by /u/Darthcolo
    [link] [comments]

    No comments:

    Post a Comment