Programming

Running interactive program from within python

Learn Programming - 45 min 14 sec ago

I've been stuck on this for quite some time now. Any help from you guys is greatly appreciated.

Checkout the question here : https://stackoverflow.com/questions/50434204/running-interactive-program-from-within-python

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

Reordering a list of tuples applying reordering rules to their second element

Learn Programming - 56 min 15 sec ago

Let's assume we have:

[('The', 'DET'), ('red', 'ADJ'), ('window', 'NOUN'), ('is', 'VERB'), ('closed', 'VERB'), ('.', 'PUNCT')]

It is a list of tuples such that their first element is a word of a sentence (in this case, 'The red window is closed.'), and the second its grammatical category (or tag).

Suppose we have the following rule:

  1. [('ADJ', 'NOUN'), ('NOUN', 'ADJ')]

This says that if we have an ADJ immediately followed by a NOUN (in this example, 'red', and 'window'), we should reorder them so that the NOUN is immediately followed by the ADJ. The result of applying rule 1 to the sentence would then be:

[('The', 'DET'), ('window', 'NOUN'), ('red', 'ADJ'), ('is', 'VERB'), ('closed', 'VERB'), ('.', 'PUNCT')]

Any one has an idea of how to automatize this for any number of other rules and sentences? Or even just some basic strategy would help, really.

Any help would be appreciated.

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

[Java] How to create a collection of objects with custom comparator?

Learn Programming - 58 min 25 sec ago

I am wanting to create a collection of objects and then implement some custom methods as well as sort this collection.

The objects I'm working with are playing cards, and I am wanting to create a "hand" of five cards and sort these by their rank. I would then want to compare two "hand" objects with each other to determine the winning hand. To accomplish this, I am thinking it would be best to create a "hand" object as well where I can implement these custom requirements. My confusion comes when I am trying to use the "card" object within the "hand" object.

The card object makes sense to me as there are two attributes each card has, being the "suite" and "rank". The hand's only attribute would be five "card" objects, so how do I represent this in the code? Am I approaching this the correct way?

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

Algorythm analisis help

Learn Programming - 1 hour 4 min ago

So I've been given this assignment in my class and I have literally no idea, what am I supposed to do. Here is the question: https://prnt.sc/jkbmz6 Any advice is appreciated!

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

Is it possible to learn Computer Science on your own?

Learn Programming - 1 hour 9 min ago

Hey.

As the title says, is it possible to learn Comp Sci on yours own? I am interested in Games Development, design, programming and I have a year of Games Design under my belt. To be honest I didn't learn anything and I would like a source for learning comp sci for complete beginners ( if it's possible of course ).

Or is it better to go to Uni again and just transfer from Games Design to Comp Sci?

I would like to slowly learn by myself, I don't care that much ( I still do but it's not a decisive part ) about the diploma as long as I can learn everything by my self.

Thank you!

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

C++ / OpenCV - Pink freezup after about 5-6mins/10000 frames?

Learn Programming - 1 hour 19 min ago

Hi guys

I've typed up this program, featuring OpenCV 3.4.1, which plays Turretz, an Android game. I'm using the BlueStacks android emulator in Windows 10. It does the following at 30Hz:

  1. Get pixels of the BlueStacks application window using hwnd2mat()
  2. Process pixels using OpenCV functions, eg. inRange(), erode(), bitwise_or() and store the result in finalmask[step]
  3. Merge together the masks from the last PERSIST frames and store in finalmask[PERSIST]
  4. Find the largest black square in finalmask[PERSIST] using kadane() (which uses Kadane's algorithm as you can guess)
  5. Move the player to the centre of this square.
  6. Sleep for the remainder of the 33ms.

The program seems to error out after about 5 minutes of runtime, or after about 10000 iterations.

Here's an 8MiB video showing the error (happens 8 seconds in). I don't know how else to explain how it breaks. Ideally I'd like this program to run for hours, maybe even days, but obviously that's not possible if it crashes after 5 minutes :p

What needs to be changed to improve this program? I appreciate your time spent reading/helping :) Please let me know if any more info (eg. debug reports) is required.

