• Breaking News

    Friday, February 5, 2021

    Do you also get into the programming zone? Ask Programming

    Do you also get into the programming zone? Ask Programming


    Do you also get into the programming zone?

    Posted: 05 Feb 2021 04:59 AM PST

    Since the title doesn't exactly describe what I mean, let me explain:

    So when I listen to electro music via headphones and drink coffee, I get into a tunnel vision where I ignore all other Input from the outside and focus only on my programming task on my screen. I go into a trance mode where I see/imagine all the logic of the Programm structure with mental eye before I proceed to programm perfect code, that fulfills the current task and is bugfree. This mode/zone continues for like 10 hours straight after which I have completed a workload originally intended for several weeks and after I then finnaly get up and notice that I am dehydrated and my blood sugar level is running close to null.

    Anyone else experiencing what I described?

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

    Whats the best free programing tool?

    Posted: 05 Feb 2021 09:32 PM PST

    Hello,

    I am a first year IT student at college. I came up with what i think is a neat idea for a computer program. I was wandering what the best free program is to use to develop my idea ?

    (this is one of my first times actually using reddit so if im doing it incorrectly i apologize )

    Thanks!

    submitted by /u/Top-Protection-9593
    [link] [comments]

    Why use recursion over iteration?

    Posted: 05 Feb 2021 12:58 PM PST

    Basically the title, but I do already understand that it's normally less lines of code which can also means it's less prone to errors.

    However with that in mind, I feel like to instinctively think of a recursive solution is VERY hard for me to do.

    Second question, have any of the full time devs on here actually used a recursive solution for something on the job and can you explain that.

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

    Why is accessing some random element near the start of an array FASTER than accessing a random element near the end?

    Posted: 05 Feb 2021 09:57 PM PST

    I know they are both O(1) complexity, i'm talking at the hardware level here.

    I know the difference is also very, very, very small.

    Just recently I was doing a leetcode challenge one of which was a solution where lots of random access is done near the end of a 2D array. I found doing the exact same solution except from the front was ~10-20 ms faster and i'm talking consistently faster. This was in C++ with vectors

    I then setup a test in python, and initialised an array of size 1 million, with random elements. I timed random element acccess near both the front and back, and the front of the array consistently produced faster results. I made sure the access was random to eliminate the compilers ability to optimise via caching etc.

    Why would this be? I have always had the assumption accessing anywhere in memory should be roughly consistent.

    Thanks for any input. Happy to share code if requested.

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

    I keep googling things I just learned about in class, is this fine?

    Posted: 05 Feb 2021 03:15 PM PST

    Im in a python class (but I don't think the language matters for this question)

    I keep getting told a lot of the time people look up syntax, and the goal isn't to memorize syntax, and Im mostly sure this is just that.

    Like right now im looking up the syntax for checking how to check if a number is in a list.

    Im just making sure what Im doing is fine, its not against any rules (Like im not taking a test that says no using google) so its definently not wrong, but Im just making sure its not harming me unknowingly

    thanks

    submitted by /u/Mission-Guard5348
    [link] [comments]

    How do I perform mathematical operations on numbers within a string and return the same string but with the updated numbers in Java?

    Posted: 05 Feb 2021 06:32 PM PST

    For instance, I have the following string: "I took 15 credits last semester and 18 this semester." I want to add 3 to each number in this string and return the following string: "I took 18 credits last semester and 21 this semester."

    I also have another string that uses commas: "I went on 12 walks last week, but only 10 this week." I want to add 2 to these numbers so the string is returned as: "I went on 14 walks last week, but only 12 this week."

    I've tried using Matcher and Pattern, StringBuilder, etc. but nothing has been working for me. Any help would be appreciated.

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

    Front-end built once, deployed on both mobile and web. Is it possible?

    Posted: 05 Feb 2021 12:12 PM PST

    Hi,

    I'm the founder of a small company that puts out tech products.

    Although not technical myself, one of the many roles that my small company needs me to fill in is the CTO role. I don't code, rather come from a design background.

    We currently have multiple products, but the relevant ones for my question are:

    • A mobile app made in React Native, published on iOS and Android
    • A custom-built eCommerce built with CorePHP and Bootstrap for front-end
    • A custom-built app made with Django and React for front-end

    However, the mobile app will now need elements from the other two apps. I suppose that the FE (front-end) dev of the Mobile App will have to replicate:

    1. the FE work the Bootstrap developer has built so far
    2. the FE work the React developer has built so far

    But then it's a cat-mouse game, where every single change I make on the React app will have to be replicated on the mobile app. And vice versa.

    Is there any tech stack I can choose where we can either work once and use the built things twice? Or at least get to something that's as close as possible to this?

    Surely the bigger tech companies must've done something about it — although when I look at the Amazon App, I can sense that it's clearly differently built from their web browser app.

    P.S: Since we're here, may I also ask: any fantastic disadvantages from being 'fragmented' across different tech stacks with different apps? FWIW all these apps will be served from the saved DB and back-end

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

    how do I remove the comma from the last number in the array?

    Posted: 05 Feb 2021 03:51 PM PST

    public static void main(String[] args) throws FileNotFoundException{

    Scanner scan = new Scanner(new java.io.File("numbers.text"));

    double[] arr = new double[scan.nextInt()];

    for (int i = 0; i < arr.length; i++)

    arr[i] = scan.nextDouble();

    int min = arrMin(arr);

    int max = arrMax(arr);

    System.out.print("The array : {");

    for (int i = 0; i < arr.length-1; i++) {

    System.out.print(arr[i] + ",");

    }

    System.out.println("} contains " + arr.length + " elements");

    int first = 0, last = arr.length-1;

    int mid = (last-first)/2;

    System.out.println("The first element of the array is " + arr[first]);

    System.out.println("The last element of the array is " + arr[last] + " and is at position " + last);

    System.out.println("The middle element of the array is " + arr[mid] + " and is at position " + mid);

    System.out.println("The largest element of the array is " + arr[max] + " and is at position " + max);

    System.out.println("The smallest element of the array is " + arr[min] + " and is at position " + min);

    }

    }

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

    I need to interview a programmer for an assignment

    Posted: 05 Feb 2021 09:38 AM PST

    Hello there. I'm learning software development and one of my homework assignments is interviewing a programmer/software developer (specific career doesn't matter as long as it's related to programming). I'm sorry for any grammatical errors or vague questions. English isn't my native language.

    I want to get this over with as quickly as possible so I'll just drop the questions here if no-one minds...

    1. Can you tell a little about yourself?

    2. What got you interested in programming?

    3. Do you enjoy your work, or do you find it tedious?

    4. What do you like the most about programming?

    5. What do you like the least about programming?

    6. What is your greatest programming-related achievement?

    7. Do you make your own programs/projects outside of work?

    8. Which personality traits/characteristics are most useful for programming?

    9. Which programming languages are an absolute necessity?

    10. What advice would you give to a someone starting out in software development?

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

    Where do you do your code reviewing process?

    Posted: 05 Feb 2021 04:47 AM PST

    I usually coding c/python on vscode and use gitlab for version control and I found gitlab mr pretty annoying for code review.

    So I am trying to find a better way for it🙂

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

    Comparing function's growth rates

    Posted: 05 Feb 2021 01:02 PM PST

    Hello,

    I've been stuck on one of my comp sci assignments for a long time now because I simply think that its wrong.

    It wants me to order some functions from lowest growth rate to highest growth rate.

    I have them as so,

    1.) sqrt(n)*log(n)

    2.) 9n*log(n)

    3.) 7*sqrt(n)

    4.) n^4

    5.) 2^sqrt(n)

    6.) 2^(n^2)

    It says I'm wrong but I literally don't believe it. I need someone on here to tell me I'm wrong and perhaps where I'm going wrong in my thinking.

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

    Java Inheritance question

    Posted: 05 Feb 2021 11:06 AM PST

    If Dog extends Mammal, and Mammal extends Animal (superclass), is Dog considered a subclass of Animal in addition to being a subclass of Mammal?

    In other words, are subclasses of a subclass classified as a subclass of the parent class?

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

    Windows app development

    Posted: 05 Feb 2021 10:47 AM PST

    Hi, most of my experience is concentrated in specific platform tooling (shell, Perl, pho, python) and some backend development (python and php mostly).

    I've made the switch to windows 10 sometimes mid last year and was curious what folks in here thought about windows 10 development. I figure some c# c++ and dot.net were where it was at.

    If I'm wrong tell me what languages I should be looking at. My real question here is: how is the platform for developing applications? I get web and mobile is all the rage at this point but I have some real interest in designing some applications with alternative user interfaces that are more intuitive.

    I'm wel aware there is quite a gap between my experience and what I'll need to learn to get there. I'm willing to put the time and work in.

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

    How can I split a numberic array into multiple arrays based on their sum?

    Posted: 05 Feb 2021 10:42 AM PST

    Here's my problem:

    I have a numeric array that contains more or less random numbers.

    var arr = [226,380,283,283,189,212,189,64,189];

    and a variable

    var x = 3; (could also be 2 or 4, doesn't matter)

    It determines the amount of arrays I want. So like this for example:

    [226,380,283] [283,189,212] [189,64,189]

    However, I don't just want to split the array, I want to sort it in a very specific way. I want the sum of each array to be as close to the other ones as possible.

    Example:

    This would be a bad output:

    [226,380,283] (sum = 889)

    [283,189,212] (sum = 684)

    [189,64,189] (sum = 442)

    The values are quite different from each other.

    This output would be much better (see how the values are really close to one another):

    [380,283] (sum = 663)

    [283,189,212] (sum = 684)

    [226,189,64,189] (sum = 668)

    Any ideas for a program logic/an algorithm that would be able to deal with this problem as efficiently as possible? Btw; I'm using JavaScript here, but I care more about the idea than the actual programming.

    PS: It doesn't matter if the output is different each time or consistent.

    PPS: Oh I forgot to mention, that I don't want to do that. I want the values in each sub array to be pretty random. Like, I don't want an array with big values and one with small ones. I want a more or less even or at least random distribution in each sub array.

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

    How is python/tkinter using less memory than c/gtk on the Rpi3 using freebsd?

    Posted: 05 Feb 2021 06:30 AM PST

    I'm practicing programming with guis on hardware with more limited resources. Since I've always felt that memory was my largest constraint when programming on the PI, I wanted to establish a baseline for how much I would have after accounting for the background processes. I fired up top and checked the "RES" column. My top 3 biggest sinks are

    lumina-desktop 130M xorg 72M emacs (personal config) 61M 

    In all memory usage is 180M Active, 23M Inact, and 340M free. I figured depending on the os, and desktop environment, people probably have between 200 and 250M free so I would want to keep my programs to around 150+- a few mb. I'm most familiar in writing guis in Racket and Python, so first I wanted to check how much resources each interpreter used on their own.

    racket interpreter 64M python interpreter 19M 

    Then I wrote a program to display a button using python/tkinter, racket/gui/, and c/gtk3.0.

    python/tk 21M racket/gui 140M c/gtk 26M 

    What is surprising to me was how memory efficient python was. It even used less memory than straight C + gtk. I recognize that this isn't scientific, and that there is probably a lot more things going on here, so what do y'all thing is going on?

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

    Mapscript error in Python-flask inside Docker

    Posted: 05 Feb 2021 09:12 AM PST

    I have a simple flask app and I am trying to run in Docker

    import mapscript

    from flask import Flask

    import json

    app = Flask(__name__)

    port = 5000

    u/app.route("/hello")

    def geocoder():

    epsg = mapscript.pointObj(1, 1)

    return json.dumps(epsg)

    test()

    if __name__ == '__main__':

    app.run(host="0.0.0.0", port=port)

    \```

    My Dockerfile is:

    FROM python

    WORKDIR /opt/demo/

    COPY /app .

    RUN pip install -r requirements.txt

    ENTRYPOINT python test.py

    But I get the following error when I run docker run -p 5000:5000 test:latest:

    Traceback (most recent call last):

    File "/opt/demo/test.py", line 1, in <module>

    import mapscript

    File "/usr/local/lib/python3.9/site-packages/mapscript/__init__.py", line 2, in <module>

    from .mapscript import *

    File "/usr/local/lib/python3.9/site-packages/mapscript/mapscript.py", line 13, in <module>

    from . import _mapscript

    ImportError: cannot import name '_mapscript' from partially initialized module 'mapscript' (most likely due to a circular import) (/usr/local/lib/python3.9/site-packages/mapscript/__init__.py)

    ``

    This happens only when I have the Python VENV activated when running outside Docker but I don't know why I am getting this error inside Docker.

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

    Know of any good dashboard apps?

    Posted: 05 Feb 2021 07:40 AM PST

    UPDATE: I found wtfutil which appears to do what I want.

    __________________________________________________________________________

    In order to be more efficient at my development work, I'm looking for a dashboard I can run on a spare low-power system and monitor (such as a R.Pi).

    There are many specific dashboards (e.g. zabbix, github), but I want a single screen for everything so I don't have to round-robin check things all the time or context switch.

    Possible Features

    • Panes
      • Single screen with an arrangement of panes
      • Panes are fixed size. They do not grow as data grows
      • Panes can be custom selected and arranged
      • Configurable refresh rate per pane
    • Can run on Linux (so I can run on a R.Pi)
    • Notices
      • Colors based on criticality: yellow, red, flashing red
      • Alarms: sounds, master indicator
    • Custom pre-built pane library
    • Generic pane types
      • RSS/Atom feed reader
      • Command line output
      • HTML page (perhaps cropped to specific div)

    Unneeded features

    • Graphs or graphics
    • Specific UI type. Terminal, Desktop, or Web UI are ok.
    • Interactivity. Read-only UI is fine. This won't be physically close enough, anyway.
    • Desktop notifications. (see prior bullet)

    Company Panes

    • Server stats: CPU, memory, http status (i.e. [https://](https://)... returns 200)
    • Latest error messages from prod app server logs.
    • Clocks for specific timezones (esp UTC)
    • Github
      • Build status of specific Github Actions CI jobs
      • Stale pull requests for project
      • CI/CD: last production deployment date/time per app

    Personal Panes

    • Next 2 scheduled meetings (from google and OWA)
    • Unread emails from primary inbox (3 max), combined from all accounts
    • Slack: direct messages, specific rooms, mentions (but not @here, @channel)
    • Local Workstation: CPU %, Memory, CPU temp
    • Github
      • CI jobs that failed because of one of my commits
      • notifications
      • open tickets owned my me
      • pull requests: others', yours approved/denied

    Possible simple DIY solution if I can't find anything.

    • Use tiled terminal or tmux to create and arrange panes
    • Bash scripts and CLI tools (e.g. github cli) to run on each pane
    submitted by /u/funbike
    [link] [comments]

    Do all programmers speak English?

    Posted: 05 Feb 2021 01:25 AM PST

    Whatever country I've been to, whatever proficiently in English is normal or not, there's one thing that always seem to be true... If a person works as a programmer, he/she speaks fluent English. Is this because the community internationally is in English and that all (most) programming languages has syntax with English words in them?

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

    Why can't execute the code to the secondary window in javascript?

    Posted: 05 Feb 2021 06:55 AM PST

    let elements; let element_text; let artistname = 'Hans Zimmer'; let spotify_window = window.open('https://open.spotify.com/search/Hans%20Zimmer'); //I thought it's becaue the window hadn't loaded, but it didn't work setTimeout(function () { }, 5000); elements = spotify_window.document.querySelectorAll('._45331a50e3963ecc26575a06f1fd5292-scss._3957b7dd066dbbba6a311b40a427c59f-scss:not(.good-one)'); alert(elements[0]); //always undefine which is wrong for (let element of elements) { element_text = element.innerText; if (element_text == artistname) { element.click(); break; } element.classList.add('good-one'); } 

    the class name isn't wrong

    https://ibb.co/sFTFt81

    Also, if I execute the following code in that tab's console, it worked

    let elements; let element_text; let artistname = 'Hans Zimmer'; elements = document.querySelectorAll('._45331a50e3963ecc26575a06f1fd5292-scss._3957b7dd066dbbba6a311b40a427c59f-scss:not(.good-one)'); alert(elements[0]); //always undefine which is wrong for (let element of elements) { element_text = element.innerText; if (element_text == artistname) { element.click(); break; } element.classList.add('good-one'); } 

    see:

    https://ibb.co/PGn9cG4

    then it clicked and jumped to the page

    https://ibb.co/n6CPmvy

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

    Json deserializing and serializing using Lombok and Jackson

    Posted: 05 Feb 2021 06:00 AM PST

    I have 2 get Api calls which should return me a Json object { "entityId" : "123", ... } and [ { ...}, {...}, ... ]

    What did my pojos look like? Currently, I have an item class for the base object and for the response a list of Items. But I am getting a cannot deserialize from json array to collecting list error. Not sure if I unbeatable how Jackson ( with Lombok) work.

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

    Get first two digits of a number in Python without slicing

    Posted: 04 Feb 2021 11:46 PM PST

    I know that to get the first two digits of a number in Python, you can simply use slicing. However, I am on the staff for an intro CS course where we haven't taught slicing to students, and instead they have to use math operators and while statements to do so. I want to write a function that gets the first two digits of a number, where if the number is less than 10 it returns 0, number , and I have this so far:

    def digits(num): if num < 10: return 0, num digit_x, digit_y = 0, 0 while num > 0: digit_y = digit_x digit_x = num % 10 num //= 10 return digit_x, digit_y 

    Is there a way to remove the first if block entirely to make this code even shorter and more elegant?

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

    [PHP][JQUERY] How do deal with this security exploit in my system ?

    Posted: 04 Feb 2021 11:32 PM PST

    My site/app is running on a local machine at work, so the threat isn't huge as we are a total of 10 users but knowing that such an exploit exists still makes me uncomfortable and I want to solve it once and for all.

    Once a user logs in, his clearance level is queried and stored in a session variable $_SESSION["clearance"];

    In all pages I have a page included that contains all possible actions and who can perform them in the form:

    • $allowed['insert']['table_id_1']=[2,3,5];
    • $allowed['update]['table_id_1']['column_1']=[2,3];
    • $allowed['update]['table_id_2']['column_1']=[5];

    I use inarray to check if a user's clearance is included in the action's array. So from above, user with clearance [5] can only insert into table_1 but not modify column_1. He can update a column with the same name in a different table, "table_id_2".

    Problem is, the table DOM id #table_id_1 is sent using AJAX along with the new value to update, column name,....to a page that handles the UPDATE for all of my tables. Currently, what's stopping user with clearance [5] from changing the dom id of "table_id_1" or change it directly in the ajax call to "table_id_2" (in page source) and thereby be granted access to update a column having the same name "column_1" in "table_id_1" which he does not have access to?

    Sometimes, the same page can include two php tables, both querying data from the same database table, but one user could update column in one table but not the other...user could simply swap the table id's in the DOM.

    And thank you in advance.

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

    No comments:

    Post a Comment