• Breaking News

    Monday, June 11, 2018

    Weird isPrime() function I stumbled upon Ask Programming

    Weird isPrime() function I stumbled upon Ask Programming


    Weird isPrime() function I stumbled upon

    Posted: 11 Jun 2018 06:37 PM PDT

    I read that

    bool isPrime(int n) { if (n == 2 || n == 3) return true; return (pow(2, n - 1) % n) == (pow(3, n - 1) % n) == 1; } 

    successfully returns true for prime numbers.

    I don't understand how this works and whether it's true. I haven't found a counterexample yet either.

    Someone please shed some light.

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

    [Java] Newbie question about sharing class between files

    Posted: 11 Jun 2018 05:30 PM PDT

    Hello,

    So hopefully this will be a quick and painless question:

    I have two java files in the same package: lets say First.java and Second.java.

    First.java contains subclass "Nodes" which I want to use in Second.java too. Can't figure out how to do that. Basically it's a linked list structure I used in one java file but also want to use it in the second file.

    The data will not be shared! As in I just want the subclass to be implemented in the second file so I can create new linked lists; not the linked lists I created for the first file. I could add the same subclass in the second file; but that's not allowed.

    Any help will be appreciated. Thank you for reading!

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

    Reference for HTML Javascript

    Posted: 11 Jun 2018 05:37 PM PDT

    I just don't really know how to word it, and google isn't working for me. Does anyone know of a reference for HTML Javascript things such as getElementById and style.fontSize etc.

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

    What programming readability techniques/tips you would like to have known before

    Posted: 11 Jun 2018 07:52 AM PDT

    Hi,

    Some years ago I learned some techniques for code readability, one of them is early return.

    for example: Instead of writing

    function doSomething($array_of_values) { if(!empty($array_of_values) { ... do something ... return true; } else { return false; } } 

    Your function is embebed inside an if statement, the else only returns a value so you can do an early return and avoid the if

    function doSomething($array_of_values) { if(empty($array_of_values) { return false; } ... do something ... return true; } 

    This second chunk of code is easier to read, understand, etc. I found techniques like this (if they can be called techniques) to be really usefull, and I think my code started to be more readable and cleaner once I started following tips like those.

    What other tips like this exists who let you get better code?

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

    Help loading an unknown file type in JavaScript or R to produce a matrix?

    Posted: 11 Jun 2018 04:08 PM PDT

    To be honest I don't really know where to start. I'm trying to read an unknown file type that is produced by recording bat echolocations. I'm a biologist and as part of my job I monitor bat species distributions by recording bat calls across my field office. Each species has a unique call. Becuase the calls are unique, we can identify bats to species by their call. I'd like to automate the species ID. But in order to train a classifyier to classify the calls to species, I first need to be able to make something of the actual files we get. The devices that I use to record the calls provide this documentation on their calls. But I know nothing about reading custom file formats. It seems like they are literally reading through bites to make something. Ideally, what I want from the files is to produce a matrix (raster?). Ideally I'd like to be able to do this in the browser so javascript would be preferred. But I'm also a little familiar with R (found this, but it doesn't really do what I want I don't think). Any help would be greatly appreciated.

    You can find sample file here mid way down the page.

    Thanks in advance for any help you can provide.

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

    Setting up an application using Php backend React front

    Posted: 11 Jun 2018 04:57 PM PDT

    Hi everyone, I was really hoping you could help me, I have been given a project to create an application using Php and React, however, I more orientated to C# so am very much out of my depth, Where do I start to create application using Php and React, could someone walk me through what I should be doing, or have any resources on using React with Php (right from setup)? I would be very grateful, I just don't know where to begin, I have downloaded what applications would best assist me. Thanks guys.

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

    Code that could add "top" to the end of a URL when opening in a new tab?

    Posted: 11 Jun 2018 07:29 PM PDT

    I have no coding background, but I was wondering if it would be possible to make a Chrome Extension or just a hotkey on my keyboard to add "top" to the end of a URL when I click on a link so I can binge the top of random subreddits. Mainly because I'm lazy and don't want to wait for the default "hot" page to load and then click on "top" and then "of all time."

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

    Screenshoting in apps

    Posted: 11 Jun 2018 03:29 PM PDT

    I never used snapchat, but as i learned from all the posts you can see if someone screenshots conversation.

    I have very little programming experience so from my perspective it's strange that an app should have that information.

    Does app need to "know" screenshot will be taken to work properly as in:

    Phone: "I will now take a screenshot" App: "Ok let me dress up...Ready" Phone takes screenshot.

    Or phone just gives information of the sceenshot like:

    Phone: "Hey app, i have taken screenshot of you" App: "Ok thanks for the info"

    Thanks.

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

    elegant for loops ?

    Posted: 11 Jun 2018 02:35 PM PDT

    Is there an alternative way i can write in c++ :

     for (int x =1; x < cards[0].dx ; x++){ for (int y =1; y < cards[0].dy; y++) 

    i must write these a lot... i am using classes and stuff and each member function of a class has the double for ..more elegant way to implement..?

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

    Search for String in HTML File in Node.JS

    Posted: 11 Jun 2018 01:18 PM PDT

    I'm trying to create a search FAQ's for my website. I want to search my HTML files for the text they're searching for, and give the answer.

    Example:

    Bill searches for "What is the minimum quantity to order for noodles" and the search finds the noodle page and responds with "You need to buy 8 packs of noodles".

    What's the best way to do that? Or should I have all my text in my DB similar to Wordpress?

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

    Type of this "time" object?

    Posted: 11 Jun 2018 11:04 AM PDT

    "2018-02-12T21:08:03.000Z" is a time object i need to parse (in java, but i doubt the language matters). I receive this as a string. What is a easy way to turn this into a LocalTime/LocalDateTime object, or just turn this into a UnixTime (milliseconds) long?

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

    How important is consistency with spacing and operators?

    Posted: 11 Jun 2018 10:53 AM PDT

    I noticed that when making equivalences, I always put a space between the equal sign and both sides. So it looks like $x = $x.

    When I make comparisons or anything else, it goes $x<$y.

    A while back, when working on a project, someone criticized this, saying that this type of spacing would be maddening on any kind of collaboration. Just wanted to see if this was a sensitive subject like tabs vs spaces. Or if the guy was just being pedantic.

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

    Would it be possible to program a noise canceling app for bluetooth earphones?

    Posted: 11 Jun 2018 01:02 PM PDT

    So I was wondering, if it were possible to do the same thing like noise-canceling earphones but with an app?

    This app would then use a built-in microphone from a smartphone to record the audio. Then use that audio and program the "reversed" frequency from that audio and play it as music. All in realtime. Would that work?

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

    Alternative to Stack Overflow?

    Posted: 11 Jun 2018 04:58 AM PDT

    Don't get me wrong, Stackoverflow is a great site, I've found a lot of solution there, but most of the time when I tried to ask for a solution there, it's either downvoted to hell, or the mod closed down my question and direct me to the other topic that doesn't solve my problems at all.

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

    What was there before O-code?

    Posted: 11 Jun 2018 12:23 PM PDT

    I want to make a video on the history of coding, going from Python, to C, to BCPL to O-code, since the standard interpreter of Python is written in C, C compiles itself but it was first compiled with BCPL, and BCPL also compiles itself but uses O-code for that.

    My question is, once I reach O-code, what's next?, I find quite a bit of information about the O-code virtual machine, but that would be tangent to my topic, I want to know if there's anything more basic than O-code written in paper tapes, and if there is, if that other thing is the end, or if the rabbit whole continues.

    Thanks

    PD: I'm not an expert on Bootstrapping, but if anyone wants to explain me how was BCPL first compiled, I would be extremely thankful

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

    ASP.NET Core 2.0 Web API app with real-time messaging handled through socket.io on a separate nodejs server

    Posted: 11 Jun 2018 08:03 AM PDT

    Hi all,

    First of all thank you to anyone that reads this and is able to help. Apologies in advance if this is the wrong sub to post this in.

    Currently working on a web application built with DNC 2.0. Last time I worked regularly with C# was a few years ago but I'm faring pretty well.

    Anyways, I've got socket.io running on a separate node server that I'm using for a real-time messaging component, but I want to be able to log the messages to my database so that they can be loaded back when the user logs in to a different device.

    I just had a question on the implementation- while I'm not new to real-time messaging, I've never introduced logging into the mix. I understand that I could use signalr and keep things all on the ASP.NET app which would probably be easier to manage, but for this project I'd really like to continue using node for this component if possible.

    2 ways I was thinking of handling this:
    1) use sockets on the client for both sending and receiving; that is, send the message via sockets, node server hits an endpoint on ASP.NET to save the message. If ASP.NET returns an OK, node then broadcasts the message, client side socket listener receives the message

    2) only use sockets on the client for listening for new messages; that is, ASP.NET opens a connection to the node server on startup. POST the message to an endpoint on the ASP.NET side, if ASP.NET is able to successfully save it to the DB, then send the message to node. Node then broadcasts the message and the client side socket listener receives the message.

    Those are really the only two scenarios I can think of, but if anyone has any suggestions they'd be super appreciated!

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

    How to run a python script for multiple python files

    Posted: 11 Jun 2018 06:52 AM PDT

    I have a python script that removes unused imports. right now i have to specify the file for which I want to run the script on.

    I want to find a way to run this on any python files found in a folder and subfolders. How do I do this?

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

    Is clojure a good language for the goal of making money with programming?

    Posted: 11 Jun 2018 12:44 PM PDT

    Hi there, I am a student currently studying mathematics, and im beginning to specialise in category theory, so im keen to get into functional programming because from what ive seen functional programming is very related to category theory. Im aiming at earning money with programming, what are your thoughts on focusing mainly on functional programming as a way to create programs to make money?

    Thanks I really apprieciate any input

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

    Writing Maintainable Tests

    Posted: 11 Jun 2018 11:41 AM PDT

    As I first started testing in my career my tests were horrible, as to be expected. They were brittle, hard to maintain, and not isolated enough.

    I've learned/am learning how to use TDD to drive my design and learning paradigms like BDD/ATDD to improve the maintainability of my tests. However, it's still a challenge.

    I'm paraphrasing, but Kent Beck said that the toughest challenge in coding is writing maintainable, readable code that has tests that don't break when you refactor.

    Resources I've found helpful:

    1. Test-Driven Development by Kent Beck
    2. BDD in Action
    3. Any talks by Gary Bernhardt on testing (still need to buy a subscription to Destroy all Software to check out his full suite of stuff though). Also Sandi Metz.

    Do you guys have any other go-to resources?

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

    (osx) Can I make a folder undeletable, but the system still able to read it?

    Posted: 11 Jun 2018 07:01 AM PDT

    It's for the K9 porn blocker. I want to fix the main folder in place because my self-control is not the best lately, so I don't want to be able to delete it (maybe only by root, but fortunately idk how that works). I found a code in an old post that did lock it and didn't let me delete it whatsoever, but the system wasn't able to read the files and de-activated the K9 software. I tried the following:

    chmod -R +a "everyone deny delete,file_inherit,directory_inherit" "$folder" sudo chflags -R schg "$folder"

    I'd greatly appreciate any suggestions. Thanks!

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

    Parsing an indented language in Scala

    Posted: 11 Jun 2018 02:54 AM PDT

    Recently Ive been using Scala combinators to parse a basic language and it's been great. I would now like to move on to parsing an indented language.
    I managed to find one stack overflow question that has an example but that's all.
    Are there any resources for parsing an indented language with Scala combinators?
    Also are Scala combinators the best approach for this or are there any other more suitable libraries I should be using?

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

    How to properly format content taken out of Database using Jinja2 in Django?

    Posted: 11 Jun 2018 06:29 AM PDT

    I am trying to make a Web application in Django. It's going to be a personal blog, I made a Model including Title, Content and date time. I am using the admin panel to create those blogs. When I display content I'd like to format it, some of which will be actual code that should be enclosed in code tag. But the content I get, is delivered in a huge block of string, and I can't know which part is which. Should I restructure my model?

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

    Need Help, Search function for my private website project.

    Posted: 11 Jun 2018 03:07 AM PDT

    I have posted the question on stack overflow but alas no one thought of an answer I hope you guys can help me. The Link > https://stackoverflow.com/questions/50713784/have-to-search-a-query-on-a-database-such-as-a-name-and-spit-out-anything-that-i

    Thanks guys/girls.

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

    Thought this would be a good community to ask?

    Posted: 11 Jun 2018 06:45 AM PDT

    Need help with c++ for exams (

    Posted: 11 Jun 2018 04:05 AM PDT

    Hello World!! I am new to programming and i need some help with c++ when i am trying to execute this code there is a tons of errors can anyone help me?

    https://pastebin.com/1Aqjn1UG <------ The code :D

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

    No comments:

    Post a Comment