Code was typed in VS2017: here's my singular source file below (~300 lines). Excuse my lack of commenting - I'll try my best to add them in the near future.

I've also asked on StackOverflow here.

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

Why not just read MDN Tutorials?

Learn Programming - 1 hour 24 min ago

I have tried Odin Project, and FreeCodeCamp's lessons, (Don't mistake, FCC is utterly amazing for it's project ideas), but everything I learned through their lessons was summed up better and more precise just in the MDN tutorials. Dude, I'm reading through the CSS layout section of MDN and it's wording it in the best way I've seen so far, (compared to multiple udemy courses, and other online tutorials). Really, you should all give it a try, I know it's much less glamorous looking, but just read it and you'll see.

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

I'm starting a blog.. Let me interview you

Learn Programming - 1 hour 38 min ago

Hey Guys,

I’m a fourth-year business student and going into the second year of being a computer science student. I was programming before I entered into the computer science program at my university and being self-taught in web dev and now experiencing some of a comp sci degree I’m a bit disappointed. I feel a lot of what we learn is outdated and some of the teachers have really let me down. An example is there is a Web Technologies course offered but HTML5 is only covered in the last week of lectures. Talking to some people in the industry I know that HTML5 is becoming the standard they use. I have begun wondering if a degree is as useful as I once thought it was.
 

  I’m starting an initiative called #EmployYourself which encourages people my age 19-25 to take business risks in the most opportune years of their life and work for yourself as if you’re working for someone else. I personally turned down a few job offers this summer to learn programming, I spend 5+ hours each week day learning about web dev. Each week I’ll be releasing blog post on what I learned and other post like useful free resources and whatever else I can come up with.
 

  I had this idea that each week I’d love to release an interview from someone in the industry talking about their personal experience with coding. They’re perspective on self-taught vs a degree and what someone should be doing so they can enter the workforce and be as prepared as possible.  

  This is something I am putting a lot of time into and really hope to help a few people. If you’d be open to answering a few questions we can have a sit down skype or google hangouts call whenever works for you! Excited to hear from you guys.

 

I’m launching my blog on June 4th!   Edit: I tried to keep this post as short as possible. Any additional questions don't be afraid to ask

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

Storing objects in a mysql / phpmyadmin database [php]

Learn Programming - 1 hour 50 min ago

Hi,

Put simply: how would one store information where the number of fields isn't known? For example, a user inputs school classes and an associated grade as many times as they want, and I want to store the name of each class and the grade the student received for that class in a MySQL / phpMyAdmin database under the student's name.

I currently have a data structure a bit like this in my php code, but I need a way of storing it all in a database:

table_students[

student{

student_name = ""

classes[

class{

class_name = ""

class_grade = ""

}

]

}

]

Please tell me if there is any other information I can provide! I'm sorry if my question is too vague, I'll try re-stating it if necessary.

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

Starting to learn python, just seems like a more complicated bash

Learn Programming - 1 hour 51 min ago

I am new to programming in general, and decided to start learning python. I am about halfway thru “Automate the boring stuff with python” and am learning it pretty well, moving along at a decent pace. But so far it seems everything I can do in python is just another shell script.

Before I developed an interest in learning a programming language, I was already proficient in bash and writing shell scripts- such as bootstrapping a configured OS and environment, interactive scripts, wrappers around other programs, etc. I know most developers start with formal languages first and then start working with the shell, I just happened to be very proficient with it beforehand.

Should I continue learning python or should I move to a lower level compiled language that is different from the shell? I feel very confident in my scripting abilities and am just learning as a hobby, but don’t want to spend too much time doing repetitive things. Any advice is welcome, thank you.

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

