• Breaking News

    Sunday, July 29, 2018

    [JS] Is there a smarter (read less verbose, but still readable and obvious) way to do this object destructuring and comparison? Ask Programming

    [JS] Is there a smarter (read less verbose, but still readable and obvious) way to do this object destructuring and comparison? Ask Programming


    [JS] Is there a smarter (read less verbose, but still readable and obvious) way to do this object destructuring and comparison?

    Posted: 29 Jul 2018 04:49 PM PDT

    Here's the code in question. I need to rip out old and new values from my state and compare to see if their equal.

    A simpler solution would be tracking changes with a flag but I prefer this.

    Any thoughts?

    const { username, description, avatarURL, modifiedUsername, modifiedDescription, modifiedAvatarURL } = this.state const current = { username, description, avatarURL } const modified = { username: modifiedUsername, description: modifiedDescription, avatarURL: modifiedAvatarURL } 
    submitted by /u/halfjew22
    [link] [comments]

    Questions about structuring a Minecraft-like world in javascript/three.js

    Posted: 29 Jul 2018 09:34 PM PDT

    The world is made up of chunks, which in turn are made of blocks (cubelets). Chunks will be stored in a database and loaded at runtime as needed.

    I'm having a hard time deciding on a good way to model chunks and blocks. As of now the chunk data looks like this:

    { x: chunkX, z: chunkZ, blocks: [ {type: BlockTypes.CUBE, position: new Vector3(0, 0, 0), integrity: 10}, {type: BlockTypes.CUBE, position: new Vector3(0, 1, 0), integrity: 10}, {type: BlockTypes.CUBE, position: new Vector3(0, 2, 0), integrity: 10}, // These three blocks represent one column {type: BlockTypes.CUBE, position: new Vector3(1, 0, 0), integrity: 10}, {type: BlockTypes.CUBE, position: new Vector3(1, 1, 0), integrity: 10}, {type: BlockTypes.SLOPE position: new Vector3(1, 2, 0), integrity: 10}, ... ] } 

    After the chunk data is loaded, the chunk mesh is generated by iterating through the blocks and getting the appropriate vertices and positions for each one, finally adding them to a single chunk mesh.

    I lack the programming vocabulary to properly explain the problem, so bear with me if I use the wrong term here. Problem is that the block DATA and the block MESH are not coupled. If I want to pick a particular block, I cast a ray which hits the monolithic chunk mesh and the only useful information I get is the chunk object that I hit and the location of intersection, which I can use to index into the chunk's block data, but it doesn't feel right at all and I want to nail down the foundational structure before I go any further.

    What's a better way to design this? Would it be feasible to store every block as a THREE.Mesh object and to just send the block type when serializing it?

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

    Need to find an app developer

    Posted: 29 Jul 2018 09:14 PM PDT

    I'm looking for an app developer to build an app from my existing website

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

    When I user .map to mmap over a populated array in this.state, why does it return undefined?

    Posted: 29 Jul 2018 08:48 PM PDT

    In my app I have a home component that is rendered after a user logins. In this home component's componentDidMount I fetch the documents associated with the logged in user. The fetch call works and the response is populated with the correct data. I take this data and make a this.setState call, setting the fetched data to this.state.

    In the home components render function I insert JSX that calls a function to map over this.state.docs and display that data. Even though the data in this.state can be logged successfully in the Home component's render function, the result of mapping over the data always returns undefined.

    If i create a new document it does get inserted and displays correctly, but the older documents never display.

    Here's my home component:

    import React from 'react'; import axios from 'axios'; import { Link } from 'react-router-dom'; const axiosConfig = { withCredentials: true, headers: { 'Content-Type': 'application/json' } }; class Home extends React.Component { constructor(props) { super(props); this.state = { docs: [], username: '', userid: '', newDocumentName: '', newDocumentPassword: '', loading: true }; console.log('this.props in home constructor ', this.props); } newDoc() { console.log('this.state before new doc ', this.state); axios(localStorage.getItem('url') + '/newDoc', { method: 'post', data: { title: this.state.newDocumentName, password: this.state.newDocumentPassword }, withCredentials: true }).then(resp => { console.log('the response to new doc ', resp); this.setState({ docs: [...this.state.docs, resp.data.document], newDocumentName: '', newDocumentPassword: '' }); }); } renderDocumentList() { return this.state.docs.map((doc, i) => ( <div key={i}> <Link to={`/editDocument/${doc._id}`}>{doc.title}</Link> </div> )); } logout() { axios .post('http://localhost:3000/logout') .then(resp => { this.props.history.replace('/'); }) .catch(error => console.log(error)); } async componentDidMount() { try { let resp = await axios .get( localStorage.getItem('url') + '/getAllDocs/' + this.props.match.params.userid, axiosConfig ) .then(resp => { console.log('awaited response in comp did mount of home ', resp); this.setState({ docs: [resp.data.docs], username: resp.data.username, userid: resp.data.userid, loading: false }); }); } catch (e) { console.log(e); } } render() { if (this.state.loading) { return ( <div> <h2>Loading...</h2> </div> ); } else { return ( <div className="page-container"> <div className="document-header"> <button className="logout-button" onClick={() => this.logout()}> Logout </button> <h3>Welcome, {this.state.username}.</h3> </div> <div className="create-or-share-document-div"> <input type="text" placeholder="New document name" name="newDocumentName" value={this.state.newDocumentName || ''} onChange={event => { this.setState({ newDocumentName: event.target.value }); }} style={{ width: '30%' }} /> <input type="password" placeholder="new document password" name="newDocumentPassword" value={this.state.newDocumentPassword || ''} onChange={event => { this.setState({ newDocumentPassword: event.target.value }); }} style={{ width: '30%' }} /> <button style={{ border: 'solid black 1px', padding: '5px', borderRadius: '10px', height: '3%', backgroundColor: 'lightgrey' }} onClick={() => this.newDoc()} > Create Document </button> </div> <div className="document-container"> <div className="document-list"> <p>My Documents:</p> <ul>{this.renderDocumentList()}</ul> </div> </div> <br /> <div className="create-or-share-document-div"> <input style={{ width: '30%' }} type="text" placeholder="paste a docID to collab on a doc" ref="sharedDoc" /> <button style={{ border: 'solid black 1px', padding: '5px', borderRadius: '10px', height: '3%', backgroundColor: 'lightgrey' }} > Add Shared Doc </button> </div> </div> ); } } } export default Home; 
    submitted by /u/sendNudesNotNukes132
    [link] [comments]

    [JS] A comprehensive library to convert "two point two million" into `2200000`

    Posted: 29 Jul 2018 08:36 PM PDT

    I am looking for an NPM package or any code that would convert as many variations of English numbers in words into proper numbers.

    For example:

    • "2.2 million" => 2200000
    • "2.2 mil" => 2200000
    • "2 grand" => 2000
    • "two point sixty-five million" => 2650000
    • "i need six hundred or seven hundred" => "i need 600 or 700"

    The last part (converting entire strings with multiple numbers) I can do on my own, and I can also replace "grand" with "thousand". But at least I need a library that supports things like "two point sixty-five".

    So far the best one I've found on NPM is words-to-num but it doesn't support decimals.

    Any recommendation please? Or maybe I am asking for too much?

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

    How do databases utilize the WHERE function so efficiently (Finding all objects in an array that meet certain criteria)

    Posted: 29 Jul 2018 08:23 AM PDT

    I am really curious how the WHERE function manages to be so efficient.

    I have doubts that it is as simple as this: (Python)

    result_array = [] for item in database: if item.company == "Google": result_array.append(item)

    Explanation: In this example, there is a result_array, which we want to store all of the items from "Google" in. We loop through the fictional "database" object and if the "company" property of the item is "Google" we add it to the result_array. We're left with an array, result_array, full of our desired objects.

    What type of programming concepts should I look up to learn how things such as SQL's WHERE function searches for objects so efficiently?

    submitted by /u/dougie-io
    [link] [comments]

    How does full-text searching work in SQL?

    Posted: 29 Jul 2018 07:15 PM PDT

    My company has a document management system that allows users to search the text of a document. I will try to provide all the details that I can here - I'm not a systems expert so hopefully what I say makes sense.

    The doc management system is SQL based - all metadata about documents is stored in SQL. Images, electronic files, thumbnails, etc. are stored in a Windows directory, including the .txt files for each document that contain the searchable text. This directory also contains .idx files, and it sounds like these are used to speed up searching in SQL, but I'm missing something here with how this text in the .txt files ends up SQL (if it does) and how the text is queried.

    I apologize if this isn't enough information to answer the question. I can try to answer any questions about our doc management environment if that will help answer my question.

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

    Would you use NodeJS to write the coomunications sub-module of an enterprise application? Is it a safe choice?

    Posted: 29 Jul 2018 06:23 AM PDT

    I'm in a unique position. I'm the chief tech lead in my company (small software house) and I'm currently designing the architecture of an enterprise application for an important multinational client.

    One of the things the application has to do is manage the upload of huge files via browser and store them on disk, so my first go-to, for this specific task, was NodeJS. Other modules will be written in .NET or Java.

    One of my team members, however, pushed pretty hard to stop me from using NodeJS at all. He put forward several objections ranging from:

    • his distaste for the language ("JavaScript is designed for the browser, not the server")

    • to security considerations ("an ex coworker of his who does security consultancy told him to stay away from NodeJS")

    • to "using this tech may make us look bad if the wrong people on the client's IT find out", given it's not "enterprise like Java or .NET"

    He comes from a Java/C++ background which make him despise everything that's not "as formal" as those ecosystems. I shut him down quickly when I saw he was being biased, but I took the last two points (security and enterpise-level) seriously.

    I'm still benchmarking based on our needs in order to choose the best tech among .NET, Java or NodeJS (which he would have done if I haden't told him to), and because this is my project, I'll decide what we use.

    However, the technical objections put forward are still looming in my head. The decision may be mine but I always consider my team's opinion, and he put a lot of self-doubt on my original assessment, making me doubt of myself to a point.

    What do you think? Should I have not considered NodeJS for an enterprise solution, even though it'll be used for just one module?

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

    What code language should I use and how can I learn it?

    Posted: 29 Jul 2018 03:27 PM PDT

    I want to make a game, but I have little experience with coding. If I ever publish it, it would be a Steam game (I don't know if that would affect which I should use). What language should I use to make it and where could I learn it (preferably online)?

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

    Cloned repo onto new machine, Python modules can't be found.

    Posted: 29 Jul 2018 03:20 PM PDT

    I've cloned my entire repo down onto a new Windows machine (from mac) and when I open up my project in Pycharm, I see this: errors

    I'm also getting "module not found" errors when attempting to run my tests with Pytest. I've set up a virtual environment and installed python, npm ,pytest, selenium ,etc.

    Why can't python see the modules even though they exist in the repo?

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

    python, html: reading and parsing emojis

    Posted: 29 Jul 2018 03:11 PM PDT

    when I open up HTML files with emojis in Firefox, it renders emojis as something like: 𾌥 (chrome shows a blank square).

    when I parse the html files using utf-8 encoding it seems to stay in that format.

    Is it possible to read those characters in as something like u'\U0001f648' so I can parse it with the emoji module? Or can I read them in directly as emojis like this: 😌?

    thanks

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

    Good laptop/processor for programming?

    Posted: 29 Jul 2018 01:27 PM PDT

    I'm relatively new to programming (about 1.5 years) and still in high school. I'm just programming for fun and have some mini projects. My question is what would be a good laptop to program on? What processor? Cores? RAM? What should I be looking out for? I'm primarily going to be using it to make and run neural networks. I've hit a wall with my asus i7-4710, 8 gigs RAM as it takes me a while to run more epochs with more complex dataframes. Any help would be appreciated. (Sorry if this doesn't belong on here but I though this would be the best place to post it)

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

    Code hygiene around the globe?

    Posted: 29 Jul 2018 07:25 AM PDT

    I work as a freelance code monkey moving from company to company. Many of these places outsource to or have offices in places like India, North Africa, the Middle East and China. Software quality varies considerably, some good, some bad, but what seems to be consistently horrible is what i call code hygiene.

    • Previous versions of code left in place but commented out.
    • Code cut and paste multiple times, rather than pulling a function out.
    • Indentation. Oh my god! How do people work on code that's inconsistent. I've seen blocks where every line is indented differently.
    • Random whitespace inserted all over the place. I've literally had to ask "why are they 10 blank lines after that if opening brace?"
    • Debugging prints left around

    When pointing these things out in code review i get blank stares, and comments along the lines of "but the code works".

    Do other people get the same issues? Any idea what the underlying issue is? Any advice on how to get the point across?

    BTW, don't take this as a "foreign developers are crap" post, because this often appears unrelated to the quality of the solution. It just seems like there's no value placed on clean code, which is different from teams in the US and EU (not really worked with other parts of the world).

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

    Remember the name of this data structure?

    Posted: 29 Jul 2018 06:33 AM PDT

    Solved, see bottom

    I saw this data structure posted to either Reddit or Hacker News a few months ago.

    It was something like a vector of fixed-sized chunks, and the author had used some of his other classes like a generic stack to build it.

    If you removed an item from it, instead of shifting all the following items like an std::vector does, it would mark it deleted in a bitmask (I think) and this allowed the user to keep stable pointers / iterators to individual elements.

    I'm quite sure it was C++. The author's page had this structure, and his stack class that was used to build it, and some other class (maybe a list).

    He had a bunch of benchmarks and graphs showing that it was faster than the STL classes at various tasks. I think it may have been intended for gamedev.

    The classes were all under the author's namespace, so it was like pfh::list, pfh::stack, pfh::(whatever the vector was called) but I can't remember the namespace either.

    Edit: One more thing, since it was structured sort of like a rope, it didn't copy anything when it reached capacity - It just linked in a new chunk and kept writing. So its push_back performance for large vectors was better than std::vector by miles.

    Edit: GOT IT!

    http://plflib.org/colony.htm

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

    Beginner question random.choice

    Posted: 29 Jul 2018 04:30 AM PDT

    Hey guys, I just started to learn how to program. I'm trying to create something that chooses random letters to create a fake word. This is what I got, and it works :)!

    import random

    letters1 = ['A', 'E', 'O', 'U', 'I']

    letters2 = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z']

    Locatie1 = random.choice(letters2)

    Locatie2 = random.choice(letters1)

    Locatie3 = random.choice(letters2)

    Locatie4 = random.choice(letters1)

    Locatie5 = random.choice(letters2)

    Locatie6 = random.choice(letters1)

    print(Locatie1+Locatie2+Locatie3+Locatie4+Locatie5+Locatie6)

    The only problem is, this program spits out 1 word everytime I run it. How do I get it to spit out lets say 10 words?
    Thanks guys!

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

    CSS content property glitch

    Posted: 29 Jul 2018 02:26 AM PDT

    Hello one of my friend's website made using wordpress has some issue. I am a web developer but I do not have experience with wordpress. I thought I could fix it but I could not

    Basically the website is this. The navbar item 'equipment sales' has a number 3 next 2 to it instead of a downward facing arrow. Now i know where this is coming from in css. The :before selector has a content attribute

    content: "3";

    If I try to change the number 3 to anything else it automatically changes back to 3. I have no idea why it i doing this.

    It would be great if you guys could take a look at it.

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

    What language should I attempt to mess around with and theoretically how would something like this be created

    Posted: 28 Jul 2018 10:48 PM PDT

    Extremely new to any sort of programming, I really only know the basics of Java. I want to attempt to create a program that will be able to access a website through an account and enter information. I have no idea as to how I would even go about this including how the program would contact the site and preform actions under the account. Any direction would be greatly appreciated, thanks!

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

    Is anyone able to help me with Lunar to Solar calendar conversion and vice versa?

    Posted: 28 Jul 2018 10:40 PM PDT

    Hi, I'm interested in doing up a Lunar to Solar calendar and vice versa conversion but I'm unsure of how to do up a formula. Can someone help me out?

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

    No comments:

    Post a Comment