• Breaking News

    Saturday, February 6, 2021

    How can I be ready for competitive programming? Ask Programming

    How can I be ready for competitive programming? Ask Programming


    How can I be ready for competitive programming?

    Posted: 06 Feb 2021 08:40 PM PST

    Hey, I'm a high school senior. I have good knowledge in python, C#, C, html, CSS, and JavaScript. How can I be prepared for competitive programming like IOI and other competitions? Where should I practice and learn? And what topics I should learn?

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

    Creating a basic shapes program with user input in Eclipse

    Posted: 06 Feb 2021 09:37 AM PST

    New to studying computer science and need to create a basic program in which the user can create a rectangle, triangle or hexagon with the colour of red, green or grey. I think I'm ok at drawing the shapes using rect.setx(10) etc, but I'm not quite sure how to make the user input work properly. If the input is invalid I need an appropriate message telling the user the correct shapes and colours (I guess using else)

    I am very new to the subject and eager to learn!

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

    Tools to engineer documentation

    Posted: 06 Feb 2021 12:41 PM PST

    I'm going to have to massively overhaul the documentation for a larg-ish product that has, currently, little to none.

    Some things to do are clear and well-defined (adding type annotations, documenting the code itself with the tools for the language/framework, swagger for the API, ...), because there are well-defined tools for them.

    So my question is: what are the tools for documenting everything else (business logic, architecture, workflows, processes, ...)? I was thinking of using a wiki, but that's like saying "use a text editor", or Confluence for that matter. There must be something structured towards documentation, encouraging good practices, suggesting stuff, ...

    Is there?

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

    Has anyone managed to successfully use C++20 modules in their programs?

    Posted: 06 Feb 2021 12:41 PM PST

    All my own attempts so far have critically failed without producing any fruits. I can't even seem to get the simplest example (i.e. https://mariusbancila.ro/blog/2020/05/15/modules-in-clang-11/) to work no matter what compiler version I try - gcc 10.2, Clang 11...

    Searching in google doesn't seem to find any success stories either.

    Are they currently in a usable state, or is it just a problem with my own configuration/environment?

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

    How to make a chrome extension not run the content_script until the user hits the toggle button in the toolbar?

    Posted: 06 Feb 2021 05:27 PM PST

    background.js

    var toggle = false; chrome.browserAction.onClicked.addListener(function (tab) { toggle = !toggle; if (toggle) { chrome.browserAction.setIcon({ path: "on.png", tabId: tab.id }); chrome.tabs.executeScript(tab.id, { file: "your_js_file.js" }); } else { chrome.browserAction.setIcon({ path: "off.png", tabId: tab.id }); chrome.tabs.executeScript(tab.id, { code: "alert()" }); } }); 

    manifest.js

    { "name": "checker", "version": "1.0", "description": "Example!", "permissions": [ "activeTab", "tabs" ], "background": { "scripts": [ "background.js" ], "persistent": false }, "content_scripts": [ { "matches": [ "*://open.spotify.com/search/*" ], "js": [ "your_js_file.js" ], "run_at": "document_start", "all_frames": true } ], "browser_action": { "default_icon": "off.png", "default_title": "icon" }, "manifest_version": 2 } 
    submitted by /u/hwpcspr
    [link] [comments]

    If javascript code click() an element and the page redirects to another url[same domain], why can’t document.getElementsByClassName(‘class’)[0]?

    Posted: 06 Feb 2021 09:13 PM PST

    the class exists on that new page but not the original one, so it's undefined, how to fix this issue?

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

    API Separation of concerns

    Posted: 06 Feb 2021 08:52 PM PST

    Hi! So i'm recently completed a Web development online bootcamp that used javascript for front end scripting also backend stuff with NodeJS/Express. I'm trying to get some more practice by creating a React app that get's all of it's data from an API. Anyways I was just trying out Mozilla Web docs Fetch method and I realized that I could use it on the client side and server side. Is it acceptable to make fetch and other api calls on the client side or do they need to server side only?

    Thank you!

    Edit: Spelling/phrasing

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

    Once again, a question about bootcamps...

    Posted: 06 Feb 2021 08:30 PM PST

    I'm getting closer to 40 and more than ever I'm looking to change up my career. The pandemic has made my wanting a change in careers even more so urgent.

    Currently I'm an unemployed career(10 yr+) bartender, needless to say, not feeling too much hope in that field, nor do I really have the drive to do that anymore for a multitude of reason. Prior to that I built massive A/V systems for about 8 years and got my first taste in coding with low level programming of integrated control systems.

    I've been wanting a career change for a while now and the state of the world has put even more fire under my ass to do so. For the last 6 months I've been trying to teach myself as much as I can regarding coding with the idea of going to a bootcamp once I felt like I had a good enough idea of what I'm doing before I invested the time and money.

    I started off using Codecademy and have moved on to using Treehouse, which I feel like I've gained way more knowledge with how it is structured. On Treehouse I was focused on JavaScript until I hit a wall where it felt like nothing was sinking in and I was just lost. So I started over entirely and have have been doing their front end course, which I feel so much more drawn too.

    My goal was to be at least enrolled in a bootcamp by the year anniversary of when I lost my job. I was looking into Hack Reactor, but now I'm leaning more toward focusing on the front end side of things. I was drawn to Hack Reactor primarily for the reviews and overall reception and credibility I've come across. Another big factor is that I would only have to pay a deposit up front until I'm hired.

    With all that said, I'm really just looking for suggestions of a potential bootcamp or even what direction to go in. I don't think that I can afford anything beyond the deposit, so I would be looking for a school that waives the fees until being hired. I'm also torn on where my focus should be. Would it be better to go the full stack route, just focus on front end,or continue my original plan with Hack Reactor and focusing on JavaScript, with the hopes that it would actually click in a more formalized environment?

    TLDR; a career change is necessary, I've tried to teach myself as much coding as I could with limited time and now I'm looking for the right bootcamp and direction of focus in a bootcamp that that doesn't require tuition upfront.

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

    Addition Algorithms

    Posted: 06 Feb 2021 07:49 PM PST

    Disclaimer:

    Don't worry. I know much better than to get excited over a "discovery" you've made or a wheel you thought you've invented... and I plan to conduct more independent research on the topic later. However, I'm currently working and I thought I'd maybe get the ball rolling and possibly acquire some insights/ sources/ articles from folks who've been around this particular block before while I'm occupied.

    Some stuff I've been wondering about:

    What possibilities, if any, are currently being researched to improve logical summation algorithms at the near-hardware level?

    What are some of the "premier" algorithms in use today and could I get you to break down the numbers for me in terms of performance?

    Are there any NON-hardware related usecases in which an efficient summation algorithm (or something different but reminiscent of one) would be useful?

    If I cited an algorithm that could perform 100% accurate summations on 32-bit integers in at MOST 5 iterations- each iteration consisting of 8 logical gate operations performed on each bit, thus 8ops × 32bits × ~5passes, would this be impressive by the standards of any decade?

    Thanks for the advice or the abuse- whatever comes to me.

    submitted by /u/ABit-2Average
    [link] [comments]

    (X-post from r/cellular_automata)I need some help adding wind and elevation to my forest fire simulation(in python using cellular automata)

    Posted: 06 Feb 2021 01:45 PM PST

    I can already do it with a flat/no wind forest(see code below i found somwhere) but i struggle to add wind/topography to be more realistic. I read some papers and kinda already know the principle behind it, but my knowledge in python is still fairly limited. If my post doesn't fit please let me know.

    from random import sample, randrange from tkinter import Tk, Canvas, Scale, Button, Label, N, ALL COLORS=["ivory", "lime green", "red", "gray75"] def random_forest(p, n): units=[(line,col) for col in range(n) for line in range(n)] ntrees=int(n**2*p) trees=sample(units,ntrees) states=[[0]*n for _ in range(n)] for (i,j) in trees: states[i][j]=1 return states def voisins(n, i, j): return [(a,b) for (a, b) in [(i, j+1),(i, j-1), (i-1, j), (i+1,j)] if a in range(n) and b in range(n)] def fill_cell(states, line, col): A=(unit*col, unit*line) B=(unit*(col+1), unit*(line+1)) state=states[line][col] color=COLORS[state] cnv.create_rectangle(A, B, fill=color, outline='') def fill(states): n=len(states) for line in range(n): for col in range(n): fill_cell(states, line, col) def update_states(states): n=len(states) to_fire=[] for line in range(n): for col in range(n): if states[line][col]==2: states[line][col]=3 for (i, j) in voisins(n, line, col): if states[i][j]==1: to_fire.append((i, j)) for (line,col) in to_fire: states[line][col]=2 def init(): global states, cpt, ntrees, running p=int(curseur.get())/100 running=False cpt=0 lbl["text"]="%3s %%" %0 curseur["state"]='normal' states=random_forest(p, n) ntrees=int(n*n*p) cnv.delete(ALL) fill(states) def set_density(states, p): n=len(states) trees= [(i,j) for i in range(n) for j in range(n) if states[i][j]==1] nontrees=[(i,j) for i in range(n) for j in range(n) if states[i][j]!=1] density=len(trees)/n**2 new_trees=int(n*n*p) before=len(trees) now=len(nontrees) delta=abs(new_trees-before) if new_trees>=before: for (i, j) in sample(nontrees, delta): states[i][j]=1 else: for (i, j) in sample(trees, delta): states[i][j]=0 def make_forest(percent): global ntrees cnv.delete("all") p=float(percent)/100 ntrees=int(n*n*p) set_density(states,p) fill(states) def propagate(): global cpt, running update_states(states) nfires=sum(states[i][j]==2 for i in range(n) for j in range(n)) cpt+=nfires percent = int(cpt/ntrees*100) cnv.delete("all") fill(states) lbl["text"]="%3s %%" %percent if nfires==0: running=False return cnv.after(150, propagate) def fire(event): global running, cpt i, j=event.y//unit, event.x//unit if states[i][j]==1: states[i][j]=2 fill_cell(states, i, j) cpt+=1 if not running: running=True curseur["state"]='disabled' propagate() n=50 unit=10 root = Tk() cnv = Canvas(root, width=unit*n-2, height=unit*n-2, background="ivory") cnv.grid(row=0, column=0, rowspan=4) btn=Button(root,text="New", font='Arial 15 bold', command=init, width=8) btn.grid(row=0, column=1, sticky=N) lbl=Label(root,text="%3s %%" %0, font='Arial 15 bold', bg='pink', width=5) lbl.grid(row=2, column=1, sticky=N) cnv.bind("<Button-1>", fire) curseur = Scale(root, orient = "vertical", command=make_forest, from_=100, to=0, length=200) curseur.set(50) curseur.grid(row=3, column=1) init() root.mainloop() 
    submitted by /u/ThatAfternoon9789
    [link] [comments]

    Help with real stock data

    Posted: 06 Feb 2021 06:57 PM PST

    Hello I am starting in py, I wanted to know if there is any way to modify this code so that it delivers the quotes by a handler, since I can not find a way to modify ... When running the api these are sent automatically every 60 seconds ... My idea is to call as follows INTC (/intc) <get share price> Thank you

    import logging from telegram import Update from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext import requests import time import schedule import datetime from pandas_datareader import data as pdr import yfinance as yf # Enable logging logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO ) logger = logging.getLogger(__name__) ### DEFINO LOS HANDLER ### def hola(update: Update, context: CallbackContext) -> None: """Send a message when the command /hola is issued.""" update.message.reply_text('Hola, DAME TU CUPO MENSUAL, perdon, es la costumbre de argy') def nahuel(update: Update, context: CallbackContext) -> None: """Send a message when the command /nahuel is issued.""" update.message.reply_text('Ah, pero La hicieron mierda') def rick(update: Update, context: CallbackContext) -> None: """Send a message when the command /rick is issued.""" update.message.reply_text('He aqui un verdadero ladri') def german(update: Update, context: CallbackContext) -> None: """Send a message when the command /german is issued.""" update.message.reply_text('¿sale o no sale ONE con ese gap?') def main(): """Start the bot.""" ## TOKEN DEL BOT ## updater = Updater("xxxx389537:AAGDTaYAz-htwJV_6n9UEMsce3SgNu7c6XE") ### ACTUALIZO LOS DISPATCHER ### dispatcher = updater.dispatcher ### EJECUTO EL COMANDO PARA LA RESPUESTA ### dispatcher.add_handler(CommandHandler("hola", hola)) dispatcher.add_handler(CommandHandler("nahuel", nahuel)) dispatcher.add_handler(CommandHandler("rick", rick)) dispatcher.add_handler(CommandHandler("german", german)) # Start the Bot updater.start_polling() updater.idle() if __name__ == '__main__': main() price='' def INTC(): bot_token='xxxx389537:AAGDTaYAz-htwJV_6n9UEMsce3SgNu7c6XE' bot_chatID='-xxxx43831' response= "Let me fetch Latest quote ford you \n" symbol='INTC' aapl=pdr.get_data_yahoo(symbol, start=datetime.datetime(2021, 2, 5), end=datetime.datetime(2040, 12, 14)) price=(aapl["Close"][0]).round(2) price=str(price) price="BOTHelper(c)2021 @ST4Helper "+symbol+ " is $"+price price=str(price.encode('utf-8','ignore'),errors='ignore') send_text='https://api.telegram.org/botxxxx389537:AAGDTaYAz-htwJV_6n9UEMsce3SgNu7c6XE/sendMessage?chat_id=-xxxx43831&parse_mode=Markdown&text=' + price response=requests.get(send_text) print(response) while True: INTC() time.sleep(60) 
    submitted by /u/skLAIMINTC
    [link] [comments]

    Collecting data from webpages and saving it to files

    Posted: 06 Feb 2021 08:14 AM PST

    Hey everyone, Im collecting data on grateful dead shows, but running into some logistical issues. I have written a python script that takes data from various text files, grabs the stuff I care about, organizes it, and puts it into a csv file. Unfortunately, I can't find a single file with all the setlist information, like I could for other parts of my data, so I need a way to:

    1: go to:https://www.cs.cmu.edu/~mleone/gdead/setlists.html

    2: select a year, for example: 1972: https://www.cs.cmu.edu/~mleone/gdead/72.html

    3: Then go link by link and copy that data into a text file, ultimately grabbing every show

    I tried web scraping via python, but Im not super familiar with it, and I couldn't figure out a way to do it, partly because the files I need are stored on the web as txts, not HTML. I also tried a program called Macro Scheduler, but that doesn't seem to have the functionality I need. I've put a good deal of time into the other aspects of this project, so I don't want to give up, but I also don't want to do this manually.

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

    Advice/Assistance for a piece of my Code please - functions

    Posted: 06 Feb 2021 02:50 PM PST

    Hi all, relearning Python, well coding, to be exact. I'm stuck on trying to implement a timeout flag for my code. The user should has the option to run the program with the time flag X. X being the amount of time the user has until the program exits. I got that working but didn't know how to implement that into my main while continuing the main program.

    Might be overthinking it. That being said if you see any recommendations or best practices in my code, please let me know. Want to improve. Thanks!

    ```

    import csv,sys,time,argparse

    data = [] #list container to store the data score = 0

    def getArg(): parser = argparse.ArgumentParser() parser.add_argument("-t","--time",type=int,help="Add a timer to the quiz") parser.add_argument("-r","--rando",help="Randomizes the questions") args = parser.parse_args() return parser

    def Time_Arg(): #function for Time flag args = getArg().parse_args() if args.time: start_time = time.time() while True: current_time=time.time() elapsed_time = current_time - start_time if elapsed_time > args.time: print("Time Is Up") sys.exit()

    if name == 'main': with open('PATH TO CSV') as csv_file: data = list(csv.reader(csv_file)) #reading the csv_file then turning that into a list

     for i in range(len(data)): #iterating the index print("Question,", data[i][0]) #printing the data [i] then the first column [0] Question_input = input("Enter you answer: ") #print("Answer,", data[i][1]) #printing the data [i] then the second column [1] if Question_input == data[i][1]: print ("Correct!", "\n") score += 1 else: print ("Incorrect! Answer is: ", data[i][1],"\n") 

    print("You scored: %d out of " % score, len(data)) #printing the number correct out of length of problems ```

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

    Is there such a thing as a mouse with absolute positioning?

    Posted: 06 Feb 2021 03:35 PM PST

    I know tablets have this sort of functionality where a point on the tablet corresponds with a point on the screen but I'm looking for something like a mouse setup where a point on the mouse mat corresponds with a point on the screen.

    Any ideas?

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

    New to Coding ����‍��

    Posted: 06 Feb 2021 07:05 AM PST

    Hello everyone! I recently started a coding Bootcamp to become a Full Stack Developer. Aside from super basic HTML & CSS knowledge, I have no clue about the rest, I just know I love computers and I'm willing to learn as much as possible. What's your advice for this process? I got a bit overwhelmed after looking for information online as there is a ton, which one works best or results more efficient to me? I don't know. I appreciate any ideas, I'm aware it will be an intense journey but I'm so ready for it.

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

    When using TextPad what does "tool completed with exit code 1" mean?

    Posted: 06 Feb 2021 10:09 AM PST

    I am trying to get a program to compile and run for a class using TextPad and I do not know what the error is. I have copied the program from an example in the text and I do not see any errors and I really need to learn how to do this.

    I NEED HELP

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

    Need help with my python code

    Posted: 06 Feb 2021 04:53 AM PST

    I made a client and server with the socket module and made it so when you type a command at the server end it would execute it on the client end and there would be multiple clients connected at one time and I want the output of the command to go back to the server but only one of the output goes back to the server and the other one gets printed when I run the next command can someone help me, please?

    SERVER:

    ```

    import socket
    import threading

    CLIENTS = {}
    host = "127.0.0.1"
    port = 6969
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((host, port))
    s.listen(5)
    print("Server started")

    def client_cmd(conn):
    while True:
    client_send = input("Command for clients: ").encode("utf-8")
    if not client_send:
    break
    for client in CLIENTS.values():
    client.send(client_send)
    data = conn.recv(2048)
    print(data.decode("utf-8"))

    del CLIENTS[conn.fileno()]

    while True:
    conn, addr = s.accept()
    CLIENTS[conn.fileno()] = conn
    threading.Thread(target=client_cmd, args=(conn,)).start()

    ```

    CLIENT:

    ```

    import socket
    import threading
    import os

    socket = socket.socket()
    host = '127.0.0.1'
    port = 6969
    try:
    socket.connect((host, port))
    print("Connected to the server")
    except:
    print("There was an error connecting to the server please try again")

    def Communication():
    res = socket.recv(1024)
    res = res.decode("utf-8")
    try:
    output = os.popen(res)
    sender = str(socket.getsockname()) + " sent back>> "
    socket.send(sender.encode("utf-8") + output.read().encode("utf-8"))
    print("command executed and sent to server")
    except:
    print("Command not found")
    socket.send("Command not found".encode("utf-8"))

    for _ in range(100):
    threading.Thread(target=Communication).start()

    ```

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

    Web app cooperating with Netflix, HBO, etc.

    Posted: 06 Feb 2021 03:04 AM PST

    Hello,
    I am a beginner level programmer and I am currently working on my app for the Bachelor of Engineering title. My idea was to develop an web app, that will co-exist with different Vod providers like Netflix and HBO. Basically I imagined it to be an simple app with the ability of synchronising played media on different computers. I also wanted to include an easy chat and other social features like adding friends and creating groups.
    My question is: how would you handle the synchronisation problem. I know there is a lot of different apps like Tele Party, but most of them are based on streaming one persons screen to the others. Any ideas how to make the app work with a clock and launching the appropriate apps on the right moment? Maybe you have some technologies to recommend?

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

    Using .htaccess files on disappearing csunix

    Posted: 06 Feb 2021 11:33 AM PST

    Hello, so I am hosting my website on a csunix account and I just finished coding my project. When I go to upload the files to csunix the .htaccess files I was using do transfer over. There is no error saying that they could not be transferred over they just load and then disappear. Was wondering if anyone else has had this problem and knows why it happens and if there is a solution.

    Thanks

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

    Help to star making desktop apps

    Posted: 06 Feb 2021 05:26 AM PST

    Hey, i'm learning C, i know some of the basics, now i want to create desktop apps, i have some ideas of apps that i want to do that would make my life easier and i want to try them (realy basic things like a to-do list for example) but i have no idea where to start, i would realy apreciate if you could reccomend some tutorials or websites that cover the "how to start".

    Thank you

    Sorry for the writing, english is not my first language!

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

    How long would this take?

    Posted: 05 Feb 2021 10:51 PM PST

    For a beginner. How long do you reckon it would take me to familiarize myself with the content required to make this app for my phone.

    I mainly wanna use a joycon to use as a remote micro-controller for my daily habit tracker typa thing. Any advice is much much appreciated, thanks!

    I'm new to reddit posting (was this a sufficient post?)

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

    MySQL syntax error during user creation when there is no apparent error

    Posted: 06 Feb 2021 04:15 AM PST

    Hi guys,

    I'm trying to install Moodle using Ubuntu using the following guide: https://docs.moodle.org/38/en/Step-by-step_Installation_Guide_for_Ubuntu

    I'm currently on step 6 where I have to create a MySQL user with the correct permissions and this is where I'm getting stuck.

    The 1st command - create user 'user1'@'localhost' IDENTIFIED BY 'password1'; works fine

    However the 2nd command -

    GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO user1@localhost IDENTIFIED BY 'password1';

    Returns the error message - ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY 'password1'' at line 1

    The installation manual mentions that this may be a problem so advises me to use - SELECT password('password1'); in order to get a hash value to overcome the problem.

    However instead of giving me a hash value it comes up with the same error of - ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('password1')' at line 1

    I am a beginner to all this so I'd appreciate any responses, thanks in advance!

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

    Simple (web) load testing tools?

    Posted: 06 Feb 2021 03:50 AM PST

    When writing web services, I occasionally want to sanity check that it doesn't break under load - especially when it comes to multiple parallell requests.

    Are there any good FOSS tools out there that allows me to for example call an endpoint with 16 concurrent connections? That preferably comes with a usable cli (e.g. I don't have to write C# or Java to configure it).

    I've tried Locust, but it's overly complicated to configure and more importantly it's way too opaque - I have no idea how many parallell connections are made at any one point, for example. It's also not performant enough (the "caller" reaches its max capacity before the server does), and I had it behaving really weirdly for really slow endpoints (timing out, even if I specified a higher timeout in locust).

    My current workflow is to create a bash script that just runs a curl command in an infinte loop, then I simply start the script multiple times. It's MUCH more performant than locust, but it doesn't enable me to test load under parallell calls.

    TBH, there's no reason this tool couldn't be much more complicated than

    commandname localhost:9000/some-endpoint --num-parallell 16 
    submitted by /u/Ran4
    [link] [comments]

    No comments:

    Post a Comment