Web API + Azure/Amazon Queue + Lambda/Function = overkill?

Learn Programming - 1 hour 55 min ago

I need to develop an application for a client that needs serious ability to scale. This will be used for emergency situations - think tsunamis, earthquakes, etc.

For the sake of simplicity, lets say that the app posts form data to be stored in a NoSQL table. Email notifications will be sent.

As it stands, the stack is proposed as follows:

  1. Asp.net Core UI (using service pattern)
  2. Asp.net Web API (also service pattern, receive data from UI, send to queue)
  3. Azure Queue (store info temporarily)
  4. Azure Function (Dequeue and store data in dB and send emails)

With the RESTful API being a separate application, does that make the queue + serverless overkill? I think there's good arguments for both "yes" and "no," but I'm curious what others might think about it.

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

How to keep yourself motivated to learn programming

Learn Programming - 2 hours 20 min ago

Here is the problem. A lot of guys just start learning programming and just quit after some time like a 6-7 months. And if you aren't studying in university/college or special high school it is hard to stay motivated and to study systematically.

What you guys do to stay motivated and to get forward.

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

Get items from SQL using PHP

Learn Programming - 2 hours 27 min ago

I have never done php before so I really don't know much about how it works having only done C++ and Java before. I need to get all the items in my current sql database and then allow them to be shown in my Android App. My lecturer has given us some basic php code to use however it returns a lot more data than necessary. This is the php code:

https://pastebin.com/eFQHRXzW (Sorry reddit formatting confuses me) This returns: https://pastebin.com/04iuJEN9 However I don't need all this data such as the words "brand" "age" etc. Is there a way to change my php code so it returns the actual value stored in each column separated by a space with each new row of the table being on a new column?

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

I am stuck after planning my web application...

Learn Programming - 2 hours 45 min ago

I have created a simple plan of the project. I have sketched the main part of the web application and am ready to begin coding (I have never coded before and have spent the past few weeks reading and watching videos on HTML, CSS and JavaScript).

I have my Sublime Text 3 open and ready to go. But then I just freeze because I have no idea where to start.

A little advice would suffice!

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

How to make pygame read inputs,scroll a background,and make a sprite jump in an arc?

Learn Programming - 2 hours 49 min ago

I have a sprite that I wish to move across a scrolling screen by pressing keys on a keyboard .How do I do so,while scrolling a background containing platforms that can be jumped on?

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

Unable to update database with drop down using AJAX on Ruby on Rails

Learn Programming - 3 hours 8 min ago

I have a Ruby on Rails project set up and I am trying to update my database using a drop down list - I am using AJAX for this since I was advised that it would be one of the ways to get this accomplished. However, the database is not getting updated, and since I am new to AJAX, I am unsure into what has to be done. I have a show.html.erb, data.php, and data.js.

show.html.erb (the drop down list only):

<%= javascript_include_tag "/assets/data.js" %> <%= form_for(@klass) do |k1| %> <td> <%= k1.select :id, Klass.all.map {|k2| [k2.model, k2.id]}, :prompt => "Select a class", :class => "select", remote: true %> </td> <% end %>

Data.php:

<? php try{ $id = $_GET['id']; $klass_id = $_GET['klass_id'] $con = mysql_connect("localhost", "root", "root"); mysql_select_db("robotr", $con); mysql_query(" UPDATE enrollments SET klass_id = '$klass_id' WHERE ID = '$id' "); } catch (Exception $e){ echo $e -> getMessage(), "\n"; } ?>

Data.js:

$(document).ready(function(){ $('.select').change(function() { id = $(this).parent().attr('id'); klass_id = $('.select option:selected').val(); var request = $.ajax({ url: "/assets/data.php", method: "GET", data: {id : id, klass_id : klass_id }, dataType: 'html' }); request.done(function() { alert("Class successfully updated"); }); }); });

I thank you in advance for your help.

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

Pages