• Breaking News

    Saturday, January 9, 2021

    [Python] Initialize multiple variables in a loop (turtle) Ask Programming

    [Python] Initialize multiple variables in a loop (turtle) Ask Programming


    [Python] Initialize multiple variables in a loop (turtle)

    Posted: 09 Jan 2021 07:11 PM PST

    I am trying to write a simple program that traces secant lines in circles. Suppose I were to ask the user for an input of how many secant lines. Then I can easily write a function that initializes a turtle and goes through a loop to draw these. What I want to do is then have orbs that move up and down each of these secants (which as a whole makes wonderful patterns). How do i do this? Create a bunch of turtles and have them move forward and backward? How can I initialize a certain amount of them that corresponds to each secant? Thanks.

    submitted by /u/read-ded-redemshin
    [link] [comments]

    Help with creating a UML class design for a business logic layer of a program that works with 'no permanent storage'

    Posted: 09 Jan 2021 12:15 PM PST

    Hello,

    Recently we've received an assignment to simply design a UML class diagram for the business logic layer of the program that should work in c# and php.

    Unfortunately, there is one caveat that has not come up previously, and the professors insist that this is something we should know and refuse to provide further clarification...

    Namely, the business logic layer should allow users to register and log in, should differentiate between different types of users and should allow for storage and retrieval of item data. This should, allegedly, NOT rely on the data management or presentation layers and the given logic design should work without permanent storage (i.e, user data can not be read and stored in a database table...).

    I am confused by this. Without permanent storage, would the user and item data simply be stored in lists with type object in some type of general 'administration/management' class?

    I seldom seek outside help for assignments as I prefer it to be my own work and progress, but as this one is not graded and we have NEVER made any sort of even remotely complex design without incorporating the database and presentation layers before, I figured it would be wise to ask. In addition, we haven't really had an assignment to make a class diagram without implementing the code, either...

    I have a feeling that the Covid19 situation coupled with often disrupted online learning has caused my university to drop the ball a bit, so I am hoping that someone can help enlighten me.

    Bonus question: are there any significant differences between c# and php that may be a 'trap'? Especially in regards to class inheritance, as that seems to be the biggest issue insofar.

    Thank you in advance!

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

    Does anyone else listen to kPop when programming?

    Posted: 09 Jan 2021 10:33 PM PST

    When I program I cannot listen to beats, podcast, but when I turn on some 2020 best KPop songs I start to get going! You don't understand much but it rhymes and they hype it up so much and you just start typing

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

    Help learning HTML

    Posted: 09 Jan 2021 04:52 AM PST

    Hello!

    I want to be capable of creating websites and apps, a sort of freelance programmer.

    I've been learning Html on freecodecamp and also bought a course on udemy "The Web Developer Bootcamp 2020" (9,99€).

    Am I going on the right direction?

    I'm thinking of taking a course this year, it's a year long and it's not a bachelor.

    Can I get a job with only this type of experience and projects, or I need actual bachelor?

    Any advices or tips would be welcome, as I don't understand much of programming languages and market.

    Thanks for reading :)

    (and happy new year!)

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

    How to stop nodemon from using index.js

    Posted: 09 Jan 2021 09:05 PM PST

    In my package.json I have "main": "build.js",
    but when I run nodemon in the console it attempts to start index.js
    which does exist in my project directory.
    Is there any way to override this behavior?

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

    User contribution to a document as a feature. Should I diff on the fly or track history with a git server?

    Posted: 09 Jan 2021 07:43 PM PST

    I'm working on a service that will allow non-technical users to contribute to a document. I need contributors to be able to see others' contribution history by line and character. I'd appreciate recommendations on how to go about storing this information.

    Git blame more or less aligns with what I am trying to do but I'm not sure how this would work since the document should be stored in a database. I'm also concerned about the cost of pinging git via AJAX is.

    Edit: Documents could be 100,000+ words with many contributors. So diff/blame performance must keep that in mind—though, it may not be needed for the entire document at once, rather specific lines at request.

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

    Help with Raspberry Pi Project Structure

    Posted: 09 Jan 2021 02:04 PM PST

    Hello, I am automating a home meat curing chamber and would like some direction in how to intelligently structure my overall project. I am an hardware EE so I have all the understanding I need regarding peripherals and control system stuff but I have very little real programming background. Especially with real time OS and web interface stuff. So please point out where I am making poor choices in general and where I seem to be misunderstanding the point, style, methods, or terminology in general.

     

    Project Outline:

    Curing/drying/ageing meat is a slow process which aim is to slowly remove water content from pieces of meat or sausage until roughly 30 to 40% of the starting weight. For more on that I suggest checking out /r/Charcuterie. My goal is to use a Raspberry Pi to control the temperature and humidity of the chamber, while logging the weight of the sausage, and the temp/humidity of the chamber. I was planning on a local web interface for me to check on the progress, change the settings, and look at historic data.

    Overall the core of the system is a simple python application that reads data from a temperature and humidity sensor and then turns on/off the cooling unit, humidifier, or dehumidifier. I was planning on using the same program to log the data to a csv file. I am using threading so I can run the two relatively independently, and these functions both have very slow sample times (seconds for control, minutes to hour for logger). So temporal accuracy or drift is not a real concern.

     

    What kind of web server/interface makes sense for this?

    All the raspberry pi tutorials are for wordpress or Linux-Apache-MySQL-PHP (LAMP) based. The wordpress one looks useful for a blog or a small store front. Not sure if that makes sense for basically an IoT device. But they don't really go into the pro and cons. So if you can point me in the right direction or a different one I would appreciate it.

     

    Does an SQL database make sense or just CSV files that I keep track of?

     

    If I wanted to plot stuff on the website. Would you recommend a program that creates images that the website hosts, or something more dynamic and interactive on the website itself. If so, what would that be called and what do I need to google?

     

    How would I pass settings from the website to python program?

    I figure I could have the webpage output to a txt file and the program to periodically read the text file.

     

    Thank you for the help. Sorry if some of these questions are very googleable, but I figured getting input on all of them combined would help me significantly.

    If there is a completely better method of doing this, please let me know.

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

    Suggestion: Android app development

    Posted: 09 Jan 2021 05:37 PM PST

    Hello all, I want to learn android app development but facing some difficulties on deciding how/where should I start about this. I have some programming knowledge on python and Matlab but basically have no idea about Java/kotlin or whatsoever. I'm finding it hard for me to grasp basic tutorials on app development.

    Could anyone please point me in the direction where I can learn to develop android app? Any suggestions on learning strategy/tutorials or other resources is welcome.

    My background: I'm from electrical engineering with severe procastinating issues but I decided to spend 2hrs per day on this. Taking baby steps to keep things steady. Is this a viable option?

    I appreciate your time. Thank you all.

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

    What is the likely-hood of a beginner getting an internship?

    Posted: 09 Jan 2021 03:42 PM PST

    Hi! I'm currently a freshman majoring in CS. I have beginners knowledge in Python and learned HTML&CSS over the winter break. At this point, should even be trying to apply for internships or focus on improving my languages instead?

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

    How should developers prepare for a future where ARM (potentially)replaces x86 in server and PC space?

    Posted: 09 Jan 2021 06:06 AM PST

    With the introduction of Apple M1 processor, ARM has stood up to be a capable competitor and an alternative to x86 processors. We can foresee a future where ARM captures considerable market share of x86 in the server space. That means we will be writing software that works and is optimised for ARM.

    Such a change would definitely affect developers who deal with low level code(device drivers, compilers, os and os kernels, etc) that requires knowledge and expertise of underlying cpu architecture.

    But does that affect general developers too?
    By general I am referring to developers who are mostly involved in implementing business logic using high level languages such as Python, Javascript, Java, C#, etc. Those languages and their implementations usually take care of running the same piece of code on different os and cpu architectures and developers just have to focus on implementing the requirements.

    If such "general" devs(including me) are affected, what can we do to prepare ourselves for the eventuality?
    Will some programming languages become more preferable over others?
    Should we invest time learning cross-platform frameworks even ?

    I am a self-taught developer with working experience in Python and Javascript and some of their related frameworks. As such, I have minimal knowledge of cpu internals or the inner workings those languages' compiler/interpreters which are potentially affected by the cpu architecture. If any statement(s) in my question is wrong, please excuse.

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

    Incomplete challenge

    Posted: 09 Jan 2021 02:30 PM PST

    Edit: It's JS

    Hello guy, after some time I've managed to achieve the 2 out of 3 solutions. But the array [5, 5, 5, 5] doesn't work.

    Sorry for the English and any possible mistake, I quite tired.

    Challenge

    In a soccer game between friends it is very common that nobody wants to be the goalkeeper. To resolve this impasse, a team decided to use the game "Rounds".

    In this game, the team makes a circle and each player "plays" any number X. After that, the team captain adds up all the numbers played and gets the result S. Then, he starts counting from 1 to S initially pointing to himself (and speaking loudly and clearly "one"), then to the player immediately his right (and saying "two") and so on. The goalkeeper will be the one being scored when the captain reaches S.

    For the purpose of facilitating the response of the problem, we will assume that the captain is in position 1, the player to his right is in position 2, the player to his right is in position 3, and so on. You must make a program that determines which position of the player should be the goalkeeper.

    Incomplete Solution

    function solution(number) {

    let sum = 0;

    for (let i = 0; i < sum.length; i++) {

    sum += number[i];

    continue;

    }

    sum > number.length ? (player = sum % number.length) : (player = sum);

    }

    solution([1, 3, 2, 1]);

    solution([1, 1, 1]);

    solution([5, 5, 5, 5]);

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

    Building an application for my business

    Posted: 09 Jan 2021 08:14 AM PST

    Hello, I am a complete beginner to programming, I want to launch an application for my business that is on most platforms (mostly the most popular like IOS and android). I wanted to first start learning Kotlin then Swift but I wanted to see if there's a more efficient way of doing this so I don't have to learn the programming languages one by one. If I do have to do that then what courses or resources do you guys recommend I learn my programming languages from. Thank you.

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

    How can I make a graph that illustrate the evolution of time to load data in a C program

    Posted: 09 Jan 2021 09:43 AM PST

    I have a school project, using C programming language, I have to get a json file using and load its data into an array of a structure, the professor asked us to make a graph that represents the evolution of time of loading these data according to their size. I don't know how should I do this, any ideas?

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

    Optimizing code (space and time requirements

    Posted: 09 Jan 2021 09:39 AM PST

    I have written this code that reads a JSON and CSV files compares them and outputs to a text file This output file will contains the association that my program has created in the following format <CSV\_SENSOR\_ID>:<JSON\_SENSOR\_ID>. If a flying object was only picked up by one of the sensors, the other sensor's ID should be reported as -1. If the distance between two readings is below 100 then we can assume that both IDs match.

    I understand that the bulk of my code is in the checkJSON function and the distance calculations, I was wondering if anyone has ideas to improve the speed and space requirements for this program and task! I think the space requirements are O(n) and the speed requirements are O(n^2) but correct me if im wrong!

    #include <vector> #include <fstream> #include <iostream> #include <string> #include <sstream> #include <cmath> //using namespace std; std::string filenameA = "input.csv"; std::string filenameB = "input.json"; /* * utlity function that converts degrees to radians * code * @param degree: angle in degrees */ long double toRadians(const long double degree) { // cmath library in C++ // defines the constant // M_PI as the value of // pi accurate to 1e-30 long double one_deg = (M_PI) / 180; return (one_deg * degree); } /** * function that calculates the distance give longitudes and latitudes * code obtained from: https://www.geeksforgeeks.org/program-distance-two-points-earth/ */ long double distance(long double lat1, long double long1, long double lat2, long double long2) { // Convert the latitudes // and longitudes // from degree to radians. lat1 = toRadians(lat1); long1 = toRadians(long1); lat2 = toRadians(lat2); long2 = toRadians(long2); // Haversine Formula long double dlong = long2 - long1; long double dlat = lat2 - lat1; long double ans = pow(sin(dlat / 2), 2) + cos(lat1) * cos(lat2) * pow(sin(dlong / 2), 2); ans = 2 * asin(sqrt(ans)); // Radius of Earth in // Kilometers, R = 6371 // Use R = 3956 for miles long double R = 6371; // Calculate the result ans = ans * R*1000; //answer in metres return ans; } /* * creating a structure of type SensorData that * holds the values for the ID, latitude and longitude */ struct SensorData { int id; std::string latitude; std::string longitude; }; std::vector<SensorData> csvData; //creating an array of type sensor data std::vector<std::string> outputData; // creating an output dataArray that is going to be used to write to file /** * function that reads the CSV file and * stores the data read into the csvData array * * @param filename: the name of the input file that is going to be reads */ void readCSV(std::string filename){ std::ifstream file(filename); //input file stream std::string input; std::getline(file, input); //read file into input string while(std::getline(file, input)){ // as long as there is a line to read std::stringstream ss(input); // creates a buffer with the characters in the string std::vector<std::string> data; while(ss.good()){ //used to check if the stream is good enough to work. It means that this function will check if this stream has raised any error or not. std::string sub; std::getline(ss, sub, ','); // read stringstream into string sub until delimiter which is a comma data.push_back(sub); } if(data.size() == 3) { //id, long, lat SensorData locData = {std::stoi(data[0]), data[1], data[2]}; csvData.push_back(locData); } } } /** * function that reads the JSON file and * compares the longitude and latitude to the CSV file and places the matching IDs in an output vector * also matches the flying objects detected by only the JSON "sensor" to -1. * @param filename: the name of the input file that is going to be reads */ void checkJSON(std::string filename){ std::ifstream file(filename); while(file){ std::string input; std::getline(file, input, '}'); if(input.size() < 6) continue; std::stringstream ss(input.substr(6)); std::vector<std::string> data; while(ss.good()){ std::string sub; std::getline(ss, sub, ','); sub = sub.substr(sub.find_first_not_of(" \t\n\r\v\f")); if(sub[1] == 'I') data.push_back(sub.substr(7, sub.size() - 8)); else if(sub[2] == 'a') data.push_back(sub.substr(12, sub.size() - 1)); else data.push_back(sub.substr(13, sub.size() - 1)); } bool found = false; for(auto i = csvData.begin(); i != csvData.end(); ++i){ if((data[1] == i->latitude && data[2] == i->longitude) || distance(stold(data[1]), stold(data[2]), stold(i->latitude), stold(i->longitude))<=100) { std::string output = std::to_string(i->id); output += ":"; output += data[0]; output += "\n"; outputData.push_back(output); csvData.erase(i); found = true; break; } } if(!found){ std::string output = "-1:"; output += data[0]; output += "\n"; outputData.push_back(output); } } file.close(); } /** * function that writes to an output text file. It also * matches flying objects picked up by only the CSV "sensor" file to -1. */ void writeFile(){ std::string output = "output"; output += filenameA[7]; output += ".txt"; std::ofstream file(output); if (!file) { std::cerr << "Error opening file for writing" << std::endl; return; } for(auto i : outputData){ std::cout << i; file << i; } if(csvData.size() != 0){ for(auto i : csvData){ std::string output = std::to_string(i.id); output += ":-1\n"; std::cout << output; file << output; } } file.close(); } int main(int argc, char * argv[]){ if(argc != 1 && argc != 3){ std::cerr << "Invalid arguments" << std::endl; exit(1); } if(argc == 3){ filenameA = argv[1]; filenameB = argv[2]; } readCSV(filenameA); checkJSON(filenameB); writeFile(); } 
    submitted by /u/QuantumBlender
    [link] [comments]

    Cron job help?

    Posted: 09 Jan 2021 12:09 PM PST

    Hi all,

    I have a pi 3b set up running octoprint to control my 3d printer.

    I would like to also use it to fire an hourly Cron job to change my esp32 RGB strip,set up as a sinric 'smart bulb' to a new, random colour, but have no idea where to start!

    It seems the sinric stuff can be changed using a websocket, see websocket example. There's also a python library if that is useful

    Thanks!

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

    Hybrid database and ACL question

    Posted: 09 Jan 2021 09:10 AM PST

    Hello all,

    I have a project that's using both NoSQL and SQL. The org/user information is being stored in the SQL database and I'm trying to think of the best place to store the ACL information.

    Traditionally, I would store it in the SQL, but this client has no idea how they'll want to setup their ACL in the future, so I'm thinking about storing the ACL (roles/permissions) in NoSQL.

    I can't think of any pitfalls of separating user information among dbs, but I thought I see what you all thought?

    Any help would be greatly appreciated!

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

    Fastest way to compare 2 large arrays

    Posted: 09 Jan 2021 08:47 AM PST

    Hello,

    I'm working on a python project (but solutions for c and c++ are also welcomed) where i need to compare 2 screenshots as fast as possible. At 1280x720 a full loop takes about 80ms on my pc but that's too much, it should be around 0-10ms.

    the code looks like this:

    x = 0 while x < 921600: if current_frame[x] != previous_frame[x]: new_array[x] = 1 else: new_array[x] = 0 x++ 

    If i had a nvidia gpu i could try cuda acceleration but i only have amd gpu.

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

    Javascript learning path

    Posted: 09 Jan 2021 08:38 AM PST

    I just finished learning frontend dev and I'm still in the process of learning javascript but I want to know what should I learn next after javascript? Something like nodejs or reactjs. Please help me.

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

    Never let a program write to C: drive? Is this possible on Windows?

    Posted: 09 Jan 2021 07:26 AM PST

    Is it possible to prevent all applications reading\writing to the C: drive and instead redirecting that write to the same path on the E: drive? I have an SSD with windows on it and I would like to have that be the only thing on it. Plenty of applications hard write to the C: drive without allowing to to specify where you want it to store it's files. My SSD is only 256GB and I have to clear it out regularly from all the shit that other programs put on it. Is this possible to do on Windows? Or is this a bad idea and is there another solution?

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

    How can I progress well in programming? How do I know if I understand the basics (if else while for function array). I have already done basic programming exercises. And when I read the code for other people doing the exact same exercise as me and they are buggy. I am unable to debug. When my

    Posted: 09 Jan 2021 06:40 AM PST

    How to really delete all files in a folder and the folder on Windows using python?

    Posted: 09 Jan 2021 05:55 AM PST

    this doesn't delete the folder

    shutil.rmtree('C:\\Users\\0\\Downloads\\preoutput') 

    this one causes this error

    Message=[WinError 5] Access is denied: 'C:\\Users\\0\\Downloads\\testdelete'

    import os import glob files = glob.glob('C:\\Users\\0\\Downloads\\preoutput') for f in files: #os.chmod(f, 0o777) os.remove(f) 
    submitted by /u/hwpcspr
    [link] [comments]

    If there’s any debugger that can show all the values of an array in a clear easy way? Best debugger for c? Why?

    Posted: 09 Jan 2021 04:52 AM PST

    make it display sth like this

    https://ibb.co/0F99d8z (need not *)

    windows

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

    Checking real cpu usages and memory footprint of a perticular code

    Posted: 08 Jan 2021 10:27 PM PST

    I saw many people do bench mark of different programing language or different functions or code.

    Let's assume I am writing a code in javascript , python and golang . The function is identical in 3 of these languages just different Syntex as per those languages.

    Is there any software or process to measure what are the CPU and memory consumption in real time in a graph or tablular data .

    Means I want to know if a function run for 5 ms ,in those 5 ms ,how much resources are consumed .

    So if I improve certain elements in the function , I can check the real effect via that graph or table data.

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

    No comments:

    Post a Comment