|
YO MAMA HEAD posted:I'm trying to convert a nice C-style math expression like (t*9&t>>4|t*5&t>>7|t*3&t/1024)-1 so that it can be understood correctly by a Smalltalk-esque language with no Order of Operations. I'm sure this can be done with regular expressions, but I'm kind of poo poo at them at the best of times and it's getting late. I know the general sense of things is that parentheses will need to be inserted all over the place, but I can't quite wrap my brain around it. It's really late at night so I may be out of my mind, but as I recall if you first use a regular substitution like s/([^+]+)\+(.+)/($1+$2)/g to put parenthesis around the lowest-order-of-operations operators, then something like s/([^+*]+)\*([^+]+)/($1*$2)/g to put parenthesis around the next-highest-order-of-operations operators, then something like s/([^+*^]+)\^([^+*]+)/($1^$2)/g for the next-highest and so on and so forth, then you'll wind up with a correctly-parenthesized expression. I suspect this technique relies on there being no parenthesis in the expression to start with, and all the operators being left-associative. As I said, really late at night, I haven't tested this, no promises. But converting to an intermediate form like RPN is a way more normal way of handling this kind of problem. Regular expressions are not really a natural solution. Edit: If you don't understand how RPN helps you, consider the expression 3+(4-2)*5. We can translate this to RPN, giving us the list [3, 4, 2, -, 5, *, +]. Reverse that list to give us [+, *, 5, -, 2, 4, 3]. Consider the algorithm: code:
code:
ShoulderDaemon fucked around with this message at 10:58 on Mar 22, 2012 |
# ? Mar 22, 2012 10:39 |
|
|
# ? May 29, 2024 18:57 |
|
Dumb question, but what is the difference between a library and an object file, and why should I choose to use one over the other? It seems to me they serve the same purpose - to provide a definition of functions/subroutines that you'd want to be able to use in multiple programs without rewriting them. And for that matter, what is the difference between a lib*.so, and a lib*.a?
|
# ? Mar 22, 2012 14:46 |
|
YO MAMA HEAD posted:I'm trying to convert a nice C-style math expression like (t*9&t>>4|t*5&t>>7|t*3&t/1024)-1 so that it can be understood correctly by a Smalltalk-esque language with no Order of Operations. I'm sure this can be done with regular expressions, but I'm kind of poo poo at them at the best of times and it's getting late. I know the general sense of things is that parentheses will need to be inserted all over the place, but I can't quite wrap my brain around it. Build a parse tree and print it with all the extra parentheses. There's almost certainly a bunch of canned parsers for arithmetic expressions out there already, so just use one of those to get the tree. The Born Approx. posted:Dumb question, but what is the difference between a library and an object file, and why should I choose to use one over the other? It seems to me they serve the same purpose - to provide a definition of functions/subroutines that you'd want to be able to use in multiple programs without rewriting them. And for that matter, what is the difference between a lib*.so, and a lib*.a? A library is a bunch of object files. It's customary to release things as libraries so there's only one file (plus whatever definitions you need), but there's no technical reason why you have to.
|
# ? Mar 22, 2012 16:01 |
|
Okay, I'll try the RPN solutions! It's worth pointing out that I'm a computer musician, not a computer scientist, and so my background on this kind of stuff is a little iffy—it sometimes seems like doing too much CS work just isn't worth it. Thanks for thoughts!
|
# ? Mar 22, 2012 16:22 |
|
The Born Approx. posted:And for that matter, what is the difference between a lib*.so, and a lib*.a?
Standish fucked around with this message at 20:50 on Mar 22, 2012 |
# ? Mar 22, 2012 20:47 |
|
I have a strange PHP question. I was working with some legacy (from like 2006) PHP code. Our SVN server has a precommit hook that runs php -l on all of the committed php files to ensure that they compile fine. I ran into an issue during an import where a script wouldn't compile. There were duplicate constants named in the same class. The code looked something like: php:<? class DeviceIDs { /** Master device constants **/ const DATA = "\x44"; // turn off streaming [other constants] /** Slave device constants **/ const DATA = "\x44"; // turn off streaming } ?> Edit: It turns out that this compiles just fine on php 5.0.4, but not newer versions. oRenj9 fucked around with this message at 21:33 on Mar 22, 2012 |
# ? Mar 22, 2012 21:02 |
|
The Born Approx. posted:Dumb question, but what is the difference between a library and an object file, and why should I choose to use one over the other? It seems to me they serve the same purpose - to provide a definition of functions/subroutines that you'd want to be able to use in multiple programs without rewriting them. Well, the big difference is that a library is - as you say - a collection of functions/subroutines that you'd want to be able to use in multiple programs without rewriting them (and what form any particular library takes is dependent on the language, tools, and OS being used), whereas an object file is an intermediate stage in the build process for C/C++ and some other compiled languages. In C/++ specifically, an object file is the machine code resulting from compilation of a single source file; it may later be used in linking to create a library or executable program, but isn't either yet. (Standish has nicely explained the difference between static and dynamic libraries.) As for why you'd use libraries over object files, for dynamic libraries the reason is obvious - object files can't be dynamically loaded directly, they need the additional information added by the linker when it creates the .so. For static libraries, it's easier to manage one file than a dozen (and in fact .a static libraries are just simple ar archives containing all the object files making up the library). In many languages the question never arises; in most interpreted languages, for example, libraries are simply distributed as source code which the interpreter loads directly - there is no distinction between the library and the source code for the library.
|
# ? Mar 22, 2012 21:19 |
|
Going along with my project from the last page, I figure while I'm waiting on hardware and relay boards to arrive I can at least start some of the programming. I'm having a hard time with this because I'm not even sure what you would call it, but can someone point me in the right direction to get started on a "waiting list" system that only gives 1 person control of the hardware at a time, and everyone else has to wait in line? I did some googling for php waiting list but it wasn't really what I was looking for. I basically need a way to keep track of all the sessions, and add them all to a list (or probably a database) for the waiting list, and as the timer runs out on the active session, pick the next entry from the waiting list and transfer control to them. I'm just having a hard time putting it to code, as I've never really done a lot with session management before.
|
# ? Mar 23, 2012 02:30 |
|
Maniaman posted:I'm having a hard time with this because I'm not even sure what you would call it, but can someone point me in the right direction to get started on a "waiting list" system that only gives 1 person control of the hardware at a time, and everyone else has to wait in line? I did some googling for php waiting list but it wasn't really what I was looking for. This is not a trivial problem, you have to be aware of concepts related to databases, concurrency, and client/server communications. You mentioned a database and this is an acceptable method, and probably one of the simplest to implement cross-session blocking (another method would be a client/server daemon). Below is my simple hackish implementation (there are more elegant/maintainable/robust/etc solutions out there in either format). When a new client connects to your website and requests access, your code will insert them into a waiting list at the end of the list. The user will be redirected to a page that allows them to click a button to check and see if they have access, if they do they get control. They will have another button to relinquish a control and there will be a time limit for both overall usage and for time since last action by the user controlling the crane. First you need to install a database, try MySQL because it's free and easy to setup. Make a table craneWaitingList or whatever you like, with an autoincremented queuePosition (int) field and an identifier (char(23)) field. Make a table called craneUsage with an identifier (char(23), startUsage (datetime) and a lastUsage (datetime) field. Create the page that allows the user to enter into the waiting list. This page will insert a unique identifier value for the client into the table. The autoincrement property of the table will automatically put them at the end of the queue. Make sure to store the unique identifier in a session variable. Generate the unique identifier with PHP's uniqid with more entropy. Create the page the user is redirected to to request access to the crane (or make this a dynamic part of the first page). When the user requests access, first check for timeouts by checking the craneUsage table for tolerance values for startUsage and lastUsage. If the tolerance values are exceeded and identifier at the front of the queue matches the identifier in the craneUsage table, remove the row from craneWaitingList by deleting on the craneUsage identifier. This process should be done in a single transaction. Next, select the minimum queuePosition from the table and match the identifier stored in the database with the current client identifier. If they match, grant the user access by first updating the craneUsage table with the identifier and new start values, and then by redirecting him to the control page. On the control page, make sure to update the craneUsage table when controls are used. The button to relinquish control removes their identifier row from the craneWaitingList table.
|
# ? Mar 23, 2012 04:05 |
|
YO MAMA HEAD posted:I'm trying to convert a nice C-style math expression like (t*9&t>>4|t*5&t>>7|t*3&t/1024)-1 so that it can be understood correctly by a Smalltalk-esque language with no Order of Operations. I'm sure this can be done with regular expressions, but I'm kind of poo poo at them at the best of times and it's getting late. I know the general sense of things is that parentheses will need to be inserted all over the place, but I can't quite wrap my brain around it. You can't use (normal) regular expressions to correctly parenthesize a context-free language, which arithmetic expressions are. Edit: Ugh, beaten by new page!
|
# ? Mar 23, 2012 06:16 |
|
Maniaman posted:Going along with my project from the last page, I figure while I'm waiting on hardware and relay boards to arrive I can at least start some of the programming. Essentially you need to create a queue. I don't know if you really need to use a database but MySQL/SQLite should get it done. What you should do is have the site have a page that does long poll requests for each client connected (there shouldn't be much problem as long as the site isn't hit very hard) which is essentially the waiting room area. When it is their turn to control the crane send some response back through and have your code redirect them to another page. On that page check to make sure that the sessions match and if they don't throw the client back out into the waiting room. And then of course once that session's time limit is up, remove them from the front of the queue, boot them off the control page and then repeat the process.
|
# ? Mar 23, 2012 06:21 |
|
I think a big thing that people don't understand is that regular expressions are useful sometimes, but they're not exactly a "one size fits all" tool for parsing poo poo. Some things are good to use them for, some things you can use them for but it's not exactly practical (ISBN thing from a page or two back), and some things are simply not possible to use them with (parsing XML and poo poo).
|
# ? Mar 23, 2012 06:48 |
|
Look Around You posted:and some things are simply not possible to use them with (parsing XML and poo poo). Unless you use Perl, where the "regular" in "regular expression" is taken to mean something entirely different, apparently. But the use of general recursion in regular expressions probably belongs in the coding horrors thread rather than here.
|
# ? Mar 23, 2012 07:00 |
|
Strong Sauce posted:Essentially you need to create a queue. I don't know if you really need to use a database but MySQL/SQLite should get it done. What you should do is have the site have a page that does long poll requests for each client connected (there shouldn't be much problem as long as the site isn't hit very hard) which is essentially the waiting room area. When it is their turn to control the crane send some response back through and have your code redirect them to another page. On that page check to make sure that the sessions match and if they don't throw the client back out into the waiting room. And then of course once that session's time limit is up, remove them from the front of the queue, boot them off the control page and then repeat the process. PHP does have a global ENV space that could be used to maintain the queue, but you'd need to synchronize access to it or you have a race condition and PHP doesn't seem to have great utilities for that. Maybe I'm being pedantic as there really won't be many opportunities for a race condition on a very low traffic site and as long as you authenticate on crane commands as well it would be by far the simplest solution if you don't mind a user getting booted after apparently being granted access every once in a blue moon. He could use a Java servlet and applet combo to make this really smooth but that's probably more than he wants to get into right now. Edit: it seems PHP resets ENV variables set by the client after the current request. Not sure if this is possible without using external daemon or database in PHP. baquerd fucked around with this message at 07:05 on Mar 23, 2012 |
# ? Mar 23, 2012 07:01 |
|
baquerd posted:PHP does have a global ENV space that could be used to maintain the queue, but you'd need to synchronize access to it or you have a race condition and PHP doesn't seem to have great utilities for that. Maybe I'm being pedantic as there really won't be many opportunities for a race condition on a very low traffic site and as long as you authenticate on crane commands as well it would be by far the simplest solution if you don't mind a user getting booted after apparently being granted access every once in a blue moon. I think all this is a little moot since I just realized he probably wants some sort of video to show the crane moving and that at least requires a flash app or a java app.
|
# ? Mar 23, 2012 08:48 |
|
Strong Sauce posted:I don't know if you're just referring to the part about not using a database or the whole post. What I meant was if the site's not meant for a lot of users he could save a lot of time with a text file. I would guess that PHP blocks the file while another process is writing to it so probably not ideal for a large number of users, otherwise yeah a database would be ideal. Good call on the flat file for really low traffic, there's a flag to set to request exclusive write access in PHP it looks like. The video can be separate from the controller infrastructure though, and can easily be prefabbed webcam software, so he doesn't need to know what's going on there to write a controller.
|
# ? Mar 23, 2012 14:45 |
|
I figured it would be easier to keep the video separate from the control. I'd like to avoid having to learn and use flash/java if at all possible. You've given me quite a bit of information on what direction to take with it though, so I have some work to do while I'm waiting on hardware to show up.
|
# ? Mar 23, 2012 15:58 |
|
What would be a good way to represent the 7 days of a week? In an options screen you would have a checkbox for each day, and then your program would use those selections to decide whether or not to perform some action on that day of the week. So if you only checked monday-friday, it woudn't send you an email on Saturday or Sunday. The first thing that comes to mind is a bitfield, and you could use a single byte to store the setting for each day. But that seems like that's not the best way to do it. This would be something that would get stored in a SQL database of some sort.
|
# ? Mar 24, 2012 04:29 |
|
Bob Morales posted:What would be a good way to represent the 7 days of a week? In an options screen you would have a checkbox for each day, and then your program would use those selections to decide whether or not to perform some action on that day of the week. I would tackle it one of two ways. The first solution would have one table with bit fields for Monday, Tuesday, Wednesday, etc plus a foreign key back to your users. This would be the option I'd pick if you are pretty sure you are stick to the days of the week and the front end is hard coded to the days of the week plus your data set is staying small. If you are going to expand this to have different triggers like quarterly, yearly, monthly, etc plus have the selection built dynamically on the front end I'd go with two tables. One table would store the selections so a field for the name of the selection and some sort of primary key. Then another table that tied a user to the triggered selection as a many-to-many relationship. Between the two the second one would be the "better" of the two because you could easily put an index on the many-to-many table on user PK and trigger PK. The first option would require table scans or lots of indexes to have good execution plans but if your number of users is small then index coverage won't really matter.
|
# ? Mar 25, 2012 14:39 |
|
C++ question about classes and pointer data fields. I'm totally stuck on this part of a homework: I have a Student class, in which Student objects can be created. I want to create a pointer data field named bestFriend. This should point to another student. This should default to null. There should be mutator and accessor functions for this variable. When the mutator is called it should set the bestFriend of both students (to each other). If one of the students already has a bestFriend, the caller object should set its bestFriend to null and print a warning. The function I'm using right now is: (in header file:) code:
code:
code:
|
# ? Mar 25, 2012 19:29 |
|
Well, there's several problems here. First of all, you don't seem to be using pointer data fields correctly, instead setting the things that the fields point to by value, which is very likely what you don't want. Make setBestFriend take one thing, a Student *, since it's not a static method. getBestFriend should return a Student * as well. As for printing, what do you want to do? It's saying "I don't know how to print a student!", and since you haven't given any more information, that's a fair thing for it to do. Define a method to cast it into something that an iostream can take, like a char * or a std::string.
|
# ? Mar 25, 2012 19:37 |
|
Suspicious Dish posted:Well, there's several problems here. First of all, you don't seem to be using pointer data fields correctly, instead setting the things that the fields point to by value, which is very likely what you don't want. How can it take only one arg? I need at least two Student types passed into it so they can be set to each other's bestFriend, right?
|
# ? Mar 25, 2012 19:40 |
|
Right now, a third Student is in charge of who s1 and s2 are friends with, and that doesn't make any sense.
|
# ? Mar 25, 2012 19:44 |
|
Kire posted:How can it take only one arg? I need at least two Student types passed into it so they can be set to each other's bestFriend, right? A method is something that belongs to an object. In C++, that object is referenced in the body with a special keyword, this.
|
# ? Mar 25, 2012 19:51 |
|
pseudorandom name posted:Right now, a third Student is in charge of who s1 and s2 are friends with, and that doesn't make any sense. What third Student? I'm confused. Should it be like this: code:
Kire fucked around with this message at 20:45 on Mar 25, 2012 |
# ? Mar 25, 2012 20:14 |
|
Kire posted:What third Student? I'm confused. Should it be like this: I forget if "this" is considered a pointer or a reference, but try: code:
|
# ? Mar 25, 2012 20:38 |
|
Suspicious Dish posted:I forget if "this" is considered a pointer or a reference, but try: That compiled ok, but now I'm having trouble calling it: code:
code:
|
# ? Mar 25, 2012 20:50 |
|
Right, so I assume you're doing something like:code:
code:
|
# ? Mar 25, 2012 21:22 |
|
Bob Morales posted:What would be a good way to represent the 7 days of a week? In an options screen you would have a checkbox for each day, and then your program would use those selections to decide whether or not to perform some action on that day of the week. Congrats, you have just started writing a scheduler. I had to do this as a junior programmer. I didn't think much of it. But if I had to do this today, I would start getting really nervous, because I know that once I implement that management will be wanting:
I'd do it like garlig says - M2M the user <-> some notification time. And get ready for some fun down the road.
|
# ? Mar 26, 2012 15:00 |
|
Do not write a scheduler. If you must, write a front end to an existing scheduler such as Quartz or even crontab.
|
# ? Mar 26, 2012 15:44 |
|
You'll probably have more luck with the C++ question in the C++ thread.
|
# ? Mar 27, 2012 06:58 |
|
I have a general logic question. I’m building an application (Java if you must know) that reads a user’s facebook information. Once you log in, it retrieves a lot of information. But what I’m concerned about is that I can pull my ‘friends’ list and all my friends’ ‘mutual friends’ info. But after that, I would like to display a sort of "friends grid" in 2-d space. I already can place their info on the grid, and show connections between them using lines. The logic part is I would like to group them, and if they are common friends, put them closer together, while if they have no relationship with each other, I can keep them at a distance. Take, for example, four groups(although I have no idea how many groups there will actually be in any given list): Work: Wendy, Wally, Wesley, Wonda, and Wilma Family: Fred, Francis, Francesca, and Frank High school friends: Heather, Henry, Hal, Howard, Hermione, and Hector College friends: Chris, Courtney, Carl, and Calvin Misc friends: Mickey and Michelle. Each group may have a strong relation, but not everyone is a friend with everyone else in a group. Keep in mind that there are no facebook groups “my family” or “my high school friends,” because no one actually makes groups like that. My app should be able to figure out the grouping on its own(using only my friends ‘mutual friends’ data), even though there is sometimes some interlap. The final output should look something like this: (Blue lines represent a friendship) Notice that individuals are placed near common friends. Thanks in advance to any goons who can give me some tips or point me in the right direction.
|
# ? Mar 27, 2012 14:01 |
|
The term you're missing is "friends graph". The problem of identifying dense subgraphs is well-studied; I'd recommend looking at some of those papers and algorithms. You might also be able to use a graph clustering algorithm like MCL or a spectral method. Once you identify clusters or dense subgraphs, it should be pretty straightforward to adjust the positions of your nodes. (I miss when Facebook actually let you visualize your friends network by passing it through something like graphviz; I think this was removed in 2005 or 2006 when it began to be too computationally intensive.) EDIT: Wasn't thinking very clearly; as far as I know a spectral clustering method will give you a nice embedding of nodes in 2D space but you'll still have to use something like a graph cut method to get the clusters themselves, and you're very likely to hit the classic problem of "how many clusters do I want?" Lysidas fucked around with this message at 14:27 on Mar 27, 2012 |
# ? Mar 27, 2012 14:13 |
|
Check out the Girvan-Newman algorithm. Doesn't help you with the "how many clusters" problem Lysidas mentioned, but it'll give you the clusters.
|
# ? Mar 27, 2012 16:09 |
|
Mark Newman. He does some amazing work with networks, and I was lucky enough to attend a talk he gave at my university last year. Come to think of it, is a nice embedding in 2D space all you need? I suspect that I was making the problem more complicated than it is.
|
# ? Mar 27, 2012 21:23 |
|
You could also look at the graphviz library if you're only interested in drawing graphs and don't particularly want to compute the clusters.
|
# ? Mar 27, 2012 21:29 |
|
I think I want to mess with an app's API calls on windows, but I don't yet know how. I have an app that grabs files which are linked from an RSS (podcast), however the files require a password in the url (http://user:pass style), this app asks for username and password every time. I was going to set the app up to use a proxy but it uses the windows settings for proxies which means all my apps would end up going through a proxy and having an app run on startup etc. What I think I want to do is make a stub dll that pass on all function calls to the original but changes the url for downloads from a certain server. Having typed all this, it looks like a silly plan, on the basis that my computer is pretty slow etc so I don't want to be running a proxy server all the time, what would you guys suggest?
|
# ? Mar 28, 2012 01:44 |
|
Crankit posted:I think I want to mess with an app's API calls on windows, but I don't yet know how. Since it would only be proxying specific traffic outright it wouldn't put a significant amount of load on your system. Edit; I don't know if doing it this way will bust up the proxy though, since it's possible requests to sub.whateverurl.com/whatever&x=y will be changed to requests to localhost/whatever&x=y (which the proxy wouldn't handle). The Gripper fucked around with this message at 05:20 on Mar 28, 2012 |
# ? Mar 28, 2012 05:16 |
|
Yes, all i need is an embedding in 2-D space. Because the only info I have is the 'mutual friends' that is the basis for the edge in any given graph. Most friends will fall neatly within any given cluster. ie work friends, high school friends, friends from my old job, friends I met during study abroad etc. The job is now to roughly identify some clusters, show it in 2-d space, and roughly build it around that. I realized that my with the information my program fetches, it cant identify the difference between "my work friends" and "that one guy who got invited to the office party once, but he was pretty funny so no he's facebook friends with everyone else at work." He'll probably get thrown into the cluster anyways, which is fine. But I'd still like it to figure out if which cluster a person belongs to if they branch out into multiple clusters.
|
# ? Mar 28, 2012 05:27 |
|
|
# ? May 29, 2024 18:57 |
|
The Atomic Man-Boy posted:Yes, all i need is an embedding in 2-D space. So which is it? Do you just want to embed the graph in 2D space or do you want to assign each node to a cluster? Also I'm going to suggest laplacian eigenmaps for the embedding, because it's really easy to implement (as long as you have access to an SVD routine).
|
# ? Mar 28, 2012 05:43 |