Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Zombywuf posted:

ORLY

That doesn't resolve the "IE Javascript debugging in Linux" issue, which is kinda the point. At the very least, you should be doing a pass of your site within Windows, and if there are problems, sometimes you have to suck it up and use Windows to have access to decent development tools for IE (unless you can get them working in WINE).

Adbot
ADBOT LOVES YOU

Zombywuf
Mar 29, 2008

Avenging Dentist posted:

That doesn't resolve the "IE Javascript debugging in Linux" issue, which is kinda the point. At the very least, you should be doing a pass of your site within Windows, and if there are problems, sometimes you have to suck it up and use Windows to have access to decent development tools for IE (unless you can get them working in WINE).

All the dev tools I've seen for IE have been plugins. It's possible (never tried it) that they will work under this setup.

Plank Walker
Aug 11, 2005
I've been having no luck finding out ways to connect to a mySQL database through C#. I'm working on a small app that needs to access a database on a remote server from a client machine. Every single article on mySQL and C# seems to assume that I'm running the app from the server, not the client. Here's what's tripping me up: (bolded area)

myConn = new OleDbConnection("Provider=NO IDEA WHAT TO PUT HERE;
Data Source= http://mysite.web???; Initial Catalog= user_db; User Id=root; Password=;");


All the examples I've found online use Provider=mySQLProv with no explanation as to what mySQLProv is. Is it something installed on the SQL server or is it just a parameter specifying that mySQL is used?

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Plank Walker posted:

I've been having no luck finding out ways to connect to a mySQL database through C#. I'm working on a small app that needs to access a database on a remote server from a client machine. Every single article on mySQL and C# seems to assume that I'm running the app from the server, not the client. Here's what's tripping me up: (bolded area)

myConn = new OleDbConnection("Provider=NO IDEA WHAT TO PUT HERE;
Data Source= http://mysite.web???; Initial Catalog= user_db; User Id=root; Password=;");


All the examples I've found online use Provider=mySQLProv with no explanation as to what mySQLProv is. Is it something installed on the SQL server or is it just a parameter specifying that mySQL is used?
mySQLProv is something installed on the client that it uses to communicate with a MySQL database.

Skulleye
Jul 31, 2004

Plank Walker posted:

I've been having no luck finding out ways to connect to a mySQL database through C#. I'm working on a small app that needs to access a database on a remote server from a client machine. Every single article on mySQL and C# seems to assume that I'm running the app from the server, not the client. Here's what's tripping me up: (bolded area)

myConn = new OleDbConnection("Provider=NO IDEA WHAT TO PUT HERE;
Data Source= http://mysite.web???; Initial Catalog= user_db; User Id=root; Password=;");


All the examples I've found online use Provider=mySQLProv with no explanation as to what mySQLProv is. Is it something installed on the SQL server or is it just a parameter specifying that mySQL is used?

I used this: http://csharp.codenewbie.com/articles/csharp/1433/MySQL_and_NET__Using_MySQLDriverCS-Page_1.html

I assume you just change localhost with the relevant address, though I have only tested it on my own computer.

xobofni
Mar 28, 2003
There's also the official one at http://dev.mysql.com/downloads/connector/net/5.1.html

Sample code:
code:
public void InsertRow(string myConnectionString) 
{
    // If the connection string is null, use a default.
    if(myConnectionString == "") 
    {
        myConnectionString = "Database=Test;Data Source=localhost;User Id=username;Password=pass";
    }
    MySqlConnection myConnection = new MySqlConnection(myConnectionString);
    string myInsertQuery = "INSERT INTO Orders (id, customerId, amount) Values(1001, 23, 30.66)";
    MySqlCommand myCommand = new MySqlCommand(myInsertQuery);
    myCommand.Connection = myConnection;
    myConnection.Open();
    myCommand.ExecuteNonQuery();
    myCommand.Connection.Close();
}

Numinous
May 20, 2001

College Slice
Can someone recommend me a book or books for learning C# and .Net? I've been coding Java, C, and C++ for a few years each but I need some help and some reference material for all of this new stuff.

csammis
Aug 26, 2003

Mental Institution
Check the book request / recommendation thread, or you can ask in the .NET Megathread for specific topics.

magicalblender
Sep 29, 2007
Why doesn't this program see the arguments I pipe to it?
code:
#showargs.c- prints each argument passed to it.
#include <stdio.h>

int main(int argc, char* argv[]){
        int i;
        for (i=1; i < argc; i++){
                printf("\n%s", argv[i]);
        }
        printf("\ndone.\n");
        return 0;
}
When I type "cat myfile | ./showargs", I expect it to print each line of myfile.
What really happens: nothing. argv is empty, I guess? Why is this?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
When you pipe commands, the piped data comes in via STDIN.

6174
Dec 4, 2004

magicalblender posted:

Why doesn't this program see the arguments I pipe to it?

First off, wrong thread.

Second, you misunderstand what the pipe does. It ties stdout of the first program to stdin of the second, it doesn't put stuff on the command line for the second program. If you printed values put to stdin in your showargs program you'd see the contents of myfile.

magicalblender
Sep 29, 2007

6174 posted:

First off, wrong thread.

Whoops v:shobon:v

Well, anyway, here's the solution I came up with, after my ignorance about piping had been corrected:
code:
#include <stdio.h>

int main(){
	char foo[100];
	while (scanf("%s", &foo) != EOF){
		printf("\n%s", foo);
	}
	return 0;
}
As a follow-up, why is it that "cat myfile | ./showargs" works, but "cat myfile | showargs" does not work? What is the significance of the dot and slash?

6174
Dec 4, 2004

magicalblender posted:

As a follow-up, why is it that "cat myfile | ./showargs" works, but "cat myfile | showargs" does not work? What is the significance of the dot and slash?

The dot and slash specify where to find the file "showargs". The "." means the current working directory, and the "/" is the standard directory separator. When those are not present the shell looks for the file "showargs" in the directories listed in the PATH variable (in the order they appear). Since the current directory is normally not part of the PATH, if you do not put the ./ the shell can't find "showargs".

more falafel please
Feb 26, 2005

forums poster

magicalblender posted:

Whoops v:shobon:v

Well, anyway, here's the solution I came up with, after my ignorance about piping had been corrected:
code:
#include <stdio.h>

int main(){
	char foo[100];
	while (scanf("%s", &foo) != EOF){
		printf("\n%s", foo);
	}
	return 0;
}
As a follow-up, why is it that "cat myfile | ./showargs" works, but "cat myfile | showargs" does not work? What is the significance of the dot and slash?

In Unix, when you use a command like "showargs", it tries to find a program called "showargs" in each directory in your PATH environment variable, and runs the first one it finds. Unlike in Windows, the current directory (which can be abbreviated as a dot) is not generally included in your PATH. You can also refer directly to a specific program, regardless of whether it's in your PATH, by specifying a full or relative path to it. So ./showargs means "showargs, in the current directory."

StickGuy
Dec 9, 2000

We are on an expedicion. Find the moon is our mission.

6174 posted:

First off, wrong thread.
Dealing with piped input is a pretty general programming question, which applies to more than just C/C++.

Orlen
Oct 25, 2005
custom user title
I'm doing some Haskell coursework and I've hit a dead end.

It's about tree structures. Here's the question:

quote:

Define a function pathEnum :: BTree a -> [Path] which takes as input a binary tree and returns the list of all the paths in the tree from the root to a leaf


Here are the relevant definitions:

data BTree a = Leaf a | Node (BTree a) (BTree a)

data Dir = L | R

type Path = [Dir]

Sample tree:

tree1 :: BTree Int
tree1 = Node (Leaf 4) (Node (Leaf 2) (Leaf 1)

Here is my attempt, but it doesn't work (won't even compile). Can anyone give me some tips? What am I doing wrong?

pathEnum :: BTree a -> [Path]
pathEnum (Leaf x) = [[]]
pathEnum (Node x y) = [L ++ pathEnum x] ++ [R ++ pathEnum y]

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Orlen posted:

I'm doing some Haskell coursework and I've hit a dead end.

You've got absolutely the right idea, but the types are a little subtly wrong in the last line of your code.

Let's first create a function, leftPathEnum, that only considers paths on the left.

> leftPathEnum :: BTree a -> [Path]

leftPathEnum on leafs returns a single result: the empty path.

> leftPathEnum (Leaf x) = [ [ ] ]

On interior nodes, leftPathEnum needs to take all the paths from its left child, and stick a 'L' in front of them. We use map for this.

> leftPathEnum (Node l r) = map (L :) (leftPathEnum l)

Hopefully you've been introduced to map before. It takes a function, and a list, and returns the list with that function applied to every element.

In this case, the function I've provided is (L :). The (:) operator is called "cons", and its type is:

(:) :: a -> [a] -> [a]

It takes a single element, and a list, and prepends the element to the list. The type of (L :) is:

(L :) :: [Dir] -> [Dir]

It takes a list of Dirs, and prepends L to the list.

Do you think you can write a pathEnum function now, with the same technique? You'll have to call map twice, and you'll be concatenating the results of the maps with ++.

Fenderbender
Oct 10, 2003

You have the right to remain silent.

Avenging Dentist posted:

That doesn't resolve the "IE Javascript debugging in Linux" issue, which is kinda the point. At the very least, you should be doing a pass of your site within Windows, and if there are problems, sometimes you have to suck it up and use Windows to have access to decent development tools for IE (unless you can get them working in WINE).

http://www.getfirebug.com/lite.html - Check this out. It may prove useful.

Orlen
Oct 25, 2005
custom user title

ShoulderDaemon posted:

Do you think you can write a pathEnum function now, with the same technique? You'll have to call map twice, and you'll be concatenating the results of the maps with ++.

Thanks very much for your help, it's much appreciated. I've got it working now! I owe you one!

Scaevolus
Apr 16, 2007

magicalblender posted:

Whoops v:shobon:v

Well, anyway, here's the solution I came up with, after my ignorance about piping had been corrected:
code:
#include <stdio.h>

int main(){
	char foo[100];
	while (scanf("%s", &foo) != EOF){
		printf("\n%s", foo);
	}
	return 0;
}
What happens when you pipe a line with more than 100 characters into this program? Foo is only defined to be 100 characters, so you end up writing to other memory. This is a buffer overflow, and you need to beware of them when you write C.

What you should be doing is
while (fgets(foo,100,0) != NULL) {

Vanadium
Jan 8, 2005

Scaevolus posted:

What happens when you pipe a line with more than 100 characters into this program? Foo is only defined to be 100 characters, so you end up writing to other memory. This is a buffer overflow, and you need to beware of them when you write C.

What you should be doing is
while (fgets(foo,100,0) != NULL) {

At least he does not instantly get a segfault from passing null pointers as streams.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
What do you mean "at least"? An instant segfault is the best kind of error to have, because it's immediately obvious that something's wrong and it's easy to find out exactly where the error happened.

FigBug
Apr 27, 2002

Lemon Party - Lest we Forget

JoeNotCharles posted:

What do you mean "at least"? An instant segfault is the best kind of error to have, because it's immediately obvious that something's wrong and it's easy to find out exactly where the error happened.

He means you should pass in stdin, not 0.

code:
while (fgets(foo,100,stdin) != NULL) {  

Scaevolus
Apr 16, 2007

Vanadium posted:

At least he does not instantly get a segfault from passing null pointers as streams.
Sorry about that, I was thinking of read() and write(), which take (int fd..), which is 0 for stdin.

vv Yeah, I know. Difference between int fd and FILE *stream and all that.

Scaevolus fucked around with this message at 02:40 on Apr 19, 2008

more falafel please
Feb 26, 2005

forums poster

Scaevolus posted:

Woops, for some reason I thought 0 worked as stdin-- on some systems stdin isn't defined in <stdio.h>, and 0 works fine.

0 is the file descriptor for stdin, but fgets() (along with fread, fwrite, fopen, etc) takes a FILE*. It also wouldn't work if you did read(stdin, buff, 100).

_aaron
Jul 24, 2007
The underscore is silent.
I want to make an RSVP website where people can log in with a username and password and indicate whether or not they will be attending an event as well as how many others they will be bringing with them. I've never really done web work before, so I don't know where to start on something like this. What language(s) should I use? I will also need some kind of database; what's easiest/most useful for something like this? If I could just get pointed to a few tutorials, that would be great. Thanks!

clockwork automaton
May 2, 2007

You've probably never heard of them.

Fun Shoe
My C skills are really shaky and as such OS is going to be the death of me. Basically I'm trying to add a syscall to store and retrieve data and be identified by a string and I sometimes I get segfaults when I try to store or retrieve data. My test program for my syscalls is as follows: It should be noted that when the syscall doesn't give me a segfault on retrieving the value it prints out a 1 (which is baffling, because I can't figure out where 1 is coming from).

code:
    #include <stdlib.h>
    #include </u/OSLab/leb35/linux-2.6.23.1/include/asm-i386/unistd.h>

    int main(int argc, char** argv)
    {
       long bytes;
       char* name;

       name = malloc(sizeof(char)*1024);

       if(argc == 1)
       {
          printf("Error: no arguments given\n");
          return -1;
       }

       if(strcmp(argv[1], "-retrieve")==0)
       {
          if(argc <  2)
          {
             printf("Error: too few arguments\n");
             return -1;
          }

          name = argv[2];

          bytes = syscall(__NR_getdata, name);   // get syscall
          printf("%d\n", bytes);
       }

       if(strcmp(argv[1], "-store")==0)
       {
          if(argc <  3)
          {
             printf("Error: too few arguments\n");
             return -1;
          }

          bytes = atol(argv[2]);
          name = argv[3];

          syscall(__NR_storedata, bytes, name);   // set syscall
       }

       return 0;
    }
I made a sort of vector that can grow and shrink to hold my data and a struct for the data this is how it is initalized:
code:
    // struct for data
    struct data
    {
       char* name;
       long bytes;
    };

    int vector_size = 10;
    int vector_len = 0;
    struct data** vector = (struct data**)kmalloc(vector_size * sizeof(struct data*), GFP_KERNEL);
based on what debugging info I can actually get I think the issue is somewhere in here:
code:
    long vector_get(char* name)
    {
       int i;
       for(i = 0; i<vector_len; i++)
       {
          // if the string matches the name return the data
          if(strcmp(vector[i]->name, name) == 0)
             return vector[i]->bytes;
       }

       // if not found return -1
       return -1;
    } 
The full code for adding and retrieving data is here.

Any help is greatly appreciated. I'm open to any sort of suggestions, I really won't be pissed if you guys tell me my approach is entirely wrong.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

clockwork automaton posted:

code:
//snip
Your approach is totally wrong. You should try posting in the C/C++ questions thread instead.

clockwork automaton
May 2, 2007

You've probably never heard of them.

Fun Shoe

Jethro posted:

Your approach is totally wrong. You should try posting in the C/C++ questions thread instead.

:D It's okay though, because I figured it out. It was an issue with user space memory and kernel space memory all I had to do was use strcpy and it was saved.

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

clockwork automaton posted:

:D It's okay though, because I figured it out. It was an issue with user space memory and kernel space memory all I had to do was use strcpy and it was saved.

I've responded to you here.

Feet Slash Birds
Feb 5, 2008

I demanded real money for internet risk and this is the result
So I'm working with LISP and I need a way to determine if a certain list is a member of another list.

eg

is (1 0) inside
((0 0)(1 0) (4 3)(6 6))


Any idea why it declares a statement like this NIL?
(member '(1 0) '((0 0)(1 0)(4 3)(6 6)))

Neslepaks
Sep 3, 2003

Presumably because MEMBER defaults to checking with EQ or EQL or whatever (which don't go into sublists), with :test #'equal it should work.

Jack Black
Nov 6, 2007
Alright, a cherries jubilee and that's it.
Ok, so I haven't really done any coding at all, ever. I just started reading "Structure and Interpretation of Computer Programs". I was wondering if someone could direct me to what I can use to get some hands-on practice for general programming?

Jack Black fucked around with this message at 03:16 on Apr 24, 2008

CrusaderSean
Jun 10, 2002
AwakenedDreamer
I just started learning basic GUI programming and I have some very general design questions. Let's say I'm writing a CAD or paint program and I have the following classes.

class ApplicationWindow {...main window that contains everything...}
class DataModel {...data representation...}
class RenderView extends JScrollPane {...visual way to display/modify data...}
class ModelEditor extends JPanel {...text display/edit data...}

My question is how to synchronize data presentation in different GUI components? I can think of couple ways to do this:
1. instantiate data object in one of the classes and save reference variable/pointer to data object in the other classes. So it's just passing the data object to whatever class that needs it.

2. instantiate data object in ApplicationWindow and create event handlers to handle all data access/updates. Pretty much centralizing interaction between data and different GUI panels.

I realize this is a really general question. Are there other ways to do this? How do programs like gimp handle this?

SixPabst
Oct 24, 2006

Say I have a string like
code:
row{item:item:item}|row2{item:item:item}|row3{item:item:item}
and I want to remove a specific row entry, can someone give me the regex pattern for this? It would be from rowX to the | character. I know the rowX portion of the string.

Much appreciated.

Edit: Nevermind, I molested a html tag sample to work.

SixPabst fucked around with this message at 21:38 on Apr 24, 2008

haveblue
Aug 15, 2005



Toilet Rascal

CrusaderSean posted:

I just started learning basic GUI programming and I have some very general design questions. Let's say I'm writing a CAD or paint program and I have the following classes.

class ApplicationWindow {...main window that contains everything...}
class DataModel {...data representation...}
class RenderView extends JScrollPane {...visual way to display/modify data...}
class ModelEditor extends JPanel {...text display/edit data...}

My question is how to synchronize data presentation in different GUI components? I can think of couple ways to do this:
1. instantiate data object in one of the classes and save reference variable/pointer to data object in the other classes. So it's just passing the data object to whatever class that needs it.

2. instantiate data object in ApplicationWindow and create event handlers to handle all data access/updates. Pretty much centralizing interaction between data and different GUI panels.

I realize this is a really general question. Are there other ways to do this? How do programs like gimp handle this?

In general, you don't ever want to store "master" data in GUI objects. You should put the data in DataModel and have the GUI objects retrieve it from there when they need to draw. You'd implement the edit operations as methods of DataModel as well (which would be called by ApplicationWindow by the event handlers).

This is one aspect of the MVC school of design, look up that if you want a better explanation.

haveblue fucked around with this message at 00:04 on Apr 25, 2008

Eldoran
Dec 26, 2005

This dosen't make any sense
I'll try to explain this as good as I can but seeing as I'm stuck and don't really know where to start searching I hope you can filter out the parts that matter.

Backstory:

I recently changed hosting and in the progress of doing so decided to rework the design of my wordpress site, I'm not a web designer by trade but i use photoshop from time to time so i figured I might be able to produce something close to decent.

The horror:

After completing the new design I thought everything was working fine until I tried the navigation links, it seems clicking any of the category or archives links breaks the site. Have a look.

Fixed site

I think this might be PHP issue, but I'm not sure.

For some reason the sites footer appears in the sidebar, so I've been trying to go true the code for that but I really can't figure out what the problem is, maybe one of you guys can.

EDIT:

The solution:

I looked at the code again this morning with fresh eyes, and figured it out it's working great now. The problem was in my commenting out a part of the code that was needed for the site to render correctly.

Eldoran fucked around with this message at 12:25 on Apr 26, 2008

Donald Duck
Apr 2, 2007
I was looking through this thread originally to find books to read, as a CS student. Found them on the first page, but just wanted to ask some questions. I'm just finishing my second year now.
The books listed were Code Complete and Practice of Programing, as well as the Art of Programming. Would all these books be useful for me? I imagine most of the Knuth book would be beyond me at this stage

Second question, pretty much everything we've done has been just in Java, with a tiny bit of C in one of my modules. I've picked up the K&R C book to help me learn C over the summer. Since I want to know more than just Java, what else is worth learning?

Edit: I was reading reviews on the Knuth books and saw they code in them is in MIX? This would make them pretty out dated would it not?

Donald Duck fucked around with this message at 03:51 on Apr 26, 2008

nbv4
Aug 21, 2002

by Duchess Gummybuns
Can someone explain to me the purpose of putting "java script:" at the begining of a function when running a javascript function from within html? For instance:

code:
<span onclick="javascript:set_something('12');">click here to set something</span>
Its not the kind of thing you can google easily...

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
There is none. It's just an alternative syntax.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply