• Breaking News

    Sunday, March 7, 2021

    Does the accuracy of sleep() (Python) worsen with long periods? Ask Programming

    Does the accuracy of sleep() (Python) worsen with long periods? Ask Programming


    Does the accuracy of sleep() (Python) worsen with long periods?

    Posted: 07 Mar 2021 05:13 PM PST

    Hi. I have written a very simple Python script that runs on a Raspberry Pi reading a thermometer chip every minute and logging the reading to a file. Nothing more for now, I'll build more on top of it later.

    The "every minute" part, for now, is done by a simple sleep(60) in the loop. I wondered how accurate that would be, so I arranged for the time difference between every line and the starting point to be written to file. I noticed that it loses about one second every 1000, more than a minute per day.

    I know that sleep() is not super accurate because it depends on the scheduler, but there are only about 15 minutes in 1000 seconds, so every sleep() call seems to be late by more that 60 milliseconds. The script is a dozen lines long and it certainly doesn't take 50 ms per iteration... is this to be expected?

    To make this more stable (I would like it to run for weeks on end) I suppose I could use signal.alarm() and set a new alarm at every cycle?

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

    C++ vs Java (details inside)

    Posted: 07 Mar 2021 05:42 PM PST

    I have a project in mind and I'm not sure how to do it. Basically, it's a program that has a GUI with basically one text area, one text field and one button. You type something in the text field, click the button, the program does its calculations and show something on the text area. The actual logic isn't a problem for me, but I'm not sure if I should go for C++ or Java. I know this type of question usually boils down to personal preference but I will try to explain from my point of view. So, I actually started already creating the program in C++ and the GUI using win32. I know win32 is old and all that, but I actually didn't mind using it (I mean, I like OpenGL so win32 isn't that scary). But my main problem with win32 started when I tried to see how I could make so the elements of a window automatically adjust to a window resize. After seeing many "can't be done", I found a blog post that apparently had a solution (didn't try but it looked like what I needed). But that was when I started remembering about Java and the Swing library. It has been some time since I've actually done anything in Java but it should be easy enough. I actually really like creating GUIs with Swing, and the layouts solve any problem with window resizing. As a bonus, my program works in both Linux and Windows. The only downside is that, to be honest, Swing GUIs look like trash. So, my options are:

    • Continue with C++ (which is the language I like the most) and the questionable Windows API and try to solve the resize problem

    • Start using Java and enjoy the ugly but easy to use Swing

    • Use something like Qt or wxWidgets (I didn't consider at first because my GUI is kinda simple, so I thought a library like Qt would be overkill, but maybe not)

    • Learn C# from "scratch" (already knowing C-like syntax and OOP) and use the more modern alternatives for Windows

    I'm honestly kinda leaning to Java right now, but accept any input.

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

    OOP and Functional

    Posted: 07 Mar 2021 08:57 PM PST

    I am currently learning C# as my first language and while studying about object oriented programming I came across procedural and functional paradigms so I was wondering is it good to know all the families like at least a language in each family or to focus on OOP. My goal is to become a developer of security applications

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

    I want to code again

    Posted: 07 Mar 2021 08:26 PM PST

    I graduated on 2010 as a Computer System Engineer, I've been working since then in the IT department of a Bank, but I barely code since 5 years ago. I'd really like to code again but I don't know what would be interesting to code. What would you suggest?

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

    Is there no code or low code software/app/whatever available to create an interactive image similar to this...

    Posted: 07 Mar 2021 07:53 PM PST

    Hey all,

    I want to create an interactive image similar to the one in the link below.

    Ie. Information on hover, however when a section of the image is clicked I want to be directed to another interactive image where there is further information etc.

    This may be very simple or very hard, I really have no clue as this is my first time attempting to create something like this so any information at all is really appreciated.

    Here is the reference https://www.preethamrn.com/pokemondens/

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

    How to really know whether I'm right without test cases? Absolute c++ 6th programming projects

    Posted: 07 Mar 2021 06:59 PM PST

    https://smallpdf.com/shared#st=0b3c09f0-73f9-4ae2-9409-1d0ecbb74306&fn=Savitch%2C+Walter+J_Mock%2C+Kenrick+-+Absolute+C%2B%2B-Pearson+%282015_2016%29.pdf&ct=1615172367875&tl=share-document&rf=link

    chapter 1

    6

    A city cab service provider charges customers based on distance and time. The service charges $2 for the first two kilometers. After the first two kilometers, the service charges $0.50 per kilometer for the next six kilometers. After six kilometers, the customer is charged $1 per kilometer. At the end of the ride, a fee of $0.2 per minute is charged based on the total travel duration. Write a program that reads the distance traveled in kilometers and the time taken in minutes for a cab ride and computes the fare based on the service's charges.

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

    "new stored procedure" option not found in SSMS

    Posted: 07 Mar 2021 10:03 PM PST

    I am trying to use the current versions of SQL Server Management Studio. I'm following the https://msdn.microsoft.com/en-us/library/ms345415.aspx guideline. When I get to step 3 and right-click on "Stored Procedures" the popup menu I am presented with does not include the "New Stored Procedure" option. Instead, at the top of the list of options that are presented is the option "Stored procedure…"

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

    I need help finding Coordinates on my screen

    Posted: 07 Mar 2021 09:31 PM PST

    For my next python project I need to be able to reliability find the coordinates of different objects on my windows screen. I was wondering if there is a way to do this easily.

    submitted by /u/Bruh-ad
    [link] [comments]

    What is the name of the concept in programming when you change a variable, this automatically update the screen ? EX: <span>@MyVar</span>

    Posted: 07 Mar 2021 03:08 AM PST

    In the past, to update a text inside a <span> markup, used to be necessary something like

    document.getElementById("myspan").textContent="hello";

    With modern libraries and frameworks, we are capable to put variables inside the html and when you change the variable, this will automatically display a different data.

    Example:

    <span>@MyVar</span>

    //Initial Value
    MyVar = "Hello";

    ...buttonClick() : MyVar="Not Hello anymore";

    So, you will see on the screen the word Hello and a button. When you click on it, Hello will be replaced by Not Hello Anymore.

    What is the name of this concept where when you change the value of a variable tied to a html templace, this update the view automatically ? I though it was Reactive Programming, but after read about it...Looks like it's not the case.

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

    Why is my Axios data coming back as undefined/NaN when res.render is placed into my express server? The information is undefined despite showing up in the console logs(i've been console logging each step along the way) what is it about res.render that makes everything go wrong?

    Posted: 07 Mar 2021 10:57 AM PST

    trivias.get('/:topic/:num', isAuthenticated, (req, res) => {

    topicsObject = { "art": 25, "film": 11, "geography": 22, "math" : 19, "science_computers": 18, "music": 12 } let topicID = topicsObject[req.params.topic] console.log(`subject: ${req.params.topic} ID: ${topicID}`); // axios request let questions_array; axios.get(`https://opentdb.com/api.php?amount=15&category=${topicID}&difficulty=medium&type=multiple`).then((response) => { questions_array = response.data.results console.log("this is the information: ", questions_array ); // console.log(`questions array: ${questions_array}`); // next index of the next question within the array const index = parseInt(req.params.num) console.log(`index: ${index}`); const nextIndex = index + 1 console.log(`next index: ${nextIndex}`); // Question Object at a given index let questionObject = questions_array[index] console.log(`the questionObject: ${questionObject}`); // The Trivia Question string let questionString = questionObject["question"] console.log(`the question string: ${questionString}`); // grabs the incorrect answers from the question object let incorrectAnswersArray = questionObject["incorrect_answers"] console.log(`Incorrect answer array: ${incorrectAnswersArray}`); // grabs the correct answers from the question object let correctAnswer = questionObject["correct_answer"] console.log(`Correct answer: ${correctAnswer}`); // concatenates the incorrect and correct answers into an array let answersArray = incorrectAnswersArray.concat(correctAnswer) console.log(`All of the answers array: ${answersArray}`); // Shuffle answer array let shuffledAnswersArray = answersArray.sort(() => .5 - Math.random() ) console.log(`Shuffle Answers Array: ${shuffledAnswersArray}`); res.render('trivias/trivia.ejs', { currentUser: req.session.currentUser, topic: req.params.topic, question: questionString, answers: shuffledAnswersArray, nextIndex: nextIndex }) }).catch((error) => { console.log(error); }) 
    submitted by /u/ceawhale
    [link] [comments]

    What is a good working Instagram endpoint to retrieve the latest photos?

    Posted: 07 Mar 2021 05:10 PM PST

    Before I get answers, I want to say that I have tried using this endpoint to retrieve the account id:

    'https://www.instagram.com/web/search/topsearch/?context=blended&query=<insert account name here>'

    and then use this endpoint to retrieve my data with the id from the previous endpoint:

    `https://www.instagram.com/graphql/query?query\_id=17888483320059182&variables={"id":"${id}","first":${8},"after":null}\`

    this method was working but I now get this error: Access to XMLHttpRequest at 'https://www.instagram.com/web/search/topsearch/?context=blended&query=< account name >' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

    I have also tried: https://www.instagram.com/<insert account name here>/?__a=1
    but this method has also stopped working and before only took so many get requests.

    I just want to fetch the latest 8 images and display them to the public on my site, what is the best solution for this? I am React to build this.

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

    [C] trying to find GCD of two elements from different arrays

    Posted: 07 Mar 2021 10:56 AM PST

    Hello reddit, i'm quite new to c programming and yet i have a task which i cannot complete. I have to write a c program which will import data from txt file, put that data into array, split the array in half and then find gcd of between elements in those two arrays and save the results into another txt file. So far i managed to implement almost everything from that list, but still the gcd function spits weird results. Here's the code:

    #include <stdio.h>

    #include <stdlib.h>

    #define x 10000 # i have 10000 numbers in text file rng.txt

    #define y 5000 # after calculating gcd of two arrays i should have 5k results

    int gcd(int a, int b)

    {

    if (a == 0)

    return b;

    return gcd(b % a, a);

    }

    int main()

    {

    FILE *myfile, *myresults;

    myfile = fopen("rng.txt", "r");

    myresults = fopen("gcd_results_c.txt", "w");

    int numbers[x];

    int n1[y], n2[y];

    int i, c;

    for (i=0;i<x;i++)

    {

    fscanf(myfile, "%d,", &numbers[i]);

    }

    for (i=0;i<y;i++)

    {

    n1[i] = numbers[i];

    }

    for (i=y;i<x;i++)

    {

    n2[i] = numbers[i];

    }

    for (i=0;i<y;i++)

    {

    c = gcd(n1[i],n2[i]);

    printf("%d,", c);

    fprintf(myresults, "%d,", c);

    }

    fclose(myfile);

    fclose(myresults);

    return 0;

    }

    After i run this code gcd function gives just the numbers taken from array 'n2' and i have no idea why. Any ideas?

    Edit: Forgot to mention that the data set in rng.txt isn't totally random, I generated numbers from 1-10k and then shuffled them, so there aren't any 0 or negative numbers, also numbers don't repeat.

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

    Are Android Java skills transferrable?

    Posted: 07 Mar 2021 10:31 AM PST

    I'm trying to code Android apps in Java hoping this would also make me easier to land another Java related job. Otherwise maybe I should just do it with Kotlin which they say is less of a hassle than Java

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

    Password Displays on the Input's Value Attribute | No Big Deal or Cause for Concern?

    Posted: 07 Mar 2021 04:31 AM PST

    I was peeking under the hood at the DOM inspector for different websites for which I have saved my login credentials. I noticed that on the password input for most of the websites, the value attribute is set to an empty string. One website, however, showed the password input's value attribute as my actual password. For example:

    <input id="passwordId" name="password" type="password" value="">

    <input class="rl-input is-fullwidth" id="loginPassword" max="99999999" maxlength="256" min="10" minlength="2" name="password" placeholder="Password" type="password" value="MyActualPassword">

    I was concerned that this is a security issue with the website -- does this indicate that the webpage is storing passwords in plaintext, or is this a non-issue/related to how my browser is rendering the page on the client side-only?

    Thanks for any insight!

    EDIT: Their website uses React. Is there a best practice for a situation like this -- to auto fill the password field without setting the value prop?

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

    Hardware Windows vs iOS (Student)

    Posted: 07 Mar 2021 06:07 AM PST

    Hey guys, I'm contemplating quite a bit.

    I'm a computer science student, I need to purchase a laptop purely for educational purpose.

    Most of the programming is being done in a windows environment. We're mostly programming in C languages.

    I'm thinking about the new XPS 13 or the M1 MacBook Air both with 16GB ram and a minimum of 512 GB SSD.

    What's your take on it? Any other propositions?

    Thanks in advance for your help.

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

    Template/cheat sheet ideas?

    Posted: 07 Mar 2021 09:22 AM PST

    So I've been learning to code lately (html, css, javascript) kind of all at the same time. As an aide to learning, what would you guys think of a "cheat sheet" of sorts? So if I create an html page and want to add css to it, I need help targeting what I need to do. Do you guys do anything like this when learning a new language? I struggle with knowing what I need to do to accomplish what I'm trying for. I'm more comfortable with typing the code than I am making sense of what I need to do.

    Sorry of this makes no sense I'm struggling to explain.

    Think of it like not knowing computers and needing to tear it apart and put back together. A list of what you need to do, in order, makes me much more efficient. Anyone else do anything like this or have any ideas of how I could create something like this?

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

    SAT-style MCQ correction with Computer Vision

    Posted: 07 Mar 2021 08:32 AM PST

    I would like to create a program that can get the selected answers from SAT-style MCQ sheets (every answer or number is a filled circle). I was impressed by how the correction of the SAT can be automated (and probably already is), and I think it'd make a fun project.

    I'm not familiar at all with Computer Vision. Does this involve ML modules? In what language should I do this (Usually code in TS, I'm ok with Python)? Do you have any resources to recommend? Open source repos that do a similar job? Thank you.

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

    What is the best tactic for handling non-programmer interviewers?

    Posted: 07 Mar 2021 12:07 PM PST

    When another dev is interviewing me I just act myself and we relate well and he/she can see I know my stuff and am capable of doing the job. That's no problem.

    When the interviewer is a non-programmer. Holy crap! I get dismissed over nonsense like my previous client wanting ads on his website. I'm just thinking to myself "Seriously? You want to dismiss me over THAT?"

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

    [R] Front-end for ggplot within RStudio?

    Posted: 07 Mar 2021 07:26 AM PST

    I teach programming in R and a while back I found a package that, when run, would pop out a front-end for visualization using ggplot that made visualization much easier. I stupidly didn't save it and Googling hasn't helped. Any ideas? I'd be super grateful.

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

    I am having Septum Nose Piercing , Does it affect my job?

    Posted: 07 Mar 2021 05:16 AM PST

    I will hide or remove it while interview , I will only use when i am not on formal.

    I've found, We can hide that piercing

    submitted by /u/Psycho-logical-being
    [link] [comments]

    4-year old Python script Help

    Posted: 07 Mar 2021 02:48 AM PST

    Hi everyone,

    As the title hints, I am trying to get a 4 year old Python script working. Unfortunately, I virtually spend all my time with C# so I am unsure of what I am looking at, on top of being an amateur, self-taught programmer.

    I've tried to make some "brute force" hacks in which I just "added" what I think would make it work, but I am just getting more and more errors (progress!). Long story short, I am kinda at my wit's end, as this was just supposed to be a relatively quick venture into getting this to work.

    So here is the github : https://github.com/Leo675/twitch-botbuster

    EDIT : Important : The first issue I encountered was uh, line 21

    async def(func):

    `Invalid syntax`.

    I have downloaded Python (3.9 I believe) and have gotten it to "run" - as in encounter run-time errors. The latest of which was a :

    twitch-botbuster-master\botbuster.py", line 403, in <module>

    bot.watch_chatters()

    TypeError: 'coroutine' object is not callable

    Any time or help would be greatly appreciated, but it is understandably a tall order. I really don't know what I'm looking at, haha. But it is motivating me to learn Python, but that is greatly detracted by my lack of time and ongoing - well everything really.

    Thanks again, stay safe everyone.

    P.S. Er, for the record, that error I posted was after I added my C# "fixes", so incredibly likely you won't encounter the same issue.

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

    No comments:

    Post a Comment