• Breaking News

    Friday, January 5, 2018

    Demoralized by good code Ask Programming

    Demoralized by good code Ask Programming


    Demoralized by good code

    Posted: 05 Jan 2018 05:17 PM PST

    Recently, I started working on a project for personal use that consists of a library (that can be reused in my future projects) and a GUI that uses that library. While writing the library, I thought it would be a good idea to make it "efficient" so I scrolled through some open-source libraries to borrow some helper methods/functions that could be useful in my project. However, not only was it too complex for me to understand, I felt utterly demoralized in progressing my own project as I feel like my own code will never be as "optimized" or "scalable" as theirs. Have any of you ever felt that way? Should I take time and try to understand their code in order to improve my coding or should I keep writing my spaghetti code?

    Btw, I'm currently a U1 SE student with some background in programming.

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

    Checking to see if 3 MIDI signals make a chord.

    Posted: 05 Jan 2018 11:49 AM PST

    I'm trying to learn how to play my keyboard. I found a monosynth and I made it into a 3 Oscillator synth. My way of determining the chord is just a ton of if statements. You can see how I'm checking for a chord on line 128. https://github.com/taylor24/ChordHelper/blob/gh-pages/index.html It's ugly, and it will only give you the chord if you hit them in order (C first. E second and G third) = Major C. If you play G E C, it wont give you C Major. How can I check to see if the perimeters make up a chord?

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

    Setting Region or "Square" of elements of an Array

    Posted: 05 Jan 2018 06:28 PM PST

    Hello everyone!

    I'm using a 2D array to generate rogue-like dungeons, very simple, drunkard walk-style. I'm trying to make it more dungeon-like by having corridors and rooms, I currently have my "crawler" choose a random direction with a random corridor length, (setting the appropriate elements to 1 for a floor). At the end of the corridor I'd like to create a square, pick a new direction, repeat etc. I'm sure this is simple I just put my finger on it right now for some reason, but what is an efficient way to set "square" or region of elements in an array.

    I currently have this when i reach the end of a corridor:

    cx and cy is my "crawler" position in the array

    for (int k = 0; k < roomSize/2; k++)

     { mapGrid[cx + (1*k), cy] = 1; //Floor mapGrid[cx - (1*k), cy] = 1; //Floor mapGrid[cx, cy + (1*k)] = 1; //Floor mapGrid[cx, cy - (1*k)] = 1; //Floor } 

    And THIS is my result

    EDIT: Formatting

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

    Denormalized database

    Posted: 05 Jan 2018 04:41 PM PST

    I am working on an API that my colleague started the basic structure of and it has led to a point of contention between us. He says that every entity in database should be linked to our main user entity. He says that this is "modern" database design.

    We have multiple user types and this design was just getting too complicated linking everything to the same table so I had to create a user table for each type of user for my own sanity which upset my colleague and he keeps referring to this as the old way of doing things and not as good performance.

    It actually wasted a lot of my time trying to shoehorn the requirement into a single table format and it's not something I have heard of. I told him that it is standard practice to have a table for each user type that has foreign key to universal user table and then have everything specific to that user type linked to that table. He says this is bad practice now and modern way is to have everything linking to a single table.

    I asked him what this setup is called and he just said "denormalization" which I know as removing redundant tables, I haven't seen anything so insistent on single parent table design.

    English isn't his first language so the discussion is not always so easy but I cant really see the benefit. I have added parent id as a index on all descendants enforced as required field through the ORM so you can still query each table by user ID with good performance but this way it's much easier for me to code the inter user logic as I am dealing with different entities accessing common entities. I could probably make it work with a single table but I would be using so many switches and enums in each record it would just be really confusing for me to get the logic down and I feel like it would lead to more bugs.

    In the end he just said for me to do what is in my skill level but the inter user logic I am implementing is quite complex so I feel like this is right approach but he says my database design is bad.

    I am not good with databases so want to improve but not really sure what I should be researching. This guy has more experience than me so I think he is probably right but he lacks the language for me to have proper discussion on the requirement.

    Any advice?

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

    I'm using async/await functions on an array of IDs to send out 10 API calls sequentially, then I want to dispatch that new array of responses to my reducer. I've retrieved my responses in order, but I don't have access to dispatch. Am I hopeless?

    Posted: 05 Jan 2018 11:31 AM PST

    RESOLVED.

    I incorporated the async/await logic into the reducer that ran right before this one was supposed to. It's a long promise chain, but it works.

    Background info:

    I'm using the OMDB api to create a web app that has a search bar at the top. This project is mainly to get a better grasp on react-redux, react-router, webpack, and babel. I'm also using bulma on the UI to see what it's all about.

    When a movie title is entered in:

    1. I send an initial request to get a list of movies with limited information.
    2. From that list I extract the imdbIDs from each movie into an array.
    3. From that array, I send out sequential api calls to get the full details of each movie, in order.
    4. Once the new array of movies arrives, I map over the data and produce a list of cards in the UI.
    5. Each card has limited information, but the user can click a button that routes them to full details.

    Now I just have to wire up localstorage (or sessionstorage, idk yet) to cache the data to prevent calling the api too many times.

    Here's the solution to my problem for anyone in the future:

    export const fetchData = searchTerm => { const url = `${ROOT_URL}?s=${searchTerm}${API_KEY}`; return dispatch => { dispatch(fetchStarted()); axios .get(url) .then( response => Object.keys(mapKeys(response.data.Search, 'imdbID')), dispatch(fetchMainData()) ) .then(async movieIDs => { let fullDetailArray = []; await asyncForEach(movieIDs, async imdbID => { const url = `${ROOT_URL}?i=${imdbID}${API_KEY}`; await axios.get(url).then(response => { fullDetailArray.push(response.data); }); }); console.log('DETAIL ARRAY', fullDetailArray); dispatch(fetchMainDataSuccess(fullDetailArray)); }); }; }; 

    ORIGINAL POST BELOW


    I'm using React/Redux/React-Router/Node

    // create an asyncForEach method: async function asyncForEach(array, callback) { for (let index = 0; index < array.length; index++) { await callback(array[index], index, array); } } // accepts an array, shoots out 10 sequential calls: export const fetchDetailsByIDs = async listIDs => { let fullDetailArray = []; await asyncForEach(listIDs, async imdbID => { const url = `${ROOT_URL}?i=${imdbID}${API_KEY}`; await axios.get(url).then(response => { fullDetailArray.push(response.data); }); }); console.log('DETAIL ARRAY', fullDetailArray); // console prints: DETAIL ARRAY (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] }; // This is my action: export const fetchMainDataSuccess = movieList => { type: FETCH_MAIN_DATA_SUCCESS; payload: movieList; }; 

    I'm unable to dispatch fullDetailArray, am I hopeless?

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

    Need Help: Website vs Program

    Posted: 05 Jan 2018 11:26 AM PST

    I am building a project that needs to integrate a database and that needs to share the data across multiple devices. Would a website or a program work better for this application

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

    Math on a 40 digit number?

    Posted: 05 Jan 2018 11:09 AM PST

    I need to do some operations on a 40 digit number. Its stored in SQL which says no thank you, won't fit in my 38 precision limit. The only other language I know is C# which also says no thank you. Any ideas?

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

    Which languages should I learn for my app? React or Swift/Java

    Posted: 05 Jan 2018 02:46 PM PST

    I've decided to develop a mobile application. So far, I've only built apps with Python (Django), PHP. I have zero JavaScript knowledge.

    My App has the following requirements:

    • Geolocation - I would like to be able to sort results by distance from users
    • Loading different cards - Probably posting a GET request and receiving json response from my backend server, then loading this data in a list view
    • Payment Processing - Stripe will do
    • Social integration e.g. FB login

    And app that comes with similar features is Tinder/Deliveroo/Uber.


    My choices are, and I am a complete beginner (zero) in all of them:

    1. React Native
    2. Swift and Java

    I understand that React Native might be better because it allows to develop for both at the same time, but I read that functionality is limited compared to Native Development. However, is it a better choice for my type of project? Does it work for my requirements? Which one should I pick, I would like to hear Pros and Cons of each e.g. learning curve, speed of development from 0 to app, set of features, debugging and future proof. I would like to stop deciding and start developing, but both seem like good options to me. If you were to start fresh again, which one would you pick and why?

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

    Is there a GUI framework that lets me specify layout constraints as linear equations?

    Posted: 05 Jan 2018 10:36 AM PST

    Because that would be awesome. Probably extremely slow, but nevertheless awesome.

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

    I want to sort some data on a website

    Posted: 05 Jan 2018 02:22 PM PST

    So basically, I try to keep an up to date list of my friend and I PC specs. Right now I keep it in a Google Sheets Spreadsheet (yes it has weird stuff, don't mind it), but it is a PAIN IN THE ASS to update (and use anyway). I'd like to make a website, that once done, will make it easier for me to edit people's specs and add other people too. A sorting system could be nice, but I can do without it.

    Sadly, I don't really have much experience with programming, but I am definitely willing to learn. I know this might be asking a lot, especially since I'm only a beginner. Where should I start?

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

    Resources for Architecture and Data Structure of Activity Feeds / Timelines

    Posted: 05 Jan 2018 02:12 PM PST

    I've got a simple PHP / MySQL / Angular app that I'm looking to add an activity feed for. I was surprised not to find a whole lot of documentation on ideas for architectures for this out on the internet - there were a lot of "things to think about" but not so many implementation ideas.

    My users are in small-ish groups of people that range from typically 2-3 people up to max of 20-30 in the very rare cases. Implementation needs to be scalable to N number of groups.

    The general ideas that I've come up with are (in no particular order):

    • Activities are recorded at write-time independently of my current data structure. So I basically create an activities table, with columns like "groupId, actorId, actionId, message, effectiveDate". When user logs in, I just look up the user's group, and join the two tables to get my results results (top 10, whatever). Downside to this is they can't really be updated or deleted if I ever decide to do this because the original content is in other tables.

    • Activities are read from multiple tables currently storing the data. So, for example I have a contact table and a communication table, and I may want to add new contact notification to my feed as well as all contact communications. So, this is just basically a bunch of joins/unions on my current data structure. I'm afraid of the performance of this.

    Any other ground breaking ideas or guidance out there?

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

    Is Unity still the best route for developing cross platform mobile AR games?

    Posted: 05 Jan 2018 02:12 PM PST

    I've seen ARkit for iOS but Google's ARcore supported device list is so small doesn't seem worth implementing it yet.

    Is it better to just use Unity currently to develop for both platforms? Or is there a better alternative?

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

    SQL Query Select Question

    Posted: 05 Jan 2018 02:08 PM PST

    Hi. I'm new to learning SQL and I'm trying to create a SQL query that selects the P's of rows that satisfy the following conditions:

    1. The q1 value matches the q1 value of one or more other P's.
    2. The pos1 and pos2 pair must be unique.

    The table I have is:

    Table Name: Trial

    P q1 q2 pos1 pos2
    1 10 50 5 4
    2 2 40 2 4
    3 3 30 2 4
    4 10 20 3 6
    5 2 10 8 6

    I am trying to select 1, 4, and 5.

    I have tried something like:

    SELECT a.P FROM trial as a, trial as b WHERE a.q1 = b.q1 and a.pos1 != b.pos1 and a.pos2 != b.pos2;

    But I would get the selection of 1, 2, 4, and 5. However, 2 is an invalid choice because it shares the same pos1, pos2 pair as P 3.

    Do you have any tips for this question? Thanks.

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

    can´t solve this problem.

    Posted: 05 Jan 2018 12:20 PM PST

    hey guys im trying to learn code, and i find a dude on youtube how to make a website and now im stuck though i followed the instructions. hope you guys can help. Thanks you on before hand it some CSS: @import 'https://fonts.googleapis.com/css?family=Alegreya+Sans';

    • { margin: 0; border: 0; padding: 0; } body { background: #F1F6F8 font-family: sans-serif; margin: 0 auto; } p { font-family: "Alegreya Sans", sans-serif; color: #524C56 margin: 0 auto; } h3 { font-size: 175%; line-height: 155% font-weight: 500%; color: #524C56; text-align: center; text-transform: uppercase; padding: 0; } a { color: #524C56 text-decoration none; font-weight: bold; } a:hover{ color: #C3D7DF }

    img { display: block; margin: 0 auto; max-width: 100% height: auto; width: auto; margin-bottom: -4px; }

    wrapper {

    max-width: 1200px; margin: 0 auto; 

    }

    banner-wrapper {

    max-width: 1200px; margin: 0 auto; padding: 0 0 3% 0 

    } header { width: 100% height 100px top: 0; left: 0; }

    logo{

    margin: 20px; float: left; width: 104px; height: 52px; background: url(img/icons/RD-dark.png); 

    } nav { float: right padding: 25px 20px 0px 0px; }

    menu-icon {

    display: hidden width: 40px height: 40px background: url(img/icons/nav-dark.png) no-repeat center; 

    } ul { list-style: none; } nav ul li { font-family: 'Alegreya Sans', sans-serif font-size: 150%; display: inline-block float: left padding: 10px; }

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

    Short-lived instances of Python server?

    Posted: 05 Jan 2018 11:52 AM PST

    Hey all,

    I'm pretty new to web/cloud computing, and I'm having trouble figuring out/deciding how to architecture the side project I'm doing. I recently built a website for myself hosted on AWS using the tutorial found at https://serverless-stack.com/ (and obviously customized it a bit).

    I also wrote a "minichess" bot during my last term of school. I'd like to host it so that people that visit my site can play against the bot. Vaguely, I think my solution is short-lived socket servers that can kill themselves based on a timeout, in order to avoid unnecessary server time. Here's where my lack of knowledge comes in:

    1.) Is there a way to do this with AWS so that instances of my website can dynamically connect to instances of the chess bot?

    2.) Would it be better to just create a monolithic server and try to implement multiple games/connections through multi-threading?

    Or is there some other option that would work better that I'm not seeing? There's also a version of the bot in Java which I could work with if that makes any part of the process easier.

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

    [HTML] How to load bootstrap css properly?

    Posted: 05 Jan 2018 11:52 AM PST

    Essentially I'm trying to make a personal website and a lot of this is new to me. I did use freeCodeCamp for some stuff but what I'm essentially doing now is making sure I can load one properly before working on it

    http://getbootstrap.com/2.3.2/examples/carousel.html#

    I downloaded the html from the site (used inspect element) and used the bootstrap they had available to download as well

    Here's my project structure (the parent directory is called bootstrap): https://i.imgur.com/biqQBwH.png

    Here's what it looks like when I load index.html: https://i.imgur.com/pdMVnTr.png

    I thought it might have something to do with the css preprocessor, but I'm really not sure

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

    What do you do to get unstuck?

    Posted: 05 Jan 2018 05:40 AM PST

    When you have difficulty solving a problem what do you do? Is there a process you have to think about something else or think about the problem in another way? Do you take a break? What do you do when you take a break?

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

    Using way too much data

    Posted: 05 Jan 2018 10:52 AM PST

    Using too much data on my android phone. .2 Gb a day, just browsing reddit and opening gifs and articles. Blocked youtube in hosts just so I don't accidentally load anything. I don't load ads. Is there a way to block gifs if they're over say a Mb? Or other ways to block the heavier parts of sites?

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

    What language should I use?

    Posted: 05 Jan 2018 09:53 AM PST

    Budget creator. So it will take in information like income per month, then I can split it down to bills, rainy day fund if it doesn't already exist, then to things I want (pc parts, car, etc...) Each thing should have a percentage bar that can be increased/decreased and give back information.

    Thanks for your time.

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

    [java] trying Externalization, not able to persist the objects state, every thing is initialised to default ??

    Posted: 05 Jan 2018 08:37 AM PST

    NOTE :. don't scared by its length most of it is just the output in the end.

    NOTE: plz copy this code into your favourite editor, as I have lots of comments : and it looks cumbersome.

    file Car.java.

     import java.io.IOException; import java.io.Externalizable; // NOTE: Externalizable extends Serializable import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.ObjectInput; import java.io.ObjectOutput; public class Car implements Externalizable { String name; // String has already implemented Serializable --> so we can directly use it to write and read int year; static int age; // in Externalization we can save the values of the static values too public Car(){ System.out.println("MANDATORY - - DEFAULT constructor"); } public Car(String name, int year){ this.name = name; this.year = year; age = 10; // initializing in the constructor, well i could have initialized it in the Class level only } // overridding the two methods, in Externalizable interface, NOTE: Serializable was a MARKER interface @Override // properties of our object that we need to save public void writeExternal (ObjectOutput oos) throws IOException { // not throwing so --> need try-catch block try{ oos.writeObject(name); // as name is object of class String _> which already have implemented the Serializable oos.writeInt(year); oos.writeInt(age); // writing the static data-member }catch(IOException e){ // only IOException System.out.println(e); e.printStackTrace(); } } @Override //--> thrown, so no try-catch public void readExternal (ObjectInput ois) throws IOException, ClassNotFoundException { String name = (String) ois.readObject(); // returns the istance of "Object" class need to type cast it int year = ois.readInt(); int age = ois.readInt(); } @Override public String toString(){ String s = "- - - current object : " + this.name + " - - - " + "\n \tname : " + this.name + "\n \tyear : " + this.year + "\n \tage : " + this.age + "\n\n"; return s; } } 

    file AddCarRecord.java.

     import java.io.FileOutputStream; import java.io.FileInputStream; import java.io.ObjectOutputStream; import java.io.IOException; import java.io.Externalizable; public class AddCarRecord { public static void main(String[] args) throws IOException{ // create car Object Car audi = new Car("audi", 2020); Car jaguar = new Car("jaguar", 2022); Car ferrari = new Car("ferrari", 2024); // Serialize these car's -> into a file FileOutputStream fout = new FileOutputStream("Maintain_CarRecords.txt"); ObjectOutputStream oos = new ObjectOutputStream(fout); System.out.println(" - - - printing before writing it to the file - - - \n"); System.out.println(audi); System.out.println(jaguar); System.out.println(ferrari); System.out.println(" * * * * * now writing to the file * * * * * \n"); oos.writeObject(audi); oos.flush(); oos.writeObject(jaguar); oos.flush(); oos.writeObject(ferrari); oos.flush(); } } 

    file ReadCarRecords.java.

     import java.io.FileOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.ObjectInputStream; public class ReadCarRecords{ // . ClassNotFoundException -> from readObject() method public static void main(String[] args) throws IOException, ClassNotFoundException{ // de-Serialize these car's -> into a file FileInputStream fin = new FileInputStream("Maintain_CarRecords.txt"); ObjectInputStream ois = new ObjectInputStream(fin); Car newAudi = (Car) ois.readObject(); Car newJaguar = (Car) ois.readObject(); Car newFerrari = (Car) ois.readObject(); // as we have overrided the toString method in the Car class SO, System.out.println(newAudi); System.out.println(newJaguar); System.out.println(newFerrari); } } 

    execution - output - - **see all set to default values when I am reading the records **.

     >> ROOT: } rm -rf *.class *.txt >> ROOT: } clear >> ROOT: } javac AddCarRecord.java >> ROOT: } javac ReadCarRecords.java >> ROOT: } java AddCarRecord - - - printing before writing it to the file - - - - - - current object : audi - - - name : audi year : 2020 age : 10 - - - current object : jaguar - - - name : jaguar year : 2022 age : 10 - - - current object : ferrari - - - name : ferrari year : 2024 age : 10 * * * * * now writing to the file * * * * * >> ROOT: } java ReadCarRecords MANDATORY - - DEFAULT constructor MANDATORY - - DEFAULT constructor MANDATORY - - DEFAULT constructor - - - current object : null - - - name : null year : 0 age : 0 - - - current object : null - - - name : null year : 0 age : 0 - - - current object : null - - - name : null year : 0 age : 0 
    submitted by /u/prashantkr314
    [link] [comments]

    What is the convention on where to write new functions?

    Posted: 04 Jan 2018 11:26 PM PST

    If I have a main function that calls Func1, where should I declare Func1? Above or below my main function? I've seen different video tutorials do it both ways. What is the convention?

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

    [JAVA] String comparison

    Posted: 05 Jan 2018 04:02 AM PST

    I have the following function

     private boolean paircheck(String s) { String[] romanPairs = { "IM","CM","CD","IC","XC","XL","IX","IV" }; for(String rps: romanPairs) { System.out.println(rps + "::" + s); if(rps == s) return true; else System.out.println("not the same"); } return false; } 

    All it`s supposed to do is compare a String of 2 characters and return true if it matches a Roman number with 2 digits. However, it never returns true, here is one of the results I got with debug console output:
    subStr:IM:subStr
    IM::IM
    not the same

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

    How to create Background applications?

    Posted: 04 Jan 2018 10:58 PM PST

    I recently got a new mechanical keyboard and it has a ton of nice and shiny new buttons! There's just one problem, I use Linux and the software for the keyboard is Windows only. Actually, every button works on my computer except there is a timer button. I think it's pretty neat idea and I want to be able to use it. So, I've decided to make my own timer software to use this button with, but I have a few things to iron out that weren't very easy to google the answer.

    I would want to not necessarily have this piece of software running ie forget to open/background the app and the button doesn't work. I don't have a good idea for how to do this. Like the original software developed for the keyboard has a setting window where you can configure the timer and a few other aspects. Then you can close that application and when you press the timer button it starts and when the timer is over your keys backlight flashes. I just don't know how to create this. Any Ideas?

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

    No comments:

    Post a Comment