• Breaking News

    Thursday, December 3, 2020

    What is the proper way of using constructor? It is a good practice to use conditions, and loop inside a constructor? Ask Programming

    What is the proper way of using constructor? It is a good practice to use conditions, and loop inside a constructor? Ask Programming


    What is the proper way of using constructor? It is a good practice to use conditions, and loop inside a constructor?

    Posted: 03 Dec 2020 10:23 PM PST

    Here's the source code of my prof in Object Oriented Programming (Python). I just want to know if this is a good practice?

    class WordLister: def __init__(self): while True: self.in_put = input('Enter a space-seperated words (or press ENTER key to exit):\n') if self.in_put == '': print('Goodbye!') break self.get_words() self.display_words() def get_words(self): self.words = self.in_put.split(' ') self.words = set(self.words) self.lwords = [] for s in self.words: self.lwords.append(s) self.words = sorted(self.lwords) def display_words(self): print('List of Words:') for w in self.words: print('\t', w) print() 
    submitted by /u/JJ_Balms
    [link] [comments]

    I just heard a shell is an OS (Linux, Windows, Apple, etc) but then someone else said you don't have to run Linux you can run Bash on Linux, what does that mean?

    Posted: 03 Dec 2020 09:33 AM PST

    If Linux is the shell, are they saying you can run a shell in a shell?

    Thank you!

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

    How to solve this partitioning problem using c?

    Posted: 03 Dec 2020 09:12 PM PST

    A natural number that is greater than one can be partitioned as a sum of some prime number(s). Your task is to find out as few primes as possible that sum up to the natural number. If the number of such partitions is more than one, only the partition with the greatest product of those summands is considered.

    Each test case will contains a natural number n, 2 <= n <= 1000000.

    For each input, output a single line that contains the number of summands and also all summands, separated by a space. The summands for each test case should be listed in non-decreasing order.

    Input Output 49 2: 2 47 6 2: 3 3 12 2: 5 7 0 

    I only know to consider 2 summands, 3, 4...(definitely not a correct way)

    #include<stdio.h> int isprime(int n){ int i; if(n==1){ return 0; } for(i=2;i<n;i++){ if(n%i==0){ return 0; } } return 1; } void decompose(int n4){ int i,j,max=0; int l; int temp[l]; for(i=2;i<n4;i++){ if(isprime(i)&&isprime(n4-i)){ if(i*(n4-i)>max){ max=i*(n4-i); temp[0]=i; temp[1]=n4-i; } } } printf("%d %d\n",temp[0],temp[1]); } int main(){ int n4,r4; printf("Enter decompose number n (n<1000000):"); scanf(" %d",&n4); printf("Enter decompose result :2:"); decompose(n4); } 
    submitted by /u/JacksonSteel
    [link] [comments]

    Why joins are impossible in (partitioned/sharded) NoSQL databases?

    Posted: 03 Dec 2020 10:04 PM PST

    Locking memory location using mutex in c++

    Posted: 03 Dec 2020 09:48 PM PST

    I'm learning to use threads in c++. I'm confused about how the mutex here actually locks the location, specifically how WaitForSingleObject() and ReleaseMutex() work to make the sum variable thread safe.

    Could you please help me walk through what happens with the first thread which to hit WaitForSingleObject() and the first one to work past it?

    How does the first thread to finish get past WaitForSingleObject()?

    And how does ReleaseMutex() not release the mutex for all the threads?

    Thanks.

    int array[LOTS_OF_VALUES]; int sum =0; HANDLE sum_mutex; void thread_func(int* array, int start, int end) { int local_sum = 0; for (int I = start; I < end; i++) { local_sum += array[i]; } WaitForSingleObject(sum_mutex, INIFINTE); //lock mutex sum += local_sum; //do operation during locked time ReleaseMutex(sum_mutex); //unlock mutex } void main() { sum_mutex = CreateMutex(NULL, FALSE, NULL); //initialise array with something // make some threads that all run thread_func // (with appropriate start and end indices) // to calculate sum } 
    submitted by /u/chinsalabim
    [link] [comments]

    How much is enough?

    Posted: 03 Dec 2020 04:05 PM PST

    Hi All,

    I'm feeling really overwhelmed with my current situation. I've been trying hard to break into this field, but I just can't seem to figure out how and I'm really beginning to doubt my capabilities.

    Quick rundown of my credentials and history.

    BS in Materials Physics

    2 Years High School Teacher (school closed pre-covid)

    1 Year Tech Support in a Hospital Lab.

    Went to a Coding Bootcamp before I started working in the hospital lab and learned Swift. I had to get a job local to me for family reasons, and there wasn't anything local for mobile development. I did put one app on the app store.

    With the help of a distant colleague, I started learning web development. Rails backend, ruby front end, but I'm not naturally coding in these languages yet. Since then, I've purchased around 13 courses on Udemy to pursue in the very little free time I have.

    I have swift decently well down I think, and I've some Python from my undergrad. I've since been learning HTML, CSS, Ruby, Rails, JS, JQuery, React, Vue and Angular, etc and I have classes and UI/UX and C programming and Kotlin as well to round off mobile development for me. Most of these I'm very much a novice with.

    With Covid going on, the laboratory is frankly overworked and understaffed and it's begun to affect my mental health (and everyone else whose working there, it's kind of a mess. Way waaaaay too much work for how many people are currently employed there). I want to move on from this position and finally into a position I can turn into my career. How much do I need to know and be able to do in order to be successful in a programming position? I don't want to be a burden on a place that employees me, but I am getting kind of antsy in this position.

    Thank you for your help!

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

    Angular: TypeError: this._ngZone is undefined

    Posted: 03 Dec 2020 02:37 PM PST

    Hi all,

    I've been learning/working with Angular for a personal project, and I've run into an error that I can't find a solution to.

    You can see my full repo here. It's relatively small, it's only got one real page so far. I did my initial setup via angular's CLI, and haven't touched package.json at all.

    The issue comes in the MainNavComponent.html at line 2, according to my browser's console. The error is as follows:

    TypeError: this._ngZone is undefined

    This is weird, because I don't call ngZone anywhere in my code, let alone in the main nav component. The only thing that I can think of is that in the MainNav component, I do set up an isHandset method which requires a BreakpointObserver. Looking at BreakpointObserver, it looks like it may use ngZone.

    This error happens before ANYTHING else, so the page never even loads. The whole webpage is, currently, completely broken because of it.

    Has anyone ever encountered this? I've deleted my ngModules folder and reinstalled several times now. I've tried doing npm update --all to see if it's a version issue. Nothing has worked so far.

    I'm really confused as to how this even happened- this code was working just fine literally a week ago (last time I made any changes). I didn't change anything about my environment or the code between last week and today, I'm at a loss as to how it managed to break itself.

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

    Remote programmer year end gift?

    Posted: 03 Dec 2020 05:52 PM PST

    I lead a team of six programmers who usually work in the office and have been remote since March due to the pandemic. Usually at the end of the year, we go out for dinner and video games my treat, plus a bottle of something nice for each of them. Looking for remote gift ideas besides something lame like a generic gift card. I thought of shipping them something but don't have their home addresses, and don't want to invade their privacy. What would you want if you had a choice?

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

    [Question/C++] Optimization of processing of vector of objects

    Posted: 03 Dec 2020 04:53 PM PST

    Hello guys,
    The general part of my program is a loop.

    I have a bunch of objects and all of them are inheritors from BaseObject with virtual function Process(). So I am going through the vector of these objects and call Process() for each of them.

    Another thing is that these objects form a chain so I need to process them one by one or data will be broken. It is not a chain line since some objects are inputs for a few of others. It looks more like a tree. Sometimes I have a branch that will merge with chain back again. I try to say that conveyor is not an option.

    And this loop has really bad performance.

    So my question to you: is it possible to make the processing faster? Maybe I should leave the loop alone and go to the optimization of each specific object?

    The processing of each object has some general view: get inputs (a different number for each), do some math with inputs, assign the result to a "value" member. All objects can be looked like some "value" that can be used as inputs for other objects.

    Please share any ideas with me, even crazy ones.

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

    Python N largest key values in list of dictionary objects

    Posted: 03 Dec 2020 04:43 PM PST

    In python 3 you are given a list of dictionary items i.e. [{...},{...},...]

    each dictionary item have identical keys and one key is an integer field

    Using only built-in modules and no external packages, how do you find the top N number of items in the dictionary list which have the largest integers in their key value field?

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

    apache config is not my strong suite

    Posted: 03 Dec 2020 03:36 PM PST

    not sure if this is actually an apache issue or config issue or possibly just me.

    i have a setup with a server which is behind a load balancer.

    the server has apache 2.4.6 and running

    os: Red Hat Enterprise Linux Server release 7.1 (Maipo)

    apache has a bunch of defined urls which are then going to a backend which is written in nodejs

    and the issue is when uploading "larger" files (20mb+), funny enough this doesn't occur on my test server which is essentially the same in everyway just with no load.

    i get the following error.

    ## error

    Bad Gateway The proxy server received an invalid response from an upstream server.

    [proxy:error] [pid xxx] (32)Broken pipe: [client xxx] xx: pass request body failed to 127.0.0.1:3000 (127.0.0.1), referer: https://website.com/ [proxy_http:error] [pid xxx] [client xxx] xx: pass request body failed to 127.0.0.1:3000 (127.0.0.1) from xxx (), referer: https://website.com/ 

    ### my config

    ServerTokens ProductOnly ServerSignature Off <IfModule security2_module> SecRuleEngine on SecServerSignature " " </IfModule> TraceEnable Off Include /path/ip.conf <VirtualHost ${internalIp}:443> ServerName website.com ServerAdmin website@web.com LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy SetEnvIf Request_URI "^" no_forwarded SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded # html, logs DocumentRoot "/path/new" ErrorLog "|/sbin/rotatelogs -l /path/apache_error_%Y.%m.%d.log 86400" CustomLog "|/sbin/rotatelogs -l /path/apache_access_%Y.%m.%d.log 86400" proxy env=forwarded CustomLog "|/sbin/rotatelogs -l /path/apache_access_%Y.%m.%d.log 86400" combined env=no_forwarded # configure ssl TLSv1.2 SSLEngine On SSLProtocol ALL -SSLv2 -SSLv3 -TLSv1 SSLHonorCipherOrder On SSLCipherSuite ALL # server certificate SSLCertificateFile "/path/website.cer" SSLCertificateKeyFile "/path/website.key" SSLCACertificateFile "/path/website.pem" # headers Header always unset Server Header always unset X-Powered-By Header add Strict-Transport-Security "max-age=31536000000;includeSubDomains" Header edit Set-Cookie "(?i)^((?:(?!;\s?secure).)+)$" "$1; secure" Header always append X-Frame-Options DENY # i guess the issue lies somewhere here? <Location "/api/"> <LimitExcept POST GET PUT DELETE OPTIONS PATCH> Deny from all </LimitExcept> SetEnvIf Request_URI .* proxy-scgi-pathinfo SetEnvIf Authorization "(.*)" Authorization=$1 SetEnvIf Content-Type "(.*)" CONTENT_TYPE=$1 ProxyPass http://127.0.0.1:3000/ ProxyPassReverse http://127.0.0.1:3000/ </Location> </VirtualHost> 
    submitted by /u/disrespected_dev
    [link] [comments]

    Need Data Compression Project Ideas

    Posted: 03 Dec 2020 02:23 AM PST

    Hi. So in our Data structure course we picked the data compression project and unforunately our proposal was reject and my group was asked to come up with more feature in our data compression project. We are already doing hybrid text based compression (lzw + huffman) but what other features can I add to the project to make our course professor approve it? :)

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

    What language would be most optimized for creating and saving randomly generated mazes?

    Posted: 03 Dec 2020 02:20 PM PST

    I'm generally new to programming (have only taken one class in c++ ages ago) and I'm working on a project that requires generating a random maze, then exporting it and its solution as a pdf or some other vector file. Is there a programming language that is better suited for this, or does it not matter beyond its ease-of-use?

    Edit before I get called out: I did a better google search and am currently learning about Prim's algorithm and other maze generators. Still overwhelmed by options, though.

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

    Python graphing from an excel file

    Posted: 03 Dec 2020 01:57 PM PST

    Hey im having a bit of troubles graphing cause i need to create the code so it only graphs one specific name but if i put the other names it will also graph it. It is line graphs

    Implement a Python function (called grafTemps) that allows, given the name of a file like the previous one and a place, draw the graphic corresponding to the evolution of the maximum temperatures throughout the years present in the file. For example, for the pordata2.csv file provided, the call grafTemps ('pordata2.csv', 'Braganca') must produce the following graphic.

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

    Absolute noob looking for a script/program that pipes certain text from a PDF into a pre-exisiting Word file

    Posted: 03 Dec 2020 01:51 PM PST

    Hi guys,

    I am an absolute noob but I'm hoping that you might have a tip for me on where I should start looking, or what keywords I need, to find a program. I feel like it might already exist in some way or shape, but I just can't find it. I was hoping I could find a little program / script that I can load a PDF into, that can look for text in a certain table cell, and pipe them into an already existing text.

    Reason asking is that part of my job is taking information out of standardized PDF's and enter it into a Word document, and it's doing my head in having to do this by hand every day.

    If anyone has heard of something that might resemble this, please do let me know. And I apologize if this isn't the right forum to be asking this in!

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

    Language choice in regards to others?

    Posted: 03 Dec 2020 01:40 PM PST

    Hello! I'm currently in school for cybersecurity and wanted to self-teach some programming languages on the side. Since Python is a pretty well-rounded language and is used often with cybersecurity tools, I figured it's a near necessity at this point to have it under my belt. With that being said, I feel a low level language would be helpful as well. I would want to be able to understand and reverse engineer malwares so I plan on also learning C and delving into Assembly as well.

    The crossroad I'm stuck at is the worth behind learning C++. Would it be helpful to learn it past basic syntax when I have Python or C at my disposal for Higher and Lower level language uses respectively? I also need to be comfortable with Java and HTML so if C++ wouldn't be a necessity it would be a big time saver.

    Thank you in advance!

    TL;DR - if C and Python: C++?

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

    Programming with Bash on linux

    Posted: 03 Dec 2020 01:31 PM PST

    Hello, new to bash on linux.

    Small question,

    · If the number entered is between 100 and 500, your script should print out the "X" character as many times as the number entered.

    If I was to make a for loop with this script, how can I reprint out a variable X amount of times from user input within a for loop?

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

    [Software Development] Looking for a mentor

    Posted: 03 Dec 2020 06:08 AM PST

    Hello! :)I'm looking for someone who would be willing to mentor me a little bit and answer some question along the way. My preferred language would be java (but would be open for learning new languages)

    I have an OK grasp of OOP and Algorithms/Data Structures.

    I'm also interested in Machine Learning (currently working through sentdex neural networks from scratch).

    Just reply to this post or write me a PM :)

    Thanks in advance!

    (I could teach you german, danish or maybe even guitar in return)

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

    How can add image background on Dart splash screen?

    Posted: 03 Dec 2020 12:02 PM PST

    There is my code from widget which has the content of splash screen.

    u/override
    Widget build(BuildContext context) {
    return Scaffold(
    backgroundColor: Colors.indigo[300],
    body: Center(
    child: Text(yourList[randomIndex],
    style: TextStyle(
    fontSize: 25,
    )),
    ),
    );
    }

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

    Homework help C language

    Posted: 03 Dec 2020 05:48 AM PST

    Hello programmers, first of all i'd like to thank those who responded to my previous post and helped me a lot but i'm gonna get straight to the point. I have a homework, a guessing game involving while loops so basically the game will keep asking you to guess the number until you get it right. The program works fine, however the input of the user will be taken as an integer, and when i put a decimal number the program prints what's inside the while loop infinitely. How do i prevent this from happening? Is there a way so that the scanf function only reads the whole number and not include the decimals after it? Thank you! sorry for bad english 1st year student here :D

    wear a mask, wash your hands.

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

    Flutter or Unity for a simple mobile app?

    Posted: 03 Dec 2020 11:34 AM PST

    I've made small puzzle-type games on the desktop before in VB and C#, but this will be my first mobile game. It will be about as simple as Checkers. Can you please tell me the pros and cons of Flutter vs. Unity for this level of app? I've never used either. Thanks in advance.

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

    Can someone help verify if my Dataframe solution is correct?

    Posted: 03 Dec 2020 11:31 AM PST

    Hello,

    I have created a csv of data with the following columns: (1) app_key (2) churn, (3)tenure

    https://i.stack.imgur.com/NAlFF.png

    I have performed the following code in order to drop app_key and churn from my data so that I can run an XGboost model

    test_data = pd.read_csv('/Users/lawrence/Downloads/CHS_August_v4.csv') test_data_ready = test_data.drop(labels = ["Churn", "app_key"],axis = 1) 

    I dropped the app_key column so that I could perform an XGBoost operation on the data set. Given that the app_key field is just a customer key, I needed to remove that in order to run XGBoost operation. You can see the XGBoost operaton below.

    test_model = xgb_model.predict_proba(test_data_ready)[:, 1] explainer = shap.TreeExplainer(xgb_model) shap_values = explainer.shap_values(test_data_ready) shap_output = (pd.DataFrame(data=shap_values, columns=test_data_ready.columns)) 

    Shap_output is a dataframe with several columns of data that represent coefficients of each feature. The problem with this output is that it only gives me the coefficient without any customer key that I can use to connect the coefficients with. The rows are listed by numbers (0), (1), (2), etc..

    I would like to produce a final output that contains app_key with the corresponding coefficients that have been output from shap_output so I can easily lookup which customers have low coefficients.

    I attempted to do this by adding the dataframe of my original csv (test_data) before dropping the values with my new output, but I'm unsure if this is the correct approach. My main concern is that the rows may not align since I'm unsure if there's any unique sorting. I'm unaware of how to check if sorting may be happening as well. below is the code I used to join my shap_output with my app_key

    shap_output['app_key'] = test_data['app_key'] 

    Can someone please let me know if this approach is the best way to ensure that I end up with one output that has the app_key and the corresponding outputs from shap_values? Or is there a better way to connect my app_key label with the corresponding coefficient?

    Thank you so much!

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

    need help for java programming

    Posted: 03 Dec 2020 04:59 AM PST

    can anyone help me to get the output like this ? i tried use for loop and failed to get same output everytime

    Enter an integer between 1 and 20: 8

    1 2 3 4 5 6 7 8

    2 7

    3 6

    4 5

    5 4

    6 3

    7 2

    8 7 6 5 4 3 2 1

    its should be like a box

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

    Is there a seemless way to program Arduino using Python code?

    Posted: 03 Dec 2020 10:53 AM PST

    I tried once before but got stuck at one point. This was years ago though. Has anything come out to make the process easier?

    Thanks!

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

    Exiftool and batch renaming/metadata, please help

    Posted: 03 Dec 2020 10:48 AM PST

    Hi,

    I work in digital preservation and our institution is currently in the process of migrating legacy data to a new digital preservation platform. The new platform is highly automated but is dependent on a very specific file naming convention. Because of the nature and use of our content, it is very important to retain the "current" file name in the embedded metadata. I say "current" because the file has already been renamed once from the raw file name at time of digitization. Basically, I need the "current" filename to be saved in the metadata, instead of the original "raw" name during a batch rename.


    Example:

    Raw file name: 0001.CR2

    Current file name: bx1_fl2_03.tif (this needs to get added to metadata)

    New file name: refid_NNNNN.tif (changing the file name to this)

    refid- unique ID

    NNNNN- five digit, padded, sequential number


    I have looked into Adobe Bridge's Batch Rename Tool and the "Preserve current file name in XMP metadata" but all I can find after the rename is "Raw File Name: 0001.CR2" in the metadata.

    I have also looked into using exiftool, but I admit I have only ever used this to view metadata for a given file, not write a new file name. Everything I have found so far says that it can be done, but I am having trouble figuring out how to do it (and in a batch function).

    Any help you can give is much appreciated!!

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

    No comments:

    Post a Comment