• Breaking News

    Tuesday, June 15, 2021

    I programmed while really high on weed and it forced me to use my brain like a Stack? Ask Programming

    I programmed while really high on weed and it forced me to use my brain like a Stack? Ask Programming


    I programmed while really high on weed and it forced me to use my brain like a Stack?

    Posted: 15 Jun 2021 08:41 AM PDT

    I chose to post this here because I do not know of any other popular programming subreddits that allow text posts (what a shame how embarrassing that fact is...)

    I tried to code while really high as an experiment. I struggled terribly for about 30 minutes or so while I was coming to terms with the insanely low focus and short term memory I was dealing with.

    After about 15 minutes of mindfulness meditation I started pushing away the ADHD random thoughts (that were 4x worse because of being high) and could find pockets of time to focus on some things for short periods of time. However my short term memory was still shot. I couldn't hold together multiple object ideas and relationships for more than what felt like a few seconds. Every new thing I'd think of, I'd lose the original idea. How was I supposed to remember what I was fixing and why?

    So what I ended up doing was pointing myself to a new code addition or problem for a small refactor I was working on. Then, if I ran into another problem that needed to be fixed because of what I was currently working on (and only because of this, very important) I went straight to that instead and gave myself a small comment reminder pointing back to the code I just came from.

    It was really scary because I really did lose track of what was in the stack, but I never lost track of current task or pointer back to what brought me there.

    All said and done, I created two new classes, moved some code out of an old class to a new one, cleaned up annoying new bugs that appeared due to the new functionality and more!

    I was really surprised it worked but also terrified that I'd lose focus before I closed out the stack. That took real focus power.

    This experiment reminded me that it's so much easier to white board bigger changes out first so you don't get lost, and to get rid of tightly coupled code architecture that you're going to forget needs updating later (and won't remember to put on your whiteboard). What that type of code does it forces you to work on multiple issues for the same stack at the same time and is easy to get lost.

    Edit: I think people are assuming some things so I'll clarify:

    1. No, I'm not new to weed
    2. No I've never been able to work when extremely high before due to it ruining my focus and memory
    3. Yes, I'm sharing a strategy to work while really high that I don't think everyone knows about and was wondering if others have done something similar.
    4. No, I don't recommend this. I think getting really high on weed helps more with being creative than logical, but it depends on how much you take.
    submitted by /u/hamburglin
    [link] [comments]

    How do I make a desmos esque app

    Posted: 15 Jun 2021 09:13 PM PDT

    I can't seem to figure out how to make math formulas look like math formulas once parsed in as a text field. Any idea how desmos does it?

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

    How do you PERSONALLY get back into "the flow" of programming after hours of interruptions? Looking for ideas to implement.

    Posted: 15 Jun 2021 05:50 PM PDT

    I started off the day spending 4 hours refactoring some code; it was a breeze and I kicked butt! I have spent the last 4 hours running monotonous errands that were unplanned but had to be done.

    Now that I have sat back down and begun refactoring again it feels foreign/ like i'm a beginner trying to read code for the first time. I'm neither mentally or physically tired and am use to 12 hour days.

    So the question is how do you personally get back into the flow of programming?

    P.S. Because of my schedule going forward, I know this will happen 1-2x a week. Any feedback I get from this question I will definitely try out to see if it works.

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

    Regarding Quaternions, Does This Look Correct?

    Posted: 15 Jun 2021 10:17 PM PDT

    I've written the following code that walks around a circle of sorts, and was wondering if the output was in-line with what one would expect the quaternion counterparts to look like.

    I'm trying to make the step to quaternion rotations, from having had used rotation matrices in the past... Found seemingly good resources on the subject and this was my first effort, using the formula...

    #please dont hate, i know this code is ugly.. from math import cos,pi,sin def invert(q): return [q[0],q[1]*-1,q[2]*-1,q[3]*-1] def qMult(q1,q2): return [q1[0]*q2[0]-q1[1]*q2[1]-q1[2]*q2[2]-q1[3]*q2[3], q1[0]*q2[1]+q1[1]*q2[0]+q1[2]*q2[3]-q1[3]*q2[2], q1[0]*q2[2]-q1[1]+q2[3]+q1[2]*q2[0]+q1[3]*q2[1], q1[0]*q2[3]+q1[1]*q2[2]-q1[2]*q2[1]+q1[3]*q2[0]] qGen = lambda theta : [cos(theta/2),sin(theta/2),sin(theta/2),sin(theta/2)] #TEST p = [1,0,0,0] q = qGen(0) qInv = invert(q) rotX = qMult(qMult(q,p),qInv) print("0:",rotX) p = [1, 0, 0, 0] q = qGen(pi/6) qInv = invert(q) rotX = qMult(qMult(q,p),qInv) print("30:",rotX) p = [1, 0, 0, 0] q = qGen(pi/3) qInv = invert(q) rotX = qMult(qMult(q,p),qInv) print("60:",rotX) p = [1, 0, 0, 0] q = qGen(pi/2) qInv = invert(q) rotX = qMult(qMult(q,p),qInv) print("90:",rotX) p = [1, 0, 0, 0] q = qGen((3*pi)/4) qInv = invert(q) rotX = qMult(qMult(q,p),qInv) print("135:",rotX) p = [1, 0, 0, 0] q = qGen(pi) qInv = invert(q) rotX = qMult(qMult(q,p),qInv) print("180:",rotX) p = [1, 0, 0, 0] q = qGen((5*pi)/4) qInv = invert(q) rotX = qMult(qMult(q,p),qInv) print("225:",rotX) p = [1, 0, 0, 0] q = qGen((3*pi)/2) qInv = invert(q) rotX = qMult(qMult(q,p),qInv) print("270:",rotX) p = [1, 0, 0, 0] q = qGen((7*pi)/4) qInv = invert(q) rotX = qMult(qMult(q,p),qInv) print("315:",rotX) p = [1, 0, 0, 0] q = qGen(2*pi) qInv = invert(q) rotX = qMult(qMult(q,p),qInv) print("360:",rotX) exit() # Quaternion unit cube for later graphical rotation testing ## Also nasty code! dont be a hater! ### This is just the direction for testing.... # verts = [[1,-1,-1,1], [1,1,-1,1],[1,1,1,1],[1,-1,1,1], # [1,-1,-1,-1],[1,1,-1,-1],[1,1,1,-1],[1,-1,1,-1]] # edges = [[0,1], # [1,2], # [2,3], # [3,0], # [4,5], # [5,6], # [6,7], # [7,4], # [0,4], # [1,5], # [2,6], # [3,7]] 

    Output from the above:

    0: [1.0, 0.0, 0.0, 0.0] 30: [1.0669872981077806, 0.06698729810778066, -0.8346253883128222, -0.06698729810778067] 60: [1.25, 0.24999999999999994, -1.6830127018922192, -0.2499999999999999] 90: [1.5, 0.4999999999999999, -2.414213562373095, -0.4999999999999999] 135: [1.8535533905932737, 0.8535533905932737, -3.054865846209121, -0.8535533905932736] 180: [2.0, 1.0, -3.0, -0.9999999999999999] 225: [1.8535533905932737, 0.8535533905932737, -2.3477590650225735, -0.8535533905932737] 270: [1.5, 0.5000000000000001, -1.4142135623730954, -0.5000000000000001] 315: [1.1464466094067263, 0.14644660940672632, -0.5582600835436322, -0.14644660940672632] 360: [1.0, 1.4997597826618576e-32, -1.2246467991473535e-16, -2.465190328815662e-32] [Finished in 0.0s] 

    Any input is appreciated, thank you!!

    submitted by /u/Ok-Aspect-530
    [link] [comments]

    How do moderators know which person an IP belongs to?

    Posted: 15 Jun 2021 03:47 AM PDT

    I've recently heard about a situation where a Youtuber was posting on lolcow, and the mods were able to trace that IP back to that person.

    I understand that mods can see the IP of the users, but how do they know what person/name this specific IP address belongs to? I thought the names of IPs were only known to the telecommunication providers

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

    HTML; What is the function called when you go from a user inputted text box to a posted site?

    Posted: 15 Jun 2021 06:59 PM PDT

    For context, at my job, users will input data into a text box but they have to do HTML formatting themselves. This causes issues because some people just are not remotely tech savvy and cannot use basic HTML. What is the feature called where if a user types and formats text freely on a text box (such as on reddit when typing up a post, or on Facebook when typing a status) and then the formatting "sticks" when you submit the form, post, etc.?

    Thanks!

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

    Wifi (programming) Questions

    Posted: 15 Jun 2021 11:23 AM PDT

    Hey guys, what do you recommend I learn in order to communicate with a wifi (that I am the owner of) to perform functions like block/limits people on the network? Also, how can I see "stats" (phase, current, RF power etc) and lastly can I see the machine code? Can I modify it? Can I see the interaction of the current functions actually in machine code?

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

    What does it take to land that first dev job?

    Posted: 15 Jun 2021 10:20 AM PDT

    Hey, folks. I'm a recent grad from Uni..well, I will be this month. I have a 3.67 GPA and knowing that you can't really get experience without experience, I've been building a github portfolio.

    Some years back, I worked my way up from pest control technician to the company's one and only IT crew, doing all things IT + Dev (full stack) with multiple platforms but, my limited experience working directly with (for) the client made the work stressful so, I lost that position. I really thought I'd be able to use that experience to land a new job and when I saw that wasn't working, I went to college, made straight As, learned conversational Spanish, and even wrote a small application that my current company is now using (I'm tech support and wrote the application between phone calls).

    My interviews blow people away. I impress all of my bosses. I have the highest numbers and quality. Yet, somehow, despite all of this I can't get the one shot. I've looked at contracting sites but, it looks like it's the same lyrics to a different tune (you gotta have the experience to get the experience) so, even getting just those little jobs to work and list has seemingly become impossible.

    I recently, despite having a stellar company wide reputation and demonstrable dev skills, was passed up for a dev position at my place of work. Lately, they kind of treat me like I'm dumb and I hate it. Up until this point, I was highly respected.

    Let me be real with you all, I'm black, I'm a woman, I'm nearly 40, and I'm a lesbian...one of those butchy ones (think Queen Latifah from Set it Off but, business casual). What are my odds as who I am? Should I hang this dev thing up and take up knitting? Are the above listed superficial factors getting in the way of what I'm trying to do? Or do I just need grit? Please, be honest.

    Also, $500 from my first paycheck to anybody who can get me in the door.

    Edit: You guys are dope. Like, y'all need to be shipped by cartels. Y'all need to be snuck across borders and sold in bulk and then rapped about on gangster albums from the 90s. Thank you guys for taking the time to help.

    submitted by /u/Agreeable-Ad-4791
    [link] [comments]

    Getting into Python

    Posted: 15 Jun 2021 01:57 AM PDT

    Hello everyone. I am a 17 year old student with some basic Python experience. I can use basic selenium in Python, make a calculator and some other beginner stuff. I don't really want to rely on my school so I am learning programming by myself. My current plan is to use GitHub Student Pack in order to get basic Python course and Data analysis in Python course from datacamp and go form there.

    Is this a good way to go? If it is what should I do after finishing these courses. Any alternatives?

    Sorry for my eng its not my first language, I have no clue how to write posts so feel free to ask me for any details if I should provide more info.

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

    Is streaming just writing data to a temp file and reading it as its being written?

    Posted: 15 Jun 2021 12:16 PM PDT

    I'm trying to understand the concept of stream. Surely the data has to be written first before it can be read, otherwise real-time data will just hog a ton of resources, right?.

    I received a lot of scrutiny for this a few months ago, a lot of people were angry (yes angry, idk why) that a control such as picturebox was just a picturebox and that I could not benefit from it's usage, but I don't think they really really understanding the logic behind my question.

    If I create an image through a tick using (example language c#) :

    var img = new Bitmap(displays.screen[cmbMonitors.SelectedIndex].Bounds.Width, displays.screen[cmbMonitors.SelectedIndex].Bounds.Height); var grph = Graphics.FromImage(img); if (displays.screen[cmbMonitors.SelectedIndex].Bounds.X < 0) grph.CopyFromScreen(-1920, 0, 0, 0, img.Size); else grph.CopyFromScreen(0, 0, 0, 0, img.Size); // Show preview of image pbImageRelay.Image = img; 

    This is just creating a bitmap frame and the timer is updating the box creating a motion, right? So if I were to use accord.vision to utilize object detection (instead of a webcam) I could detect an object in motion on my desktop right, such as moving a file?

    submitted by /u/deuz-bebop
    [link] [comments]

    Embed OneNote into application?

    Posted: 15 Jun 2021 11:55 AM PDT

    Is it possible to embed OneNote into an application in C#? With a normal OneNote view. I have found the API but don't quite understand it.

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

    C++ Efficiency Question

    Posted: 15 Jun 2021 03:32 PM PDT

    So I have this node class in a game engine, and I want to make sure it's efficient as I can get it. It's basically a wrapper around a std::list of child nodes which inherit from this class.

    Are there any ways to know if this is the most efficient method? Here's an example of me constructing the hierarchy manually (will probably script this eventually):

    Context: Although I've been coding for a long time, I'm only getting back into c++ recently and C++17 stuff is all new to me.

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

    Curious how to parse and validate a (very) large string.

    Posted: 15 Jun 2021 03:19 PM PDT

    Hey all,

    I've been tasked with developing a bot that listens to a GitHub Issue Webhook that will parse/process each issue that is filed on a repo. The goal for this processing is to validate whether or not the text in the issue matches a massive templated form. We are using it as a form of ticketing system for one of our internal processes.

    Currently implementing this in Java per the team's request. I have over 5 years of Java experience, but haven't really done parsing like this before. After searching online for 1 or 2 days, I havent found an elegant solution for this yet.

    First, let me show you the template in question.

    Essentially it is a multi-hundred line GitHub Markdown template like this:

    ### Section 1: Section title ### Section 2: Section title ### Section 3: Section title ... ### Section N: Section title 

    My thought is that I could read the GitHub Issue Body line by line and try to satisfy an array of regexes in sequence. If it fails on a particular regex, we would know exactly which part of the template is missing or noncompliant and can inform the user via comment or issue label, etc. However, this makes the solution very brittle as these regexes would need to be updated any time the template is updated. It also feels like a nightmare to write a couple hundred regexes and then ask other team members to review and potentially maintain them, especially considering I don't have a ton of regex experience myself.

    Some Psuedocode illustrating my idea:

    // Not real regex lol. You know what I mean. String[] templatePatterns = new String[]{"### Section 1: Section title", "### Section 2: Section title", "### Section 3: Section title", "...", "### Section N: Section title"}; int patternIndex = 0; foreach line in issueBody{ if(line.match(templatePatterns[patternIndex])){ patternIndex++; } } // If we havent traversed all the patterns successfully, if(patternIndex != templatePatterns.length()){ log(error, "Issue does not match template on following pattern: ", templatePatterns[patternIndex]); } 

    What are your thoughts? Have I missed some core feature of Java to help with this? Is my google-fu rusty?

    I really appreciate any input you might have on this.

    Thanks!

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

    What does it mean for a database to be "relational"?

    Posted: 15 Jun 2021 04:38 AM PDT

    I'm just getting into computer science and have been learning about databases and SQL. However, no one has ever taken the time to explain me what the term "relational" means in this matter. So I thought it would be a good opportunity to help anyone in my same position to ask here about this topic. Of course, feel free to give any kind of explanation, brief or long, it will always be appreciated.

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

    How do I get git to prompt my password, for god's sake.

    Posted: 15 Jun 2021 09:02 AM PDT

    I need to apply for a programming internship and I can't push my code to a GitHub repo.

    I've been away from programming for at least 5 years, but I remember quite well that in 2016, when I did git push -u origin main for the first time in a repo (after providing the remote URL), it would ask me for my credentials.

    Now, due to some satanic plot they introduced some kind of GCM credential manager and when I try to push the repo it does nothing, just hangs there, black screen nothing happens. I've been looking for documentation that actually tells me how to set my credentials in this thing all morning, so far haven't come across a working solution that will let me input my credentials for GitHub.

    Help is suuuuper appreciated, thanks.

    EDIT:

    For you guys to understand, my problems is the same as this person's problem: https://stackoverflow.com/questions/59216268/git-credential-manager-for-windows-gcm-doesnt-prompt-for-credentials

    Documentation has been useless, so far.

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

    What is a good replacement for Freenode when you just want to ask a quick question about some #language, #editor or #tool?

    Posted: 15 Jun 2021 11:04 AM PDT

    How do you overcome learning walls and discipline issues?

    Posted: 15 Jun 2021 08:48 AM PDT

    Pretty long. TLDR I know basic programming concepts and know how to find what I need on google but that makes me feel inadequate and I have terrible discipline so I tap out after 2-4 weeks of learning. What's a better way to approach learning?

    I always feel like if I knew how to program, I'd love it. I love making things and I love solving problems whether it's through my own research or just straight up going to discord or stackoverflow and asking someone who already has the answer to my issue. But my own problem I can't solve is that I have awful discipline — if that's what you want to call it.

    I start learning a language for like 2-4 weeks. Then I either get caught up in life or I just lose interest. And I hate learning like that. Just reading through a textbook from start to finish, or watching a video series like "learn python 101" to understand the computer science behind a language. Of course it's helpful to know but I'm not interested in that.

    I can't keep myself interested or committed.

    But when I have my own ideas that I want to make, I'll literally sit at my computer trying to bring it to life for 20 hours a day for a month if that's what it takes.

    I've semi automated a bunch of issues that get called in at my help desk job with powershell. I didn't even know powershell existed before I got this job, and it wasn't even expected of me to do this I just wanted to do it. I was too busy at work to learn about it or make my scripts so I'd spend all of my free time at home setting up an environment that closely mimics what we have at work, then just learn about powershell and make and test scripts to automate a bunch of different processes. Spent my entire weekends off work doing this.

    I Made a python script to scrape all the posts from /r/HardwareSwap that mentioned selling a specific ryzen, then comment on the post saying "PMED!" or "DMed!" Or "I'm interested. I sent you a private message" and then it DMs the person. So I could try to get at the Ryzen cpu before everyone else since I had been trying to buy a Ryzen off there for like 3 weeks but everyone kept beating me to the posts.

    I Made another python script that just scans all the posts and comments from /r/popular and it scans every url mentioned in the comments. I made this script so it can scan the URLs that are mentioned and see if those urls redirect to another url as I've noticed in the last month there's been a phishing scam going around on reddit where someone tries to sell a t shirt by posting it on reddit but not advertising that it's for sale at all. They just post a cute/cool t shirt knowing at least one person will comment saying omg this is awesome where can I buy one?? Then they drop their phishing link that redirects to another phishing link. So I made the bot hunt for all these comments and when it finds a phishing link or a redirect to their main phishing site, it just leaves a comment on the post with all of the info to like username, account age, the disguised phishing link, account age karma and information on identifying the scam. This calls out the scam and make others aware of it. The Script also stores all of the information in mysql as well just so I can do something with the data later whenever I figure that out.

    That script took me like 3 weeks of me sitting at my computer for 12 hours a day reading about praw and scraping urls with python, looking on stack overflow of snippets that would do what I want, messing with regex patterns until I find one that gets what I need. I enjoyed that. I loved making it and I was happy when it was finished.

     

    I've been a mod for like 4 different twitch streamers at one point or another. So I make stuff for them as well. One streamer wanted a command in their chat to tell us what current song is playing on their Spotify. There used to be a plugin that already did this but it wasn't supported anymore. So through my own research I found you can link last fm to Spotify and then scrape xml data from last fm. So that's what I did and I just put it on a web server. Then anytime someone typed !song in chat, it would fetch whatever is on the web server and post it in chat. "Now playing Such Great Heights by The Postal Service"

    For Another streamer, I just made this "darts" game which is basically just a random number generator with weighted odds. They type !darts in chat and then it runs some JavaScript that generates a random number out of 1000 and a weighted list. If it gets 1-10 then there's another rng ran so that it picks from a drop table and puts it in chat. "User threw a dart and hit a bullseye! Rolling drop table........ They win 1000 in game Gold!" Then The streamer has to give away 1000 gold.

    Currently working on a discord bot for the same streamer that will generate a bingo board so anyone that watches the stream and is in the discord server can participate and then cross out a bingo board whenever a certain event happens on stream for even more giveaways and viewer interaction.

    I love making stuff like that. I was never bored when I was working on any of the stuff I've mentioned here. But if I go on YouTube or Udemy and watch beginner to expert JavaScript/python/java/go/php/powershell/sql/c/c#/.net series, I tap out after a week.

    But that's pretty much all I can do is make scripts.

    Get data from some source. Store data in array. Loop through array. Pick random array element. If condition Do math function. Print result. Post data to sql. Delete data from sql.

    And most of the time it's just me googling. "How to add to end of array in JavaScript." "How to shuffle an array in JavaScript" "How to scrape a url with powershell invoke web request" "python for loop example"

    If I lost internet access and someone sat me in a room and said "okay make all of this stuff again" I might be able to make my help desk powershell scripts but that's pretty much it. I'd mostly be helpless for the others. I'm just a professional googler.

    And I doubt android apps or web pages or something like autocad is built entirely on math functions, loops and arrays.

    So idk. Where do I go from here? Anyone else in a Similar situation? Any insight?

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

    Need help with app prototyping

    Posted: 15 Jun 2021 01:39 PM PDT

    I recently got into app prototyping so I am a complete noob. The platform I am using is Framer. My issue is I am having trouble implementing a scrollable window for a stack.

    I guess the purpose of this post is to connect with someone who is a bit experienced in that area and could clear up some confusions I have.

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

    16 going to college next year need advice

    Posted: 15 Jun 2021 01:27 PM PDT

    I'm 16 going into college for a diploma in IT and need advice

    So basically I want to be prepared to go into the course and I don't wanna walking like a fool. The things I'll be doing in the course are

    • Information Technology Systems
    • Creating Systems to Manage Information
    • Using Social Media in Business
    • Programming
    • Website Development
    • Data Modelling

    Any websites or things I can do to practise.

    BTW... The reason I don't wanna search this up on youtube is that I would rather have someone actually give me advice, I don't know, I just like this.

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

    What's more than a warning but less than an error?

    Posted: 15 Jun 2021 03:33 AM PDT

    In an app, you generally have multiple kinds of messages. You have debug messages, warning messages, error messages, etc.

    Usually, error means something crashed or is not working properly and that's really bad.

    Warning generally means you're doing something risky/deprecated/not advised, but it won't necessarily crash the app.

    I am looking for what you'd call a message that's somewhere between warning and error: it would mean something like "You're doing something seriously wrong and it's bound to crash the program or generate problems, but who am I to stop you."

    I kind of want to emphasize that "this is a really nasty warning". I'd like a new word for that.

    What would you call such a message?

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

    [Kotlin] Best approach for after-ending triggers

    Posted: 15 Jun 2021 06:11 AM PDT

    Hi all!

    I'm implementing one of many (yet to define) actions that will run after an ads campaign finishes.

    I was thinking on something like calling a service method that executes all actions by injecting a List<IEndingAction> instance variable with each implementation of IEndingAction having an execute method that does whatever it needs with a common input (the ads campaign that is finishing)

    I have done this for many other scenarios alike, but I'd like to read your comments.

    Thanks!

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

    C Coding File I/O Help!!!

    Posted: 15 Jun 2021 06:46 AM PDT

    hey, why did my code do the endless loop even though i have add EOF in the while code

    here's the code (sorry for using my native language, but then again it's just another variabel name)

    void menampilkanData(){

    system("cls");

    fdata = fopen("fileObat.txt", "r");

    while(fscanf(fdata,"%d %s %s %d %d %d/%d/%d %d/%d/%d", &dO.id, dO.nama, dO.noRak, &dO.stok, &dO.harga, &dO.tglProd, &dO.blnProd, &dO.thnProd, &dO.tglEx, &dO.blnEx, &dO.thnEx)!=EOF){

    printf("%d %s %s %d %d %d/%d/%d %d/%d/%d", dO.id, dO.nama, dO.noRak, dO.stok, dO.harga, dO.tglProd, dO.blnProd, dO.thnProd, dO.tglEx, dO.blnEx, dO.thnEx);

    } fclose(fdata); getch(); 

    system("cls");

    printf("9. Kembali ke kelola obat\\n"); printf("0. keluar\\n"); 

    scanf("%d", &pilih);

    switch (pilih){

    case 9:

    kelolaObat();

    break;

    case 0:

    break;

    default:

    printf("Masukan anda salah!");

    getch();

    }

    }

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

    How to remove all characters after a specific character in python?

    Posted: 15 Jun 2021 10:20 AM PDT

    Say i had something like:

    John_9823
    Ben_120
    Tom_1923

    How would I remove everything after the _ but keep everything before it?

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

    Multi-threading takes longer to run than running on a single thread

    Posted: 15 Jun 2021 10:01 AM PDT

    Hi guys, I am learning OPENMP on C++. I am posting my code here but basically I am trying to approximate pi using darts and a square. What is bothering me is that if I run on 8 threads, then the code, on avg, takes 1.5 seconds longer than running it on a single thread. Any ideas of why this might be happening?

    #include <omp.h>

    #include <iostream>

    #include <random>

    main()

    {

    double npoints{100000000};

    int circle_count{0};

    std::default_random_engine generator;

    std::uniform_real_distribution<double> distribution (0.00,1.00);

    omp_set_num_threads(8);

    double t1 = omp_get_wtime();

    #pragma omp parallel num_threads(8)

    {

    #pragma omp for reduction(+:circle_count)

    for(int i=0; i<(int)npoints; ++i)

    {

    double xcoord = distribution(generator);

    double ycoord = distribution(generator);

    if( (xcoord-0.5)*(xcoord-0.5) + (ycoord-0.5)*(ycoord-0.5) <= 0.25)

    {

    ++circle_count;

    }

    }

    //circle_count += local_circle_count;

    }

    double t2 = omp_get_wtime();

    std::cout << t2-t1 << std::endl;

    double PI{4*circle_count/npoints};

    std::cout << PI;

    }

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

    No comments:

    Post a Comment