• Breaking News

    Sunday, June 20, 2021

    Programmers who can think recursively, can you share a problem or two that you think is best solved with recursion? Ask Programming

    Programmers who can think recursively, can you share a problem or two that you think is best solved with recursion? Ask Programming


    Programmers who can think recursively, can you share a problem or two that you think is best solved with recursion?

    Posted: 19 Jun 2021 04:47 PM PDT

    I have been doing live coding interviews lately as I near the end of a few job prospects. I have shocked and amused a few interviewers when I came up with a non recursive solution to some of their problems, like flattening an arbitrarily nested array, traversing a node tree for various reasons, or computing paths for A*.

    I come here seeking problems that seem easier or intended for recursive solutions to either help wrap my brain around it. It's also reddit so maybe some amusing discussion will also follow :)

    --edit: I'm going to include an example here since I realize this could use more context. Flattening an arbitrarily nested array - have any of you seen this as a job application task? Here's the iterative version. It's baby's first ruby script so please pay no mind to the obvious lack of idioms, architecture, etc. The flatten_array function is where the magic happens :)

    --edit2: here's a list of things suggested so far that I will try to keep updated. Thanks for all of the suggestions!

    minesweeper - done recently for a coding interview

    node/folder traversal - done recently for a coding interview

    ackermann functions

    generation of a maze

    tower of hanoi

    sudoku

    merge sort

    binary tree inversion

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

    If I am using WSL2 with Windows as a development environment, then am I missing anything by not switching to complete Linux (Ubuntu) as a dev environment?

    Posted: 19 Jun 2021 07:37 AM PDT

    For the sake of argument, assume I need Windows OS and I cannot switch. I just want to know information.

    As someone who has never used Ubuntu as a dev environment before, I am under an impression that when using the WSL2 terminal, all the good things of Linux like package managers is covered.

    Then, are there any feature or dev tools that are only possible via a complete Linux (Ubuntu) environment, and using them feature with WSL2 with Windows would be a hindrance or Not at all possible?

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

    Where can the "new" keyword in JAVA be used?

    Posted: 19 Jun 2021 10:05 PM PDT

    Currently learning java and I have seen over time the keyword "new" used like the example below. What I want to know is how does it work in this case?

     LinkedList<Customer> queue = new LinkedList(); queue.add(new Customer("Sally")); queue.add(new Customer("Ben")); queue.add(new Customer("Emma")); queue.add(new Customer("Fred")); 

    I understand that the keyword "new" is used to instantiate a object reference to a class. From there we are able to access methods attributes and other things from within that class. But I can't understand what the above code is doing and why we are instantiate again? Also the word Customer is a class. New to collection's also how can a class be a field for a Linked List.

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

    What's the best Company you have ever worked for and why?

    Posted: 19 Jun 2021 09:52 AM PDT

    In the curses library, how in the world do you check for specific letter key inputs?

    Posted: 19 Jun 2021 05:10 PM PDT

    In the curses library, I can detect arrow keys but can't figure out from Google how to detect for letter key inputs.

    Does anyone know where I might have better luck finding his out?

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

    question win32 api

    Posted: 19 Jun 2021 05:09 PM PDT

    Hi, so I play this roblox idle farming game. I thought having multiple instances of the game might give me more chances of getting items. I found a way through installing process explorer and close thread roblox's event called "singleton. I want to automate it for other people to use without process explorer. I thought I can use pywin32 for it. But the thing is I am unfamiliar with these things, like the terms "handle" "Pid" "events". I tried microsoft's docs on WIN32API but it has its difference and the example used in its docs is c++ while I only know python. Any guide/tutorial/docs to make sense of these things?

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

    Which app do you use to draw flowcharts?

    Posted: 19 Jun 2021 12:58 PM PDT

    When working on personal projects I often desire an app that should allow me to map out the flow of the program, so coding it would be easier.

    Any specific flowchart apps that many programmers use?

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

    Why need Netcat when I already have the WireShark?

    Posted: 19 Jun 2021 08:16 PM PDT

    https://imgur.com/a/2pQW2kW

    Practical Malware Analysis: The Hands-on Guide to Dissecting Malicious Software

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

    Best technology / solutions for document management automation?

    Posted: 19 Jun 2021 08:15 PM PDT

    I am looking to build a script that can automate information on .csv files and then produce a new CSV to be imported into scheduling software.

    The software will be provided a csv file containing links to hosted content and organised by category such as cats, dogs and mice.

    The software will contain a database of .csv files that have other information organised by category.

    For Example:

    1. Post titles for cats, dogs and mice.
    2. Blog destinations for each category such as Steves Cat Blog, Stacey's Dog Blog
    3. Social media posting accounts organised by category

    The script will then be provided a set of instructions.

    1. Total no. of posts
    2. No. of posts per day
    3. No. of posts per account

    The script will then output a CSV file containing the information organized in a format that can be used by the scheduling software.

    Can anyone recommend what the best way to go about this would be from a programming standpoint.

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

    Deleting projects off my local machine

    Posted: 19 Jun 2021 07:09 PM PDT

    I have about three years worth of projects, exercises, tutorials, etc... on my laptop stored in a repo folders. And it's eating up a sizable portion the memory on my comp.

    So my question is, is it common place, or feasible to, just delete all of this stuff off of my local machine as the majority of it is already hosted on GitHub. Can't I just clone a project if I ever want to mess with it again? Does this make sense? Instead of having these projects eating up space on my hard drive can't I just delete them and keep them on GitHub. Sorry if this has been asked before. The answer may be obvious or maybe I'm thinking about this wrong, but I tried to look up the answer and couldn't find anything. Thanks.

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

    Is there a way to have a random bijective map between two integer ranges without having an array of said range?

    Posted: 19 Jun 2021 02:24 PM PDT

    Hi, I think it is worthwhile to give some context to this question. This is being done in Meteor/Apollo/MongoDB/React, but the question is language-agnostic.

    I'm trying to create an endless feed of random user posts without repeats. This is typically done with pagination, but the issue with pagination is that it is returned in a fixed order as it appears in the database. What I am trying to achieve is random pagination.

    So if I have say 100 entries in my database, my current big picture idea is that I generate a random seed on the client upon page load, and send that seed back and forth for pagination, and to have a function which takes in this seed to bijectively map to an entry in the database.

    Here I will illustrate an example. Suppose my database has 1,000 queries (numbered & indexed 1 - 1000 for simplicity). Client A sends seed A along with the offset (0) and limit (10). The limit here will always be constant at 10, and the offset is the only changing value, which is the sum of all previous limits.

    Now, what should happen is I obtain 10 random unique integers in the range [1,1000], based on the seed, offset, and limit. So with typical pagination, I will retrieve the data from indices 1 to 10. But now with this seed, I need to injectively map the numbers [1,10] to a random unique selection of 10 integers within the range [1,1000].

    Next, I retrieve the data at those specific indices in the DB, and send it back to client A. Now, client A scrolls down and hits the trigger to load more, so now client A sends seed A along with an offset (10) and limit (10). With the offset and limit, I have the new unseeded range, [11,20]. And this should map to a random unique selection of 10 integers within the range [1,1000] but NOT map to the integers already mapped to by the first 1-10. This means that I need to have a random bijective mapping between the ranges [1,1000] and [1,1000].

    This looked like it could be solved with the Fisher-Yates shuffle which would basically give me a random permutation, and then I can predictably do this with a seeded Fisher-Yates shuffle. But it's not quite the case because I wish to avoid having to generate this array of [1,1000] on every user query. The range scales based on the number of items and once this number grows large (potentially in the millions, or more), it isn't going to be efficient having to generate it for every user query.

    This is a pretty interesting problem and I'd love to hear some perspectives on this. I must admit that I am trying to push the idea of this having uniqueness as far as I can, but I understand if this is the best that can be done, and then I'll have to compromise on occasional non-uniqueness.

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

    Is it the right way for android/ios app developers to write a server-side in Golang and the front end in Kotlin/swift?

    Posted: 19 Jun 2021 12:26 AM PDT

    I am learning golang and done some projects in it and I am curious about the question that is it possible and the correct way for android or ios developers to write a server-side code in golang and front end in kotlin or swift. I don't have experience in mobile app development but I am curious and want to know if it is possible for two languages to work at the same time.

    May this will help me to shift to mobile app development without thinking that I wasted my time learning golang.

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

    Is 16GB For 4yrs Output Enough Or Too Much?

    Posted: 19 Jun 2021 04:00 PM PDT

    I'm starting my SE degree next week and will be trading my 2015 MacBook Air for something more pawerful.

    I'm starting my SE degree next week and will be trading my 2015 MacBook Air for something more powerful.his sound about right?

    Aside from programming, I'll be using it for streaming, the odd MacOS game and remote learning.

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

    Learn C++ or something else?

    Posted: 19 Jun 2021 11:57 AM PDT

    I've been doing C# and React/Angular since the start of my career. Kind of looking for something to add to my stack.

    Don't have many opportunities for remote working so was considering to learn Python, Go, Ruby or C++?

    C++ seems best for my technical skill set. All others are just another way of selling yourself quicker.

    Also I am in Europe.

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

    [javascript] display error to user with express.js

    Posted: 19 Jun 2021 11:39 AM PDT

    Hi there, I'm a newbie and I'm building a weather app.
    I wanted to throw an error when the user insert a city that doesn't exist or when they send an empty input.
    I have done some researches but I can't seem to find the right answer for me.
    Here is my code:
    (sorry if it's messy)
    `

    const express = require('express');
    const https = require("https");
    const bodyParser = require("body-parser");
    const app = express();
    app.use(bodyParser.urlencoded({extended: true}));
    app.use(express.static('public'));
    app.get("/", function(req, res){
    res.sendFile(__dirname + "/index.html")
    })
    app.post("/", function(req, res){
    const apiKey = "448385fead47b54d9a6b8ef9e045b479";
    const query = req.body.cityName;
    const unit = "metric";
    const url = "https://api.openweathermap.org/data/2.5/weather?q=" + query +"&units="+ unit +"&appid=" + apiKey;
    https.get(url, function(response){
    console.log(response.statusCode);

    response.on("data", function(data){
    const weatherApp = JSON.parse(data);
    const temp = Math.floor(weatherApp.main.temp);
    const description = weatherApp.weather[0].description;
    const icon = weatherApp.weather[0].icon;
    const imgUrl = " http://openweathermap.org/img/wn/" + icon + "@2x.png";
    res.write(`
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Weather App</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" type="text/css" href="/css/style.css">
    <link href="[https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">](https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css%22%C2%A0rel=%22stylesheet%22%C2%A0integrity=%22sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x%22%C2%A0crossorigin=%22anonymous%22%3E)
    <link rel="preconnect" href="[https://fonts.gstatic.com">](https://fonts.gstatic.com%22%3E/)
    <link href="[https://fonts.googleapis.com/css2?family=Lobster&family=Open+Sans&display=swap" rel="stylesheet">](https://fonts.googleapis.com/css2?family=Lobster&family=Open+Sans&display=swap%22%C2%A0rel=%22stylesheet%22%3E)
    </head>
    <body>
    <section id="form" class="position-absolute bottom-0 start-50 translate-middle-x">
    <div class="container form-in-post">
    <form action='/' method='POST'>
    <label for='cityName' class="form-label">Please choose a city</label>
    <input class="form-control" type='text' name='cityName' id='cityName'>
    <button class="btn btn-primary mb-3">Check</button>
    </form>
    </div>
    </section>
    </body>
    </html>`)
    res.write(`
    <section id="weather" class="position-absolute top-0 start-50 translate-middle-x">
    <div class="container text-center">
    <h1 class="cityName"> ${query.toUpperCase()}</h1>
    <h3 class="temp">${temp}°</h3>
    <p>${description}</p>
    <img src = ${imgUrl}>
    </div>
    </section>`);
    res.send();
    })
    });
    });
    app.listen(3000, function(){
    console.log('The server is running on: localhost 3000.');
    });`

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

    Best way to setup and host regular database backups and imports

    Posted: 19 Jun 2021 11:34 AM PDT

    I have 2 psql commands that I want to run once every x days via cron jobs. What's the most efficient way of doing that? Hiring a VM on digital ocean or something similar and setting it up on that?

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

    [REVIEW] A Simple Linux CLI timer based on the Pomodoro Technique

    Posted: 19 Jun 2021 09:40 AM PDT

    Link to the code

    Please review and give me your suggestions..

    Any help would be much appreciated.

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

    How do you make source code save?

    Posted: 19 Jun 2021 09:35 AM PDT

    I want to add the Google Adsense code in between <head> and </head> tags on HTML.

    I am a shit coder so I am unsure of how to save the source code once I have edited it as HTML, and if that is even the right thing to do.

    How do I save source code? or How do I paste a link in between HTML head tags and keep it there?

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

    Goal Tracking System

    Posted: 19 Jun 2021 07:41 AM PDT

    I am asking for advice or feedback about a goal tracking system that I am planning to put together. Please leave comments in the document or on this post.

    Also, if you know of a group/forum that would be a good place to share this, please share it or let me know.

    https://docs.google.com/document/d/1X7ryTaAfBbRTLk5D0Mjbhl_MNK0cFmcJwhWU77TUtsM/edit?usp=sharing

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

    Nodejs use import function without new keyword

    Posted: 19 Jun 2021 07:33 AM PDT

    ``` class Metadata { constructor () {}

    async get(item, delay=0){ //do something } 

    } module.exports = Metadata; in another file i do const metadataService = require('./metadata');

    const myFunc = async () => { const item = await new metadataService().get(...) } ```

    how do I destructure the import so that I dont need to instantiate new every time?
    I want const item = await metadataService.get(...)

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

    What exactly is the problem when a webpage loads but not the thumbnails or the images(or half of them)?

    Posted: 19 Jun 2021 06:57 AM PDT

    This is very annoying, I am guessing the server the thumbnails load from is having issues but when it happens it usually affects many websites so it must be my internet connection? but I thought the internet either works or it does not work like electricity, can it half work?

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

    Is front-end more respected now?

    Posted: 19 Jun 2021 12:04 AM PDT

    I first started learning web dev at age 11 in the 90s and growing up I always heard that front-end wasn't taken as seriously as "real" programming and that if I wanted to pursue a career as a programmer I should learn something like C or Java.

    Even as recently as the last decade I've heard people say things like front-end isn't taken as seriously at places like Google and such.

    Fast-forward to today, it seems like front-end is front and center. I've been self-teaching for a year now and understand a lot of what used to be back-end is now handled client-side and it's such a drastic change from how I always thought of it. I never thought I'd be able to make good money with HTML, CSS, and JavaScript but here we are.

    To those who have been in this field for a while, is front-end still looked down upon in your opinion? Would a front-end dev at Google be taken as seriously as a C or Java dev?

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

    C++ concepts question

    Posted: 19 Jun 2021 05:48 AM PDT

    Reading through cppref on concepts and constraints, under Atomic Constraints I came across this example:

    template<typename T> struct S { constexpr operator bool() const { return true; } }; template<typename T> requires (S<T>{}) void f(T); // #1 void f(int); // #2 void g() { f(0); // error: S<int>{} does not have type bool when checking #1, // even though #2 is a better match } 

    Now I understand that they are trying to show that the temporary object S<T> created in #1 doesn't convert to a bool:

    The type of E after substitution must be exactly bool. No conversion is permitted:

    But the error confuses me. Shouldn't f(0) call #2? It specifically says (just above):

    If the substitution results in an invalid type or expression, the constraint is not satisfied.

    The substitution results in a non-boolean atomic constraint, therefore the constraint is not satisfied, but why does that prevent #2 from being a potential candidate?

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

    Is there still no way of opening a local path in File Explorer from Chrome?

    Posted: 19 Jun 2021 04:44 AM PDT

    Is there no way of opening a local folder such as this in your file explorer:

    C:\Users\me\Desktop\Folder

    Directly through a link in Chrome without having to install extensions? I've tried googling and most responses seems to be many years old. Has Google not added this functionality yet?

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

    No comments:

    Post a Comment