• Breaking News

    Friday, January 10, 2020

    Am I moving my project in the right direction? Making installation scripts. Ask Programming

    Am I moving my project in the right direction? Making installation scripts. Ask Programming


    Am I moving my project in the right direction? Making installation scripts.

    Posted: 10 Jan 2020 06:41 PM PST

    Background:

    I've been self teaching my way around linux for the past couple of years, building a project which is supposed to reduce the high tech barrier to entry for a cryptocurrency node device. It's been going well and my confidence in this has steadily been growing and I'm onto the 2nd version of the project. In the past I've managed to find all the info I need to overcome each problem I've faced step by step from communities like this. Great.

    The project I'm making is built on a Raspberry Pi, and once I make a new version and add features etc, I create a disk image of the project and upload it for users to flash to their own devices. What is on the disk image is shown at my github but understandably a user actually has no idea what is on the disk image I upload until they use it. Which then brings in the issue of trust. People don't actually know me and the project directly supports a users privacy, so there is a conflict there between the basis of what the project does and the way I'm delivering it.

    The question:

    I want to stop making disk images as a way of releasing my project, and instead produce install scripts. These scripts would be hosted on my Github so opensource and verifiable there's nothing malicious.

    Is this a better practice? Or should I be looking at another method I'm not aware of? Does anyone have a link to some resources of Do's and Dont's?

    For more context:

    My/The project github

    My current direction is that in future to install my project a user would enter wget -O - https://raw.githubusercontent.com/shermand100/pinode-xmr/development/pinode-xmr-build.sh | bash at the command line once they've installed their OS from their normal trusted source.

    This brings up a menu to select their OS, which downloads and runs the script for their OS. (This should open up the project to more hardware, not just currently the Raspberry Pi specific image I make now).

    If selected, the script raspbian.sh for example then continues the install but is heavily reliant on the sudo command. Which is my concern for if this is best practice?

    I know that's a bit wordy but I hope it's clear enough what I'm trying to achieve.Many thanks

    Dan

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

    Trying to understand Strategy pattern, and composition over inheritance

    Posted: 10 Jan 2020 06:31 AM PST

    I've found that most programming courses (both online and at universities) teach inheritance and OOP in an awful way. Your generic OOP example usually consists of implementing a taxonomical hierarchy of animals to explain inheritance (Cat extends Feline, Feline extends Mammal, Mammal extends Animal, you get the picture), to avoid '''code reuse'''. Many new programmers don't understand how tightly coupling your classes like this can make your code a mess. See http://whats-in-a-game.com/implementation-inheritance-is-evil/

    To get rid of this bad habit I've been reading up on design patterns. I've been trying to really understand the strategy pattern and I've come across this example https://www.geeksforgeeks.org/strategy-pattern-set-2/

    At first glance it looks fine, the program has encapsulated Jump and Kick behaviour away, and now all classes derived from the Fighter class can pick and choose their own jump or kick behaviour and even change it dynamically.

    My question however is about the usage of extends here. We see that the Ryu, Ken, and ChunLi classes all extend Fighter, essentially tightly coupling these classes with Fighter. What if in the future you want a Dhalsim character (for those who don't know, Dhalsim is a monk character who can levitate) and you don't want any Jump behaviour, since this character has no jumping behaviour but simply floats instead. The Dhalsim class still requires a jump behaviour.

    What you can do is :

    1) override the jump method with an empty implementation.

    2) Create an abstract FighterWithoutJump class which has no jumpbehaviour instance field and no jump() method and let Dhalsim extend from this class.

    Both these 'solutions' are ugly and lead to either an explosion of hierarchical classes in case of #2 and unclear contracts in violation of interface segregation principle in case of #1. This is exactly the problem which the strategy pattern was trying to solve, and now we're back to square one.

    So my question is, is there an elegant solution to this problem which I'm not seeing?

    edit: as a follow up question after reading this article https://www.javaworld.com/article/2073649/why-extends-is-evil.html , is there ever a reason to use inheritance over composition?

    edit2: guys I'm not actually creating a street fighter clone, the scenario is meant just as an example.

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

    Trouble getting .Net Core in Docker to talk to local database

    Posted: 10 Jan 2020 02:44 PM PST

    I wrote my first back-end .Net Core web app recently that uses a localdb (ms sql db) on the host machine while the app itself is running inside a docker container.

    When trying to get the docker container to connect, I found many sources online saying that you need to make sure that TCP connections are allowed by the sql database. So in light of this, I decided that since I had everything running locally, I could instead change my connection strings in the following manner (The model is called 'Employee):

    "EmployeeContext": "Server=(localdb)\\mssqllocaldb;Database=EmployeeContext-1;Trusted_Connection=True;MultipleActiveResultSets=true", "EmployeeContext": "Server=192.168.0.214,1433\\mssqllocaldb;Database=EmployeeContext-1;Trusted_Connection=True;MultipleActiveResultSets=true" 

    The first being the original (which still works locally) and the second being the new one. This however lead to connection refusal. Now I should note that I can actually see the database in Visual Studio under the 'SQL Server Object Explorer'. My next step was to go into the 'SQL Server Configuration Manager' tool to make the database accept TCP but under 'SQL Server Network Configuration', there is only SQLEXPRESS and no MS Sql database.

    First off, am I on the right track at all? Secondly, why is there no MS SQL database in the configuration manager? If its okay not to be there, how can I enable TCP connections for that database?

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

    Java vs C++ assignment

    Posted: 10 Jan 2020 08:38 PM PST

    Hello everyone. One of my university's assignments required us to provide two almost identical C++ and Java programs to showcase how garbage collection may make a Java program run faster than the C++ equivalent. The hint we had was to create a very large amount of objects and then remove some of them so that the final data structure would be very sparse. A Java garbage collector would rearrange these objects and move them close to each other in memory, whereas in C++ the absence of a gc would result in bad spatial locality for the remaining objects, making the C++ equivalent program slower when we perform operations on these sparse objects. I have written an example that I will post later(not currently on my laptop) using arrays and a custom class with a simple method that adds certain long fields, but my first question is, is anyone available for a quick chat on what may be going wrong with my code?

    EDIT: Since Java arrays actually hold references to the actual objects of my class, I created two arrays of pointers in C++ and filled the first one with almost 11GBs of my custom class objects(around 120000000 objects). Then, I assigned references to these objects with a large step between them to a new array of 10.000 pointers to the initial array. Then I deleted all other entries from the first array. I thought than now performing calculations among these sparse objects of the second array would be much slower in c++ due to bad locality(compared to the same logic and applying System.gc() before the calculations in Java) but the corresponding programs run equally fast.

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

    Need help in android programming

    Posted: 10 Jan 2020 08:29 PM PST

    So im making a video player which can run two videos simultanously without either of them pausing. Im running them on two different threads. The idea is that Ill enable pip mode and when i press button one thread will minimize so the second video from second thread is only visible. Then when i press the button again the second video will minimize and first video will become full screen. Is it possible to enable pip mode on thread level?

    public class MainActivity extends AppCompatActivity {
    VideoView video1,video2;
    u/Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    video1=(VideoView)findViewById(R.id.video1);
    video1.setVideoURI(Uri.parse("android.resource://" +getPackageName()+ "/"+R.raw.video1));
    video1.setMediaController(new MediaController(this));
    video1.requestFocus();
    video2=(VideoView)findViewById(R.id.video2);
    video2.setVideoURI(Uri.parse("android.resource://" +getPackageName()+ "/"+R.raw.video2));
    video2.setMediaController(new MediaController(this));
    video2.requestFocus();

    final Thread view1=new Thread(new Runnable() {

    u/Override
    public void run() {
    // TODO Auto-generated method stub
    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_DISPLAY);
    video1.requestFocus();
    video1.start();
    }
    });

    Thread view2=new Thread(new Runnable() {

    u/Override
    public void run() {
    // TODO Auto-generated method stub
    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_DISPLAY);
    video2.start();
    }
    });
    }
    }

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

    Powershell Command Help

    Posted: 10 Jan 2020 07:48 PM PST

    I'm trying to convert this windows batch command to powershell:

    call "%WORKSPACE%\node_modules\.bin\ngc" -p "%WORKSPACE%\tsconfig-aot-admin.json"

    I'm not sure how to do this when passing a parameter with powershell.

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

    Are you ever 100% happy with your code/a project?

    Posted: 10 Jan 2020 07:08 PM PST

    I feel like every project I work on, I review the code after a while and feel like it could have been written so much better. Are you ever truly happy with what you created? Are you guys/girls constantly refactoring? Do I need to read more on application design?

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

    Can a wrapper be created around existing android games to redefine their controls ui to spread the controls around the perimeter of the screen for multiple people to control parts of what 1 player would normally do?

    Posted: 10 Jan 2020 06:15 PM PST

    I want to try mutliple people each taking part of the controls of a single player game on an android touchscreen, and would like to generalize this to work on any existing android game if possible.

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

    Which emulators of very old game systems (nes, snes, genesis, etc) run in platform-independent browser purely in Uint8Array of its memory space including controls input, screen pixels output, etc?

    Posted: 10 Jan 2020 05:26 PM PST

    I dont want it accessing the user interface, only the Uint8Array, which code outside the emulator may or may not copy to a canvas, copy various customizable controllers into it, etc?

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

    How do I write a command that will search your entire computer for a file that contains a line of text you write?

    Posted: 10 Jan 2020 09:02 AM PST

    New Job, Completely Overwhelmed

    Posted: 10 Jan 2020 08:36 AM PST

    I just started my first full-time programming job, and it feels like a nightmare. There's only one other developer, and the lead developer just quit. There are 120 open tickets, monolithic code bases (20,000+ lines in individual files), multiple projects to maintain, hundreds of dependencies. I feel like I'm being set up to fail. I don't know what to think.

    Any advice? Once caveat: I don't want to quit because I want the pay to fund investments.

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

    Unexpected end of input with fetch from JSON API

    Posted: 10 Jan 2020 12:30 PM PST

    I'm using React and trying to send a simple fetch in a project that is frontend-only. I was getting a CORS error, so I added mode: "no-cors" to the fetch, following the advice I found on another StackOverflow question. This resolves the CORS error, but now I'm getting an 'SyntaxError: Unexpected end of input' error. None of the data is being saved to state, so the fetch is not being completed properly. I don't have access to edit the JSON file, but I can't do anything for this exercise without being able to fetch the data.

    Here's what I have in my App.js:

    import React, { Component } from "react"; import { BrowserRouter as Router, Switch, Route, Link, withRouter } from "react-router-dom"; import ContactList from "./components/ContactList"; class App extends Component { constructor() { super(); this.state = { contacts: [] }; } componentDidMount() { this.fetchContacts(); } fetchContacts = () => { fetch("https://s3.amazonaws.com/technical-challenge/v3/contacts.json", { mode: "no-cors" }) .then(resp => resp.json()) .then(contacts => { this.setState({ contacts: contacts }); }) .catch(alert); }; render() { return ( <div> {this.state.contacts.map(contact => { return <p>{contact.name}</p>; })} <ContactList contacts={this.state.contacts} /> </div> ); } } export default withRouter(App); 
    submitted by /u/panda_nectar
    [link] [comments]

    Feeling like everything is just hacked together?!

    Posted: 10 Jan 2020 12:19 AM PST

    So I am fairly new to programming but for the most part I am able to get my ideas out in my personal projects.

    I am still learning the concepts and best practices but everything I put together feels like I hacked it together. Taking code snippets from here and putting it with code snippets from there and tinkering until eventually I get the result I am looking for. Whatever snippets or concepts I use, I study it and figure out why its working that way the best I can. At the end of it, I know there was probably a better way to put my code together but I got the result so I move on to the next project or idea but I am left with the feeling that I just hacked together something and could have done it better.

    Is this a common feeling with other people who are learning or those who are experienced programmers?

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

    Removing duplicate code with multiple APIs

    Posted: 10 Jan 2020 10:29 AM PST

    We currently have multiple APIs doing the same thing but the code is basically just copied for each API. The names of fields and formats are different between the various APIs, but everything is ultimately the same. I am working to make these APIs to call the same code so we can remove any duplication.

    I have made changes and now each individual API has a class that the JSON gets mapped to. I then convert each of those classes to a single class (handle any format conversion, name differences, etc). This seems to be working well.

    The problem I am running into is handling errors. I validate the single class but when there is an error the expected error output is supposed to have something like

    { "errors": [ { "error": "DOB is not in valid range", "field": "dob" } ] } 

    The problem is if one of the APIs has the field dateOfBirth instead of dob then I am not mapping the correct field in the error.

    I see two solutions for this:

    1. I could have a process that remap each the fields back to what each of the individual APIs needs but that seems like a hassle.

    2. I can do the validation on each of the individual APIs instead of the shared single class. This also seems like a hassle to duplicate the validation and if I miss validation on an API it won't be consistent.

    Any suggestions?

    submitted by /u/-----_-_-_-_-_-----
    [link] [comments]

    Search server for filepaths over character limit

    Posted: 10 Jan 2020 09:21 AM PST

    Hi all, I'm not sure if this is the right place to post this question, but here goes.

    My work is migrating files from a server formatted for OSX to a server formatted for Windows. We're running into issues because of the 256 character limit, and I was hoping to find a program that could search for Files over the limit. That way we could rename them and migrate all the data

    Any thoughts?

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

    How exactly does Open Source Code licensing work?

    Posted: 10 Jan 2020 01:58 AM PST

    Hi. I am fairly new to the world of programming. I am a college student and have never received formal Coding education. I just do it for fun. My first encounter with Coding was around Last June. I wrote some small Python scripts for personal use with Google and Reddit's help.

    I started taking coding seriously in November and I have come a long way since. As I don't own a PC or a server I write code on my android, so I started learning JavaScript as I can deploy my online JS scripts on Google app Script. I have created some useful Userscripts and Tools for an online community that I am a part of. I am interested in Open Source them. So I have been looking into it.

    I often see some sort of MIT License on GitHub projects and I have no idea what they are and what is their importance. Could someone please explain me what they are and should I get one before making my code public? Thanks.

    I am sorry if this post doesn't belong here, but I thought this would be the best place to ask.

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

    Help with double corruption

    Posted: 10 Jan 2020 04:46 AM PST

    #include <stdio.h>

    #include <stdlib.h>

    int Length(const char* pString) {

    int i = 0;

    while(*(pString + i) != '\0') i++;

    return i;

    }

    typedef struct Client Client;

    struct Client {

    char* ID;

    char* Name;

    char* Email;

    void (*ShowClient)(Client*);

    void (*Free)(Client*);

    };

    void Client_ShowClient(Client* this) {

    printf("%s \n", this->ID);

    printf("%s \n", this->Name);

    printf("%s \n", this->Email);

    }

    void Client_Free(Client* this) {

    free(this->ID);

    free(this->Name);

    free(this->Email);

    free(this);

    }

    Client* NewClient(const char* ID,const char* Name,const char* Email) {

    Client* Constructed = malloc(sizeof(Client));

    Constructed->ID = malloc(Length(ID) * sizeof(char));

    Constructed->Name = malloc(Length(Name) * sizeof(char));

    Constructed->Email = malloc(Length(Email) * sizeof(char));

    Constructed->ID = (char*)ID;

    Constructed->Name = (char*)Name;

    Constructed->Email = (char*)Email;

    Constructed->ShowClient = Client_ShowClient;

    Constructed->Free = Client_Free;

    return Constructed; //Apparently if all I do in this function is allocate the return type it just returns that without the need to call return #Spooky!

    }

    int main (void) {

    Client* Carb = NewClient("465798132", "Potato", ["CharliePotato@carbohydrates.com](mailto:"CharliePotato@carbohydrates.com)");

    Carb->ShowClient(Carb);

    Carb->Free(Carb);

    }

    Ubuntu 18.04 - 64 Bits - gcc 7.4.0

    Been toying around with function pointers and...

    This return erros (double free or corruption) or (invalid pointers). And if I don't free the memory Valgrind says there are leaks so...

    Kinda of stuck, any help would be appreciated.

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

    Need help to handle password recovery on a website

    Posted: 10 Jan 2020 01:42 AM PST

    I am developping a website for a company during my 6 months internship and I'm facing an issue regarding password recovery process. There will be an admin account that will manage others user accounts. It will be able to modify user password if they forget their password. However I can't find a way for admin to recover their password if they ever forget it. Since I'll leave the company in a few weeks, I can't be the one reseting the admin password whenever it is required.

    Do you have any idea of a secure automatic process that allows them to retrieve their password ?

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

    Machine Learning and Sport Video Games Question

    Posted: 10 Jan 2020 01:26 AM PST

    When I was growing up and I would play video games such as Madden, NBA 2K, etc I always enjoyed the media headlines (news headlines and later tweets) you could read about people's reactions to what happened in game. This brought about a great deal of immersion for me, and I was wondering if with machine learning maybe one day sports video games could provide a new level of immersion with full (not necessarily super in-depth) media articles breaking down games or team dynamics? I understand machine learning is capable of so much more, but this also seemed like something a lot of people would enjoy.

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

    How to write a bot that auto posts to instagram

    Posted: 10 Jan 2020 01:10 AM PST

    Hey all,

    I was wondering if anyone might have an idea on how to create a bot to auto post images to an Instagram account. I have spent the afternoon playing around with some python bots but seem to run into a similar error each time (it appears as though the unofficial api used by most of these bots has been blocked by instagram?)

    There are a couple of instagram account i know of which seem to still be using a bot to auto post. Any ideas how/if i could do this?

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

    No comments:

    Post a Comment