• Breaking News

    Thursday, August 29, 2019

    Should an if-else go in the main or method? Ask Programming

    Should an if-else go in the main or method? Ask Programming


    Should an if-else go in the main or method?

    Posted: 29 Aug 2019 05:58 PM PDT

    Basically should it be this:

    if (football) { kick() } else { throw() } function kick() { ball = 'kicked' } function throw() { ball = 'thrown' } 

    or this:

    kick() throw() function kick() { if (football) { ball = 'kicked' } } function throw() { if (!football) { ball = 'thrown' } } 

    I imagine it would be a bit circumstantial but I feel like I need some consistency in this regard.

    Note: this code is generic. I'm not looking for a solution for this exact code.

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

    Met up with an old buddy, he's working on "self correcting software" (his words). I know nothing of this specialization. Is there any relevant software or hardware that I can get him as a gift? He likely does not want books/courses.

    Posted: 29 Aug 2019 02:08 PM PDT

    How do you do things like reserve objects if you're using a nosql db like Cassandra? If 3 Uber drivers click accept on a single ride at once, how do you handle the race condition?

    Posted: 29 Aug 2019 04:12 PM PDT

    I can think of a few solutions, but I'm not happy about any of them. You could have a single app server that is the only one used for a given ride, but that complicates load balancing and you have to handle what happens if the server goes down. I'd rather somehow just handle it entirely in the db.

    One idea is to insert a record reserving the ride for each driver. Then you wait some period of time and query for all records applying to this ride. Then, the record with the earliest creation date or lowest uuid would win and the others would report failure to reserve the object.

    But is that guaranteed to work? How can you pick a time period that's sure to work?

    If this is a terrible idea, what is a correct approach?

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

    App design: how to best trigger a GUI window

    Posted: 29 Aug 2019 07:36 PM PDT

    I want to write a reminder app that launches at startup automatically. Now the users should be able to launch an application window and add reminders in the app. What can I do to listen for users trying to launch the app by themselves considering the app is already running on the background?

    Platform is POSIX/Freedesktop and toolkit is GTK if that's relevant.

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

    How to calculate a string expression with only 1 operand?

    Posted: 29 Aug 2019 11:03 PM PDT

    OPERATOR***

    For example the user enters string "451+234","2*3".

    There can be only 1 operator in the expression. When I searched for help elsewhere I saw using sstream can be helpful but I've never used it before.

    I feel like the question is simple but the answer is very complex for a beginner programmer.

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

    Super super basic JavaScript. Although I'm stupid enough to not understand it.

    Posted: 29 Aug 2019 06:02 PM PDT

    <!DOCTYPE html>
    <html>
    <body>
    <h2>What Can JavaScript Do?</h2>
    <p id="demo'>JavaScript can change HTML content.">
    <button type="button" onclick=' document.getElementById("demo").innerHTML = "Hello JavaScript!"'>Click Me!</button>
    </body>
    </html>

    It is supposed to say What can Javascript do? and then underneath it would have a button. The button would say "Javascript can change HTML content." When you click the button, it would say, "Hello JavaScript"

    I have no idea why it isn't working, honestly I'm trying to learn but its extremely difficult. Hopefully someone can help me out here. Thanks :)

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

    My team is building a boring, pedestrian business web application. What resources do you have for improving ease of interaction, good looking but still functional design layout, and anything else that makes a site easier to use for employees but also looking more modern?

    Posted: 29 Aug 2019 09:32 PM PDT

    My company is giving us a hack day to build whatever we want, but what we produce has to have some sort of benefit to the company. What are some ideas that my team can produce?

    Posted: 29 Aug 2019 08:05 AM PDT

    Hey front end developers!! What are some design practices you use very often?

    Posted: 28 Aug 2019 11:29 PM PDT

    Header function declarations local to file

    Posted: 29 Aug 2019 07:17 AM PDT

    In C++ (14) I have a header file that defines some *templated* functions. Since they are templated, they must be in the header, not a .cpp. However, these templated functions are not meant to be externally visible - they are only used by the functions in the header that are intended to be visible externally (i.e., from other source files that include the header).

    Is there a way to declare that some of these functions defined in the header should be "as if they were in the .cpp file", i.e., not visible to other files that include the header?

    Note: My header is not a class or struct - it just contains function prototypes. I'm also not using a namespace right now. I know I can fix it using namespaces, but I'm curious if I'm missing some keyword like "local".

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

    Express.js - Cross-Origin Request Blocked

    Posted: 29 Aug 2019 01:17 PM PDT

    I have a Node.js server running on localhost port 3000. I also have a Vue.js application running on port 8080. I've implemented passportjs (Google strategy) on my login form that is written in Vue.js.

    However, when I click on the Google+ button, I have a CORS blocked error which tells me that I have a missing CORS even though I have enabled cors in my server code.

    I've tried changing parameters to cors():

    app.use(cors({origin: 'http://localhost:3000', credentials: true}));

    I've also tried adding Header set Access-Control-Allow-Origin '*' to my apache2.conf file.

    I also get a HTTP 302 code every time I hit the button.

    Node.js file: ``` const express = require('express'); const bodyParser = require('body-parser'); const cors = require('cors'); const passport = require('passport');

    const app = express();

    app.use(cors());

    // Routes app.use('/user', users);

    // Passport strategy passport.use(new GoogleStrategy({ clientID: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, callbackURL: '/user/google/redirect' }, function(accessToken, refreshToken, profile, done) { User.findOrCreate({ googleId: profile.id }, function (err, user) { return done(err, user); }); }));

    // Server start app.listen(3000, (req, res) => { console.log(Listening to port 3000...\n); }); ```

    Router: ``` // auth with google+ router.get('/google', passport.authenticate('google', { scope: ['https://www.googleapis.com/auth/plus.login'] } ));

    // callback route for google to redirect to router.get('/google/redirect', passport.authenticate('google', { failureRedirect: '/login' }), function(req, res) { res.send('Done!'); }); ```

    Vue.js file:

    ``` <template> <v-card class="elevation-12" v-on:submit.prevent="login"> <mdb-btn align-center justify-center class="btn-gplus" icon="google-plus-g" fab v-on:click="authGoogle()">Google +</mdb-btn> </v-card> </template>

    <script> import axios from 'axios'; import router from '../router/router'; import { mdbBtn } from 'mdbvue';

    const { URL } = require('../config');

    export default { name: 'Login', methods: { authGoogle () { axios.get(${URL}/user/google, { }).then(res => { console.log(res); }).catch(err => { console.log(err); }) } }, components: { mdbBtn } }; </script> ```

    When I enter http://localhost:3000/user/google/ in my browser, the Google login page opens successfully but I cannot accomplish this in my code.

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

    Help me get started on working on a project!

    Posted: 29 Aug 2019 10:52 AM PDT

    So now that I have a couple years of coding experience, and pretty comfortable with C and Python, I want to start a project but there's so many things running through my mind on how to start one that I need advice.

    1) Would it be easier to make a website or an app? And in both scenarios, do employers find it even impressive at all if you say you just coded a personal website or app without making it public?

    2) If I choose to make an android app, what do I need to do? What language do I need to know? What programs do I need to download? Can I just code in VSCode like I've been using to practice python?

    3) Same questions as #2 but for websites.

    4) Any other tips appreciated. Anything I'm skipping over before starting a project? Do I need to post my stuff on Github? (Or git...??? Idk the difference).

    Thanks!!

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

    Need Some Advice on Structuring AI

    Posted: 29 Aug 2019 12:42 PM PDT

    I'm working on an AI that uses a State Machine to switch between states (Attack, Defend, Move, etc)

    there is also multiple types of different AI that all share the same state machine, and I want them to act differently.

    So my question is how can I make the states unique without adding the same code to all the AI in the game?

    Any help with this is truly appreciated, because I'm stumped :/

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

    Computer Science Prof. says we have to use netbeans, can he tell if I use Eclipse?

    Posted: 29 Aug 2019 10:41 AM PDT

    I was wondering if its possible to use eclipse without him knowing when i turn in my assignments, or is there something in the file that somehow shows what I've used?

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

    How to create an HTML form that allows MS word type of formatting?

    Posted: 29 Aug 2019 10:31 AM PDT

    I am making a form for an app I am creating. So far it is just a simple text box that allows the user to type stuff and submit.

    But, I want the user to be able to format their text with bullet points, bolding, and pretty much like most of the options they'd have when typing in MS word in Google docs. Any ideas on how I can go about this? Is there a bootstrap library for this or any JS libraries?

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

    How do I prevent create-react-app's `npm start` from deleting the `paths` property from tsconfig.json?

    Posted: 29 Aug 2019 12:52 PM PDT

    Every time I add paths to my tsconfig.json file and restart npm start, it deletes the paths configuration. Is there a way to prevent this from happening?

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

    What's a good intermediate level C++ book?

    Posted: 29 Aug 2019 12:35 PM PDT

    Any recommendations?

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

    How to structure code that contains slightly different logic for different customers?

    Posted: 29 Aug 2019 12:26 PM PDT

    My current approach is to encapsulate different logic into different methods(or classes) and use feature flags to enable/disable them for different customers.

    It gets messy when you get more customers and more customizaions are needed. A bunch of if and switch statements everywhere.

    What's the best practice to handle it? Thanks! ( I mostly write Python and Java code)

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

    I don't know if this is the right place

    Posted: 29 Aug 2019 12:10 PM PDT

    Sorry if this isn't the right place, but i'm starting a new project for my uni, I need to accomplish a few things and I'm trying to figure out what the best languages would be for this.

    1. The application needs to be a stand alone application with stability that is cross platform e.g. Windows, linux osx, ios and android
    2. The application needs to be scalable and able to working with docker containers
    3. The application will need to be able to simulate internet searches with rest calls.
    4. it Cannot be a web app it need to run stand alone but obviously will have network access
    5. It need to be secure and not processing heavy at least the mobile apps anyway(if the majority of the processing is done by a server thats fine)

    Thanks for any advise in advances

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

    Help creating “simple” executable

    Posted: 29 Aug 2019 09:21 AM PDT

    Hey AskProgramming, how should I go about creating a simple executable (thinking notepad) to search within a limited criteria (akin to "K:\Programs\DesiredSearchableFolders") and create a shortcut to the relevant files. If for example folder "Test1" contains a text file "project1timeline.txt", and folder "Test2" contains text file "project2timeline.txt", I want to create a shortcut link for each individual "timeline" file, such that in my folder "timelines" I would have a shortcut to each seperate text file.

    Google searches of available commands for notepad havent yielded commands capable of creating shortcut files... can you guys help me with this?

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

    C# - windows cannot find command

    Posted: 29 Aug 2019 09:13 AM PDT

    I'm using system.diagnostics.process.start to call cmd and run and LPR command (LPR port monitor is enabled on my machine) but my app throws up a command window with an error saying:

    Windows cannot find 'lpr'. Make sure you typed the name correctly, and then try again 

    The call i'm using for this in my app is:

    System.Diagnostics.Process.Start("cmd.exe", $"/C START/MIN lpr -S {ip_addr} -P PASSTHRU -o l {file_name}"); 

    Can anyone tell me what i'm doing wrong?

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

    Looking for a stock market API

    Posted: 29 Aug 2019 08:50 AM PDT

    Hi!

    My brother is a statistician that doesn't know how to program, and I am a hobbyist programmer who knows nothing about the stock market. He asked me if I could help him automate plotting stock market data and so I'm trying to oblige him. I first tried with Alpha Vantage, which has a python library, seems easy enough and they claim "Global coverage" which I assumed meant you can request data about any stock globally, but that doesn't seem to be the case since I get errors when requesting stocks on the nordic market. I mailed the support about this but they haven't responded. So I've been searching other APIs that allows this but reading up on them only confuses me when I can't understand any finance lingo they use.

    So now I'm turning over to you guys, wondering if anyone of you can recommend an API able to work on these criteria:

    • Able to pull stock closing value data daily
    • Pull historical data
    • Able to pull data about stocks in these lists:
    1. https://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ
    2. http://www.nasdaqomxnordic.com/aktier/listed-companies/nordic-large-cap
    3. http://www.nasdaqomxnordic.com/aktier/listed-companies/nordic-mid-cap
    • Support for Python

    Bonus if there's support for:

    • If you can pull data for multiple stocks in a single request.

    No requirement on price, but naturally the cheaper, the better.

    Any advice would be much appreciated.

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

    Looking for feedback on how developer resources could be improved!

    Posted: 29 Aug 2019 07:56 AM PDT

    Pre-increment and Post-increment in C

    Posted: 29 Aug 2019 05:13 AM PDT

    Hello reddit, today i come begging for some explanation about Pre-increment and Post-increment in c.

    I have the following program in c, in which i increment\decrement x and save the value to n (or the other way around i'm not really sure), what i initially thought is that we're going to post increment x (x is 9 now), and then decrement (x is 8), and then increment again (x is 9), finally decrement (x is 8), but it seems like am getting the following output, 9 - 8

    int main() { int x = 8, n;

    n = (x++, --x, ++x, x--);

    printf("%d - %d \n", n, x); return 0; }

    Can somebody please explain what exactly am i doing wrong.

    Thank you :)

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

    No comments:

    Post a Comment