• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Nice! This motivated me to figure out how to use cabal to install the required packages so I could run your code. The Hilbert curve option only drew a single horizontal line, but the other two seemed to work as intended.

I got curious about Data.List.Stream aka stream-fusion. Googled a bit, and learned it's a faster drop-in replacement for Data.List, but hasn't been able to replace the original in the standard library due to some situation where the stream-fusion doesn't yet perform adequately. Since stream-fusion is incompatible with the list comprehension syntax, I don't see the point of using it if you don't actually need the extra perf. Are you using it out of habit?

Yeah, the Hilbert curve is broken for some reason, I'll have to take a closer look at that. As for stream-fusion, I mostly just wanted to try it out to see if it improved performance. (it didn't really)
 
My local community college has a "Computer Programming Certificate." It consists of the following: C#.net • Visual Basic.NET • Introduction to JavaScript Programming
• JavaScript Applications • XHTML. I'm not sure if some of those like the C# are simply intro courses or not, but it probably costs well over 2 grand. As someone starting from scratch, does this sound like a worthwhile investment career wise?
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I'm having difficulty with a Java Swing concept that I can't seem to find information about in my textbook or online. I'm sure it's out there, I just haven't been able to find it.

My professor wants me to create a GUI that displays lines and circles as a tic tac toe board. That is simple enough, but he wants it to scale based on the size of the window.

I have no idea what to implement or code in order to make it repaint based on window size.
Could anyone help me out with that?
 

NotBacon

Member
I'm having difficulty with a Java Swing concept that I can't seem to find information about in my textbook or online. I'm sure it's out there, I just haven't been able to find it.

My professor wants me to create a GUI that displays lines and circles as a tic tac toe board. That is simple enough, but he wants it to scale based on the size of the window.

I have no idea what to implement or code in order to make it repaint based on window size.
Could anyone help me out with that?

you could call getContentPane().getSize() on your JFrame and programmatically define your shapes and lines?
 

hateradio

The Most Dangerous Yes Man
I have no idea what to implement or code in order to make it repaint based on window size.
Could anyone help me out with that?
Do you start by having a default width/height for your frame? If you do, then you should make all your drawings relative to that. Eg, if you were going to draw two vertical lines, one should be drawn about 33% of the height down, the other about 66%. So you'd do width * .33 and width * .66 for the positions where you'd draw them.

You can then add a listener which repaints things when the size is changed.

http://docs.oracle.com/javase/tutorial/uiswing/events/componentlistener.html
 

Nesotenso

Member
messing with the key parameter in the sorted function in python, trying to understand it.

can someone tell me if I can use key to add 2 to each element in the list?

Code:
numbers = [ 1, 33, 22, 44, 55, 66]

print (sorted (numbers, key = lambda ....
 

Water

Member
My local community college has a "Computer Programming Certificate." It consists of the following: C#.net • Visual Basic.NET • Introduction to JavaScript Programming
• JavaScript Applications • XHTML. I'm not sure if some of those like the C# are simply intro courses or not, but it probably costs well over 2 grand. As someone starting from scratch, does this sound like a worthwhile investment career wise?

Depends on how good the teaching and teachers are, how deeply they cover things, how big an expense "well over 2 grand" is to you, what type of learner you are, what your career goals are, what your life situation / schedule is etc. I'd expect the value of the certificate itself to be next to nothing.

I don't find the list of topics promising. It's a bunch of different technology that seems to have a web programming focus. Nothing on the list is something I'd use to teach programming from scratch, and the variety is a problem in itself. The vibe I get is "let's make you sort-of employable in a specific programmer role as fast as humanly possible by populating your CV with many pieces of tech". Now, many people actually do make a living in programming with a wide and toe-deep skillset, and might do decent work in their niche as long as they stick to what's familiar and apply standard solutions. This is... okay, I guess, if all you want is to be employed.

If you want to be a good programmer of any sort, you need deep understanding of programming. You reach that not by scraping the surface of a bunch of languages and technologies, but by drilling deep and building complex things. Learning some computer science theory helps. The curriculum you optimally want to have for this path is Bachelor's in CS or equivalent; they typically force you to build some interesting things in practice in addition to covering the theory. After you have a decent amount of programming skill, learning new pieces of tech is something you can and will easily do on your own. You can of course also learn this stuff on your own, but having professional support would be much more helpful with this actually-hard material than when learning how to push out a webpage with some Javascript and XHTML.

If an actual CS degree or equivalent live classes with proficient teaching are not an option, there's a staggering amount of brilliant quality material on programming out there these days, including full CS courses with video and exercises for free. Plus forums and IRC channels for free peer support. A tutoring arrangement of some sort to help you take advantage of the above might also be worth it.
 

miniMacGuru

Neo Member
messing with the key parameter in the sorted function in python, trying to understand it.

can someone tell me if I can use key to add 2 to each element in the list?

Code:
numbers = [ 1, 33, 22, 44, 55, 66]

print (sorted (numbers, key = lambda ....

The key argument is used when you need to pull one piece of data out of a more complicated data structure, but it won't change the elements. It lets you do something like sort a list of pairs by the 2nd value in each pair.

Code:
numbers = [[1,5], [2,4], [3, 3], [4, 2], [5,1]

#print sorted by the first number in each pair (asc)
print(sorted(numbers, key=lambda x: x[0]))

#print sorted by the 2nd number in each pair (asc)
print(sorted(numbers, key=lambda x:x[1]))

If you want to run the same modification on a list in python, you could use list comprehensions:
Code:
numbers = [1,2,3,4,5]
bigger = [x + 2 for x in numbers]
#bigger is now [3,4,5,6,7]
 

Nesotenso

Member
The key argument is used when you need to pull one piece of data out of a more complicated data structure, but it won't change the elements. It lets you do something like sort a list of pairs by the 2nd value in each pair.

Code:
numbers = [[1,5], [2,4], [3, 3], [4, 2], [5,1]

#print sorted by the first number in each pair (asc)
print(sorted(numbers, key=lambda x: x[0]))

#print sorted by the 2nd number in each pair (asc)
print(sorted(numbers, key=lambda x:x[1]))

If you want to run the same modification on a list in python, you could use list comprehensions:
Code:
numbers = [1,2,3,4,5]
bigger = [x + 2 for x in numbers]
#bigger is now [3,4,5,6,7]

just needed to know that, so it sorts lists, dictionaries

thanks.
 

Nesotenso

Member
I am getting an error in IDLE when I try to run a simple client server program. The following is the example code from a site

client side
Code:
import socket               # Import socket module

s = socket.socket()         # Create a socket object
host = socket.gethostname() # Get local machine name
port = 1234               # Reserve a port for your service.

s.connect((host, port))
print (s.recv(1024))
s.close                     # Close the socket when do

server side
Code:
import socket               # Import socket module

s = socket.socket()         # Create a socket object
host = socket.gethostname() # Get local machine name
port = 1234                # Reserve a port for your service.
s.bind((host, port))        # Bind to the port

s.listen(5)                 # Now wait for client connection.
while True:
   c, addr = s.accept()     # Establish connection with client.
   print ('Got connection from', addr)
   c.send('Thank you for connecting')
   c.close()                # Close the connection

I run server.py first and then client.py and I am getting this error

Code:
Traceback (most recent call last):
  File "C:\Python32\client.py", line 7, in <module>
    s.connect((host, port))
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it

can anyone help me out and see what is going wrong here?
 

Deadly

Member
Post what you got.
Actually managed to figure it out but thanks!

New question though, is it possible for a single textbox be used to search all columns of a database? When I tried it out, I wrote the queries and it generated me 9 textboxes (one for each column). What I'd like to do is just merge those into one.
 
Actually managed to figure it out but thanks!

New question though, is it possible for a single textbox be used to search all columns of a database? When I tried it out, I wrote the queries and it generated me 9 textboxes (one for each column). What I'd like to do is just merge those into one.

Are you doing this visually? I don't know C#, but this question kinda doesn't make sense.
 

CrankyJay

Banned
Actually managed to figure it out but thanks!

New question though, is it possible for a single textbox be used to search all columns of a database? When I tried it out, I wrote the queries and it generated me 9 textboxes (one for each column). What I'd like to do is just merge those into one.

Of course it's possible, I don't know what your set up is that it's auto-generating textboxes for you.
 

Deadly

Member
I was following this video guide: https://www.youtube.com/watch?v=Sg0xauiBkuQ&list=PLS1QulWo1RIZz2vLIlj0Ra26IowB_vwmf&index=6

To sum it up he uses the query builder that generates a textbox and button for the search but then he creates his own textbox and button but takes the code from the generated button to his own button and changes a part for it to affect his new textbox. I followed the steps but what I did was I'd input LIKE @ColumnName + '%' for all of my columns but that ends up generating a textbox for each column. So when I tried creating my own button this method couldn't work anymore.

I'm using Visual Studio if that helps with anything.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
you could call getContentPane().getSize() on your JFrame and programmatically define your shapes and lines?

Do you start by having a default width/height for your frame? If you do, then you should make all your drawings relative to that. Eg, if you were going to draw two vertical lines, one should be drawn about 33% of the height down, the other about 66%. So you'd do width * .33 and width * .66 for the positions where you'd draw them.

You can then add a listener which repaints things when the size is changed.

http://docs.oracle.com/javase/tutorial/uiswing/events/componentlistener.html

I read over your advice, and it was working for my first attempt. I was able to get the lines set up correctly and they scaled based on the frame. But I found that just using JPanels for the different cells would produce what he was asking for as far as layout in a somewhat simpler fashion since he wasn't actually asking for the cell division lines to be drawn.

The problem I am running into now though is that when I'm attempting to draw the X's, O's and blank cells it's just producing a tiny little white box in the panel. I'm at a loss as to what is causing this. I've remade this over twice so far with different approaches and have yet to get the drawing portion working correctly.

The assignment is not asking for any logic as far as being able to play the game. It just wants 9 cells that have an X, O, or nothing drawn based on a RNG. It also needs to scale based on the window size, but that's working so far for the panels. Not sure how it will work with the actual drawings yet since I haven't gotten those to work.

I'll post my code and a picture of what my frame looks like. If anyone with Java Swing experience could give me some insight and point me in the right direction it'd be greatly appreciated. I'm really frustrated with this assignment, but I feel like I'm just missing something really simple.

http://pastebin.com/pgHecQ6x

5Row7ze.png
 

Rapstah

Member
Image classes usually have some sort of built-in scale method. I can't find the images in your posted code though, is it the latest version?
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Image classes usually have some sort of built-in scale method. I can't find the images in your posted code though, is it the latest version?

Yes, it's the latest version.

I'm not using any images, just trying to draw lines and ovals onto the JPanels.
 

Rapstah

Member
Yes, it's the latest version.

I'm not using any images, just trying to draw lines and ovals onto the JPanels.

getHeight() and getWidth() in your NewCell paintComponent() method are equivalent to this.getHeight() and this.getWidth(), that is the height and width of the shape you're trying to draw inside of a given cell and not the height and width of the cell.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
getHeight() and getWidth() in your NewCell paintComponent() method are equivalent to this.getHeight() and this.getWidth(), that is the height and width of the shape you're trying to draw inside of a given cell and not the height and width of the cell.

I just edited it to:
Code:
g.drawLine(0, 0, 50, 50);
but it produces the same result. The little white box and a line through it. It seems like it's creating a panel on top of the panel, then drawing to that. Instead of drawing directly on the JPanel like what I want.
 

Rapstah

Member
I just edited it to:
Code:
g.drawLine(0, 0, 50, 50);
but it produces the same result. The little white box and a line through it. It seems like it's creating a panel on top of the panel, then drawing to that. Instead of drawing directly on the JPanel like what I want.

Oh, wait, I see what's going on here. NewCell is an extension of JPanel. That's the JPanel you're drawing into. For some reason its default size is 10x10. If you do this.setSize(new Dimension(1000000, 1000000); in the paintComponent method of NewCell, you'll see the lines be able to be a lot larger.

This is just an example. I'd suggest you make the coloured cells an extension of JPanel instead and then draw lines in their paintComponent method.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Oh, wait, I see what's going on here. NewCell is an extension of JPanel. That's the JPanel you're drawing into. For some reason its default size is 10x10. If you do this.setSize(new Dimension(1000000, 1000000); in the paintComponent method of NewCell, you'll see the lines be able to be a lot larger.

This is just an example. I'd suggest you make the coloured cells an extension of JPanel instead and then draw lines in their paintComponent method.

Ok, I'm going to try this. Thanks!

edit: Successful! Confirmed, do not enjoy Swing.
Code:
       JPanel cell1 = new JPanel() {
            int value = LabZehn.generate();
            @Override
            protected void paintComponent(Graphics g) {
                if (value == 1) {
                    g.drawLine(10, 10, getWidth()-10, getHeight()-10);
                    g.drawLine(getWidth()- 10, 10, 10, getHeight()-10);
                } else if (value == 2) {
                    g.drawOval(10, 10, getWidth()-10, getHeight()-10);
                }
            }
        };
 

Heysoos

Member
Is anyone here familiar with Verilog?

I'm doing a project for class and I keep getting an error on this part:

Code:
module encoder(KEY, BCD);
	input [3:0] KEY;
	output reg [3:0] BCD;
 
	always@(KEY)
		case(KEY)
			4’b0111: BCD=4'b0011;  		
			4’b1011: BCD=4'b0010;
			4’b1101: BCD=4'b0001;
			4’b1110: BCD=4'b0000;
			default: BCD=4'b1111;
		endcase
	
endmodule

and this is the error:
B4xPnu5.png


Syntax error, but I'm not sure exactly what I'm doing wrong. Might not be the right place to ask, but hoping someone can give me some tips.
 

arit

Member
Is anyone here familiar with Verilog?

I'm doing a project for class and I keep getting an error on this part:

Code:
module encoder(KEY, BCD);
	input [3:0] KEY;
	output reg [3:0] BCD;
 
	always@(KEY)
		case(KEY)
			4&#8217;b0111: BCD=4'b0011;  		
			4&#8217;b1011: BCD=4'b0010;
			4&#8217;b1101: BCD=4'b0001;
			4&#8217;b1110: BCD=4'b0000;
			default: BCD=4'b1111;
		endcase
	
endmodule

and this is the error:
B4xPnu5.png


Syntax error, but I'm not sure exactly what I'm doing wrong. Might not be the right place to ask, but hoping someone can give me some tips.

I don't know verilog so I could be wrong, but at least here in the codeview of this forum it looks like you are using two different types of ' per line when declaring the bitwidths.
 

Heysoos

Member
I don't know verilog so I could be wrong, but at least here in the codeview of this forum it looks like you are using two different types of ' per line when declaring the bitwidths.

Jesus Christ... I never freaking noticed that. I've been on this stupid thing for two hours for such a stupid thing. ><
 

Haly

One day I realized that sadness is just another word for not enough coffee.
This course is kicking my ass.

I'm on the first week and I realize I barely understand what logarithms are. It's just another function to me.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
This course is kicking my ass.

I'm on the first week and I realize I barely understand what logarithms are. It's just another function to me.

Logarithms kick my ass as well. My professor always explained them as....wait...I tried typing it out, but I can't remember it myself.
Something about converting it into its exponential form.

That course looks interesting though, but I'd be lost instantly.
 
Hey programmingGaf! I have a program that performs Floyd's algorithm on a multi-dimensional array. The intersection represents the edges between the two points. It works as intended when tested on a 2x2, 3x3, 4x4, 5x5, 6x6, and 10x10 array of inputs. However, on a 20x20 array it failed my school's automated test. There are no extra numbers added, just the wrong answer. I would really rather not perform the algorithm by hand on paper because I know that it works within my program.

Does anybody see a design mistake? Am I not understanding something correctly?

Function to insert inputs into the array (ROLUMN is 20)
Code:
int graph::insert_node(int& weight, int& abort){
	static int i = 0;
	static int j = 0;


	//Add to row
	if(i < ROLUMN){
		//Avoid Floyd diagonal
	/*	if(i == j){
			i++;
		}*/
		adj_list[j][i].edge_weight = weight;
		i++;
		return abort;
	}
	//Next row
	j++;
	if(j < ROLUMN){
		i = 0;
		adj_list[j][i].edge_weight = weight;
		i++;
		return abort;
	}
	//No more nodes
	i = 0;
	j = 0;
	return -1;
}

Function that performs Floyd's algorithm.
Code:
void graph::algorithm(){
	int i = 0;
	int j = -1;
	int tmp;
	int pivot = 0;


	while(pivot < ROLUMN){
		//Algorithm within one pivot
		while(i < ROLUMN){
			if(adj_list[pivot][i].edge_weight > 0){
				if(i == j){
					continue;
				}
				j = 0;
				while(j < ROLUMN){
					if(adj_list[j][pivot].edge_weight > 0 && j != i){
						tmp = adj_list[j][pivot].edge_weight +
						   	adj_list[pivot][i].edge_weight;
						if(tmp < adj_list[i][j].edge_weight ||
								adj_list[i][j].edge_weight == -1){
							adj_list[i][j].edge_weight = tmp;
							adj_list[j][i].edge_weight = tmp;
						}
					}
					j++;
				}
			}
			j = -1;
			i++;
		}
		i = 0;
		pivot++;
	}
}
 

Tristam

Member
Logarithms kick my ass as well. My professor always explained them as....wait...I tried typing it out, but I can't remember it myself.
Something about converting it into its exponential form.

That course looks interesting though, but I'd be lost instantly.

The log of a number is the number that you would need to raise some base (usually 10, for natural log) to in order to produce that number.

E.g., log(1000) = 3 -- again, assuming base of 10 -- since 10^3 = 1000.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
It's just hard for me to intuit that when I look at a logarithm.

Like lg(4). That's 2. But I need to actually think about it, whereas 2^2 is instinctually 4 to my eyes.

Something more complex like:
i6tMut3G5KZ5z.png

And my eyes just glaze over.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
The log of a number is the number that you would need to raise some base (usually 10, for natural log) to in order to produce that number.

E.g., log(1000) = 3 -- again, assuming base of 10 -- since 10^3 = 1000.

That's it! Thanks.

I knew it was something like that, but when I started trying to recall it the memory left me.

It's just hard for me to intuit that when I look at a logarithm.

Like lg(4). That's 2. But I need to actually think about it, whereas 2^2 is instinctually 4 to my eyes.

Something more complex like:
i6tMut3G5KZ5z.png

And my eyes just glaze over.

And it's gone...
 

Slavik81

Member
If anyboy has any interest in the programming language Rust, a good guide came out recently (it's still being worked on):
http://rustbyexample.com/

There's also this series, which is only on part 4 so far Rust for C++ programmers. The links to other parts are on the right.

I think this language is going to be big in a few years.
I read through all the articles I find about it, though I haven't actually used it yet. Rust looks like a language I might actually use in place of C++ some day. It looks beautiful.

I should really take it for a spin. It and Haskell are on my todo list.
 

leroidys

Member
I'm finally loving and appreciating how great VIM is. Best editor world.

I'm forcing myself to learn it this quarter, and have made it over the initial hump where it's no longer a barrier to productivity. I like being able to essentially multiply commands, but still prefer sublime for it's modern gui, autocomplete, dir lists, and some other features.

Writing code in vim does make me feel like a badass though, and seems to be somewhat easier on the wrists.
 

phoenixyz

Member
Does anyone know a good resource to learn regular expressions? I really need to step up my game a little bit in that area.

I like being able to essentially multiply commands, but still prefer sublime for it's modern gui, autocomplete, dir lists, and some other features.
If you are comfortable with ST, why do you feel the need to learn vim? Nerd cred?
 

leroidys

Member
Does anyone know a good resource to learn regular expressions? I really need to step up my game a little bit in that area.


If you are comfortable with ST, why do you feel the need to learn vim? Nerd cred?

Yeah, basically just to add to my skill set. It's also nice to be able to make quick edits to code remotely.
 
I made this little program to count lines of code (and comments and blank lines) in a directory and all of its subfolders. It's in C++ and I'm pretty satisfied with the performance (counts all of the UE4 source in under a second) but I'd like to know if there's things that could be improved as far as C++ style and design go. I tried to stick to C++11 things as much as possible. I used Boost in a few places (recursive directory iterator and some string algorithm things), so if you want to compile it, you need that (and CMake).

https://github.com/GyrosOfWar/cloc-cpp
 

Anustart

Member
If I had a beginning and end point, how could I calculate an arc between the two? Trying to accomplish something in Unity (c#) that would give me an arc (arbitrary arc, doesn't need to be anything specific) and don't know how to go about it.
 
Top Bottom