qid
int64
1
3.11M
question
stringlengths
10
32.1k
date
stringlengths
10
10
metadata
list
response_j
stringlengths
0
33.7k
response_k
stringlengths
3
34.7k
2,089,834
I'm looking at learning JavaFX. I've tried setting Eclipse to develop a small app and I've downloaded the Eclipse plugin. [Eclipse JavaFX plugin](http://javafx.com/docs/gettingstarted/eclipse-plugin/) BUT... it just seems, well, flakey. So I have 3 questions... 1: Is there a better plugin? 2: Or is there some great set of tutorials out there that I'm missing? 3: finally, is it meant to be easy to call Java code from FX? I'm stuggling, it there a good example somewhere? On questions 1 & 2, Eclipse underlines code in red that just shouln't be. For example.. see this image... [alt text http://www.qenet.co.uk/fx.jpg](http://www.qenet.co.uk/fx.jpg) Why does it underline bit of imports in red? I know this is little of an open ended question. So I guess my main question is this... Is my experiance of JavaFX and Eclipse the best I can hope for? Or am I missing something ? (and I'm not looking for a Yes/No response) :-) Just looking for a discussion on how best to learn/develop JavaFx.
2010/01/18
[ "https://Stackoverflow.com/questions/2089834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26778/" ]
Netbeans is really the only way to go at the moment for JavaFX development. They are both Sun products and Sun has made sure the two work very well together. Before long Eclipse and others will catch up but for the moment that's how it is.
To me this has happened when I wronlgy installed javafx sdk 1.2.3....This plugin works only with 1.2.1... :/
2,089,834
I'm looking at learning JavaFX. I've tried setting Eclipse to develop a small app and I've downloaded the Eclipse plugin. [Eclipse JavaFX plugin](http://javafx.com/docs/gettingstarted/eclipse-plugin/) BUT... it just seems, well, flakey. So I have 3 questions... 1: Is there a better plugin? 2: Or is there some great set of tutorials out there that I'm missing? 3: finally, is it meant to be easy to call Java code from FX? I'm stuggling, it there a good example somewhere? On questions 1 & 2, Eclipse underlines code in red that just shouln't be. For example.. see this image... [alt text http://www.qenet.co.uk/fx.jpg](http://www.qenet.co.uk/fx.jpg) Why does it underline bit of imports in red? I know this is little of an open ended question. So I guess my main question is this... Is my experiance of JavaFX and Eclipse the best I can hope for? Or am I missing something ? (and I'm not looking for a Yes/No response) :-) Just looking for a discussion on how best to learn/develop JavaFx.
2010/01/18
[ "https://Stackoverflow.com/questions/2089834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26778/" ]
There is another JavaFX plug-in for Eclipse from Exadel. You can download it here: <http://exadel.org/javafxplugin>. Give it a try.
I have similar problems but funnily only under Linux, not Windows. Hope they change that soon.
2,089,834
I'm looking at learning JavaFX. I've tried setting Eclipse to develop a small app and I've downloaded the Eclipse plugin. [Eclipse JavaFX plugin](http://javafx.com/docs/gettingstarted/eclipse-plugin/) BUT... it just seems, well, flakey. So I have 3 questions... 1: Is there a better plugin? 2: Or is there some great set of tutorials out there that I'm missing? 3: finally, is it meant to be easy to call Java code from FX? I'm stuggling, it there a good example somewhere? On questions 1 & 2, Eclipse underlines code in red that just shouln't be. For example.. see this image... [alt text http://www.qenet.co.uk/fx.jpg](http://www.qenet.co.uk/fx.jpg) Why does it underline bit of imports in red? I know this is little of an open ended question. So I guess my main question is this... Is my experiance of JavaFX and Eclipse the best I can hope for? Or am I missing something ? (and I'm not looking for a Yes/No response) :-) Just looking for a discussion on how best to learn/develop JavaFx.
2010/01/18
[ "https://Stackoverflow.com/questions/2089834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26778/" ]
There is another JavaFX plug-in for Eclipse from Exadel. You can download it here: <http://exadel.org/javafxplugin>. Give it a try.
To me this has happened when I wronlgy installed javafx sdk 1.2.3....This plugin works only with 1.2.1... :/
1,347,573
Good Morning SO Campers, I'm interested in developing a social networking site. It will be run on a Linux dedicated server and must be written in PHP. The site functionality will be a cross between FaceBook, Myspace and Yahoo. Specifically, the site needs to offer: * The ability for users to obtain a free email address. * Instant Messaging * RSS Feeds for Weather, News Etc. * Member pages where they can send/receive emails, maintain their own profile etc. Instead of building this solution from scratch, I'm seeking input as to the types of APIs, plugins, modules that are available to cobble this solution together. Thanks, in adavnce, for your help and insight.
2009/08/28
[ "https://Stackoverflow.com/questions/1347573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/123213/" ]
Check out [Elgg](http://elgg.org). Elgg is highly extensible and has a good array of plugins already written for it.
See also [SocialEngine](http://www.socialengine.net/)
1,347,573
Good Morning SO Campers, I'm interested in developing a social networking site. It will be run on a Linux dedicated server and must be written in PHP. The site functionality will be a cross between FaceBook, Myspace and Yahoo. Specifically, the site needs to offer: * The ability for users to obtain a free email address. * Instant Messaging * RSS Feeds for Weather, News Etc. * Member pages where they can send/receive emails, maintain their own profile etc. Instead of building this solution from scratch, I'm seeking input as to the types of APIs, plugins, modules that are available to cobble this solution together. Thanks, in adavnce, for your help and insight.
2009/08/28
[ "https://Stackoverflow.com/questions/1347573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/123213/" ]
Check out [Elgg](http://elgg.org). Elgg is highly extensible and has a good array of plugins already written for it.
You can also consider CMS systems, which have Social Networking components/extensions. E.g. Joomla has [JoomSocial](http://www.jomsocial.com/). I am also sure that most of this functionality may be constructed in [Drupal](http://drupal.org) using its numerous modules.
1,347,573
Good Morning SO Campers, I'm interested in developing a social networking site. It will be run on a Linux dedicated server and must be written in PHP. The site functionality will be a cross between FaceBook, Myspace and Yahoo. Specifically, the site needs to offer: * The ability for users to obtain a free email address. * Instant Messaging * RSS Feeds for Weather, News Etc. * Member pages where they can send/receive emails, maintain their own profile etc. Instead of building this solution from scratch, I'm seeking input as to the types of APIs, plugins, modules that are available to cobble this solution together. Thanks, in adavnce, for your help and insight.
2009/08/28
[ "https://Stackoverflow.com/questions/1347573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/123213/" ]
Check out [Elgg](http://elgg.org). Elgg is highly extensible and has a good array of plugins already written for it.
As mentioned in another answer you could look at Jomsocial which is very good. If you are interested in a free extension to Joomla then you could also look at [Communtity Builder](http://www.joomlapolis.com/).
1,347,573
Good Morning SO Campers, I'm interested in developing a social networking site. It will be run on a Linux dedicated server and must be written in PHP. The site functionality will be a cross between FaceBook, Myspace and Yahoo. Specifically, the site needs to offer: * The ability for users to obtain a free email address. * Instant Messaging * RSS Feeds for Weather, News Etc. * Member pages where they can send/receive emails, maintain their own profile etc. Instead of building this solution from scratch, I'm seeking input as to the types of APIs, plugins, modules that are available to cobble this solution together. Thanks, in adavnce, for your help and insight.
2009/08/28
[ "https://Stackoverflow.com/questions/1347573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/123213/" ]
Check out [Elgg](http://elgg.org). Elgg is highly extensible and has a good array of plugins already written for it.
Have you considered Buddy Press?
1,347,573
Good Morning SO Campers, I'm interested in developing a social networking site. It will be run on a Linux dedicated server and must be written in PHP. The site functionality will be a cross between FaceBook, Myspace and Yahoo. Specifically, the site needs to offer: * The ability for users to obtain a free email address. * Instant Messaging * RSS Feeds for Weather, News Etc. * Member pages where they can send/receive emails, maintain their own profile etc. Instead of building this solution from scratch, I'm seeking input as to the types of APIs, plugins, modules that are available to cobble this solution together. Thanks, in adavnce, for your help and insight.
2009/08/28
[ "https://Stackoverflow.com/questions/1347573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/123213/" ]
You can also consider CMS systems, which have Social Networking components/extensions. E.g. Joomla has [JoomSocial](http://www.jomsocial.com/). I am also sure that most of this functionality may be constructed in [Drupal](http://drupal.org) using its numerous modules.
See also [SocialEngine](http://www.socialengine.net/)
1,347,573
Good Morning SO Campers, I'm interested in developing a social networking site. It will be run on a Linux dedicated server and must be written in PHP. The site functionality will be a cross between FaceBook, Myspace and Yahoo. Specifically, the site needs to offer: * The ability for users to obtain a free email address. * Instant Messaging * RSS Feeds for Weather, News Etc. * Member pages where they can send/receive emails, maintain their own profile etc. Instead of building this solution from scratch, I'm seeking input as to the types of APIs, plugins, modules that are available to cobble this solution together. Thanks, in adavnce, for your help and insight.
2009/08/28
[ "https://Stackoverflow.com/questions/1347573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/123213/" ]
You can also consider CMS systems, which have Social Networking components/extensions. E.g. Joomla has [JoomSocial](http://www.jomsocial.com/). I am also sure that most of this functionality may be constructed in [Drupal](http://drupal.org) using its numerous modules.
As mentioned in another answer you could look at Jomsocial which is very good. If you are interested in a free extension to Joomla then you could also look at [Communtity Builder](http://www.joomlapolis.com/).
1,347,573
Good Morning SO Campers, I'm interested in developing a social networking site. It will be run on a Linux dedicated server and must be written in PHP. The site functionality will be a cross between FaceBook, Myspace and Yahoo. Specifically, the site needs to offer: * The ability for users to obtain a free email address. * Instant Messaging * RSS Feeds for Weather, News Etc. * Member pages where they can send/receive emails, maintain their own profile etc. Instead of building this solution from scratch, I'm seeking input as to the types of APIs, plugins, modules that are available to cobble this solution together. Thanks, in adavnce, for your help and insight.
2009/08/28
[ "https://Stackoverflow.com/questions/1347573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/123213/" ]
You can also consider CMS systems, which have Social Networking components/extensions. E.g. Joomla has [JoomSocial](http://www.jomsocial.com/). I am also sure that most of this functionality may be constructed in [Drupal](http://drupal.org) using its numerous modules.
Have you considered Buddy Press?
110,926
If I was to create a ipfw divert rule to forward all FTP traffic to a specific socket, is it possible to use Java to connect to the socekt and read the packet information? If so, how would i go about reading/writing to the scoket?
2008/09/21
[ "https://Stackoverflow.com/questions/110926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/368855/" ]
[Blender](http://www.blender.org/) is a free 3D modeling tool. Here is an article covering from installation of blender, exporting, to the importing of a model made in Blender into the XNA enviroment: [Getting started with Blender 3D and XNA](http://www.virtualrealm.com.au/blogs/getting-started-with-blender-3d-and-xna/)
yes, truespace is a good choice. It's the first 3d authoring program I ever used. It's pretty simple, and it's free. you can find tutorials on the official website <http://www.caligari.com/> If you don't plan on selling your game, you can download 3D Studio MAX student license. It's the full program for 3 years for free. The learning curve is pretty easy too, especially for modeling. You can find good tutorials on [digital tutors](http://www.digitaltutors.com/training/3ds_max-tutorials). some are free, some are not. There's also 3Dbuzz you can check out for tutorials.
110,926
If I was to create a ipfw divert rule to forward all FTP traffic to a specific socket, is it possible to use Java to connect to the socekt and read the packet information? If so, how would i go about reading/writing to the scoket?
2008/09/21
[ "https://Stackoverflow.com/questions/110926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/368855/" ]
[Blender](http://www.blender.org/) is a free 3D modeling tool. Here is an article covering from installation of blender, exporting, to the importing of a model made in Blender into the XNA enviroment: [Getting started with Blender 3D and XNA](http://www.virtualrealm.com.au/blogs/getting-started-with-blender-3d-and-xna/)
Ill second Blender. You can find some handy tutorials linking XNA and Blender here; <http://www.stromcode.com/>
110,926
If I was to create a ipfw divert rule to forward all FTP traffic to a specific socket, is it possible to use Java to connect to the socekt and read the packet information? If so, how would i go about reading/writing to the scoket?
2008/09/21
[ "https://Stackoverflow.com/questions/110926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/368855/" ]
Take a look at trueSpace also, its just become free - but as Evil Activity stated; Blender is also a good sugestion i just never really got use to its interface and how to do stuff. trueSpace is a little more easy in that way, but i think that blender is more powerful. I guess you know <http://creators.xna.com/>, there is a 3D tutorial you can look at here: <http://creators.xna.com/en-US/education/gettingstarted>
yes, truespace is a good choice. It's the first 3d authoring program I ever used. It's pretty simple, and it's free. you can find tutorials on the official website <http://www.caligari.com/> If you don't plan on selling your game, you can download 3D Studio MAX student license. It's the full program for 3 years for free. The learning curve is pretty easy too, especially for modeling. You can find good tutorials on [digital tutors](http://www.digitaltutors.com/training/3ds_max-tutorials). some are free, some are not. There's also 3Dbuzz you can check out for tutorials.
110,926
If I was to create a ipfw divert rule to forward all FTP traffic to a specific socket, is it possible to use Java to connect to the socekt and read the packet information? If so, how would i go about reading/writing to the scoket?
2008/09/21
[ "https://Stackoverflow.com/questions/110926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/368855/" ]
Take a look at trueSpace also, its just become free - but as Evil Activity stated; Blender is also a good sugestion i just never really got use to its interface and how to do stuff. trueSpace is a little more easy in that way, but i think that blender is more powerful. I guess you know <http://creators.xna.com/>, there is a 3D tutorial you can look at here: <http://creators.xna.com/en-US/education/gettingstarted>
[Houdini](http://www.sidefx.com/). It have too a free tool, [Apprentice](http://www.sidefx.com/index.php?option=com_download&Itemid=208&task=apprentice).
110,926
If I was to create a ipfw divert rule to forward all FTP traffic to a specific socket, is it possible to use Java to connect to the socekt and read the packet information? If so, how would i go about reading/writing to the scoket?
2008/09/21
[ "https://Stackoverflow.com/questions/110926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/368855/" ]
yes, truespace is a good choice. It's the first 3d authoring program I ever used. It's pretty simple, and it's free. you can find tutorials on the official website <http://www.caligari.com/> If you don't plan on selling your game, you can download 3D Studio MAX student license. It's the full program for 3 years for free. The learning curve is pretty easy too, especially for modeling. You can find good tutorials on [digital tutors](http://www.digitaltutors.com/training/3ds_max-tutorials). some are free, some are not. There's also 3Dbuzz you can check out for tutorials.
[Houdini](http://www.sidefx.com/). It have too a free tool, [Apprentice](http://www.sidefx.com/index.php?option=com_download&Itemid=208&task=apprentice).
110,926
If I was to create a ipfw divert rule to forward all FTP traffic to a specific socket, is it possible to use Java to connect to the socekt and read the packet information? If so, how would i go about reading/writing to the scoket?
2008/09/21
[ "https://Stackoverflow.com/questions/110926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/368855/" ]
Ill second Blender. You can find some handy tutorials linking XNA and Blender here; <http://www.stromcode.com/>
Having worked a modeler and texture artist for over 3 years, I have tried the majority of modeling tools and keep coming back to [Nevercenter's Silo](http://www.nevercenter.com/). It's the most elegant, well designed sub-d polygonal modeling application I have ever had the pleasure of using. Once you've used Silo, you'll wonder why anyone uses anything else.
110,926
If I was to create a ipfw divert rule to forward all FTP traffic to a specific socket, is it possible to use Java to connect to the socekt and read the packet information? If so, how would i go about reading/writing to the scoket?
2008/09/21
[ "https://Stackoverflow.com/questions/110926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/368855/" ]
Take a look at trueSpace also, its just become free - but as Evil Activity stated; Blender is also a good sugestion i just never really got use to its interface and how to do stuff. trueSpace is a little more easy in that way, but i think that blender is more powerful. I guess you know <http://creators.xna.com/>, there is a 3D tutorial you can look at here: <http://creators.xna.com/en-US/education/gettingstarted>
Ill second Blender. You can find some handy tutorials linking XNA and Blender here; <http://www.stromcode.com/>
110,926
If I was to create a ipfw divert rule to forward all FTP traffic to a specific socket, is it possible to use Java to connect to the socekt and read the packet information? If so, how would i go about reading/writing to the scoket?
2008/09/21
[ "https://Stackoverflow.com/questions/110926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/368855/" ]
Ill second Blender. You can find some handy tutorials linking XNA and Blender here; <http://www.stromcode.com/>
[Houdini](http://www.sidefx.com/). It have too a free tool, [Apprentice](http://www.sidefx.com/index.php?option=com_download&Itemid=208&task=apprentice).
110,926
If I was to create a ipfw divert rule to forward all FTP traffic to a specific socket, is it possible to use Java to connect to the socekt and read the packet information? If so, how would i go about reading/writing to the scoket?
2008/09/21
[ "https://Stackoverflow.com/questions/110926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/368855/" ]
Take a look at trueSpace also, its just become free - but as Evil Activity stated; Blender is also a good sugestion i just never really got use to its interface and how to do stuff. trueSpace is a little more easy in that way, but i think that blender is more powerful. I guess you know <http://creators.xna.com/>, there is a 3D tutorial you can look at here: <http://creators.xna.com/en-US/education/gettingstarted>
Having worked a modeler and texture artist for over 3 years, I have tried the majority of modeling tools and keep coming back to [Nevercenter's Silo](http://www.nevercenter.com/). It's the most elegant, well designed sub-d polygonal modeling application I have ever had the pleasure of using. Once you've used Silo, you'll wonder why anyone uses anything else.
110,926
If I was to create a ipfw divert rule to forward all FTP traffic to a specific socket, is it possible to use Java to connect to the socekt and read the packet information? If so, how would i go about reading/writing to the scoket?
2008/09/21
[ "https://Stackoverflow.com/questions/110926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/368855/" ]
Take a look at trueSpace also, its just become free - but as Evil Activity stated; Blender is also a good sugestion i just never really got use to its interface and how to do stuff. trueSpace is a little more easy in that way, but i think that blender is more powerful. I guess you know <http://creators.xna.com/>, there is a 3D tutorial you can look at here: <http://creators.xna.com/en-US/education/gettingstarted>
[Blender](http://www.blender.org/) is a free 3D modeling tool. Here is an article covering from installation of blender, exporting, to the importing of a model made in Blender into the XNA enviroment: [Getting started with Blender 3D and XNA](http://www.virtualrealm.com.au/blogs/getting-started-with-blender-3d-and-xna/)
1,053,793
I'm implementing a small time tracking app and I can't decide between two database designs. The first has all the log entries in a single table, ie. ``` TimeLog ------------- job_id : long timestamp start : boolean [or perhaps 'type : enum'] _id : long ``` The other option is to have two tables, one for 'start' entries the other for 'stop' entries. ``` StartLog StopLog ------------- ------------- job_id : long job_id : long timestamp timestamp id : long id : long ``` What are the pros and cons of each approach? Is there another alternative? My specific app will be running on SQLite and I'd like to optimise it for speed - but I am interested in generic arguments.
2009/06/27
[ "https://Stackoverflow.com/questions/1053793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48234/" ]
I would go for the first (single-table, type-differentiated) design, not particularly because there are too many tables, but simply because the database entities are very similar and would have similar constraints and operations.
I think that depends on what queries will you use more. If you query most of the time only for start entries or stop entries, but not both, you will benefit from smaller table sizes. On the other hand, if you mostly use both parts in the same query then merging the results could slow you down. Also, are you sure you want to optimize for speed? Most of the time, speed is not a problem and you should worry what approach makes more sense.
1,053,793
I'm implementing a small time tracking app and I can't decide between two database designs. The first has all the log entries in a single table, ie. ``` TimeLog ------------- job_id : long timestamp start : boolean [or perhaps 'type : enum'] _id : long ``` The other option is to have two tables, one for 'start' entries the other for 'stop' entries. ``` StartLog StopLog ------------- ------------- job_id : long job_id : long timestamp timestamp id : long id : long ``` What are the pros and cons of each approach? Is there another alternative? My specific app will be running on SQLite and I'd like to optimise it for speed - but I am interested in generic arguments.
2009/06/27
[ "https://Stackoverflow.com/questions/1053793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48234/" ]
I would go for the first (single-table, type-differentiated) design, not particularly because there are too many tables, but simply because the database entities are very similar and would have similar constraints and operations.
The first option is the best by far. Both operations (Start/Stop) share common attributes. With this design you will be in a better position if the requirements change (for example if a "Cancel" operation gets created).
1,053,793
I'm implementing a small time tracking app and I can't decide between two database designs. The first has all the log entries in a single table, ie. ``` TimeLog ------------- job_id : long timestamp start : boolean [or perhaps 'type : enum'] _id : long ``` The other option is to have two tables, one for 'start' entries the other for 'stop' entries. ``` StartLog StopLog ------------- ------------- job_id : long job_id : long timestamp timestamp id : long id : long ``` What are the pros and cons of each approach? Is there another alternative? My specific app will be running on SQLite and I'd like to optimise it for speed - but I am interested in generic arguments.
2009/06/27
[ "https://Stackoverflow.com/questions/1053793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48234/" ]
I would go for the first (single-table, type-differentiated) design, not particularly because there are too many tables, but simply because the database entities are very similar and would have similar constraints and operations.
At the level of LOGICAL design, there is no question that the "two-tables" option is the correct one. At the level of PHYSICAL design, you might benefit frmo the one-table design if start/stop times are very often required together. You might wonder why to make this distinction. Keeping a clear view of logical design helps you keep a better overview of what kind of data is actually recorded in the database. Having a boolean attribute in one single table does not "obviously" tell you that it's about start versus stop times. Having two distinct "tables" (at the logical level) might better do that job, especially if they have the word "start" resp. "stop" in their names. The physical design level is where you must focus on performance, the best way to achieve which is usually to get data that is used together frequently, as physically close together as possible (and there rarely is anything closer than together in the same row).
1,053,793
I'm implementing a small time tracking app and I can't decide between two database designs. The first has all the log entries in a single table, ie. ``` TimeLog ------------- job_id : long timestamp start : boolean [or perhaps 'type : enum'] _id : long ``` The other option is to have two tables, one for 'start' entries the other for 'stop' entries. ``` StartLog StopLog ------------- ------------- job_id : long job_id : long timestamp timestamp id : long id : long ``` What are the pros and cons of each approach? Is there another alternative? My specific app will be running on SQLite and I'd like to optimise it for speed - but I am interested in generic arguments.
2009/06/27
[ "https://Stackoverflow.com/questions/1053793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48234/" ]
I would use the first design: a single database table. As Cade Roux said, the entities are very similar and would have similar constraints and a common set of operations. Additionally, I suggest renaming the `start` field to one called `type` with data type `enum`. Suppose at some point you would like to record other times, not just start and stop times. The most obvious example involves employers recording employees' breaks. Some employers pay their employees for short breaks, perhaps 15-minutes or less in duration. You *don't* want them to punch out completely (i.e., go "off the clock"), but you *do* want to indicate the fact that they have started their break period, for payroll calculations and legal purposes (e.g., mandatory breaks every `n` hours, as required by law). ``` Table "TimeLog" --------------- job_id : LONG timestamp : TIMESTAMP type : ENUM [ "punch-in", "punch-out", "break-start", "break-stop" ] _id : LONG ``` This could be easily accomplished with a `type` field with data type `enum`. You could have a `punch-in`, `punch-out`, `break-start`, and `break-stop`, in the case of the above example.
I think that depends on what queries will you use more. If you query most of the time only for start entries or stop entries, but not both, you will benefit from smaller table sizes. On the other hand, if you mostly use both parts in the same query then merging the results could slow you down. Also, are you sure you want to optimize for speed? Most of the time, speed is not a problem and you should worry what approach makes more sense.
1,053,793
I'm implementing a small time tracking app and I can't decide between two database designs. The first has all the log entries in a single table, ie. ``` TimeLog ------------- job_id : long timestamp start : boolean [or perhaps 'type : enum'] _id : long ``` The other option is to have two tables, one for 'start' entries the other for 'stop' entries. ``` StartLog StopLog ------------- ------------- job_id : long job_id : long timestamp timestamp id : long id : long ``` What are the pros and cons of each approach? Is there another alternative? My specific app will be running on SQLite and I'd like to optimise it for speed - but I am interested in generic arguments.
2009/06/27
[ "https://Stackoverflow.com/questions/1053793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48234/" ]
I think that depends on what queries will you use more. If you query most of the time only for start entries or stop entries, but not both, you will benefit from smaller table sizes. On the other hand, if you mostly use both parts in the same query then merging the results could slow you down. Also, are you sure you want to optimize for speed? Most of the time, speed is not a problem and you should worry what approach makes more sense.
At the level of LOGICAL design, there is no question that the "two-tables" option is the correct one. At the level of PHYSICAL design, you might benefit frmo the one-table design if start/stop times are very often required together. You might wonder why to make this distinction. Keeping a clear view of logical design helps you keep a better overview of what kind of data is actually recorded in the database. Having a boolean attribute in one single table does not "obviously" tell you that it's about start versus stop times. Having two distinct "tables" (at the logical level) might better do that job, especially if they have the word "start" resp. "stop" in their names. The physical design level is where you must focus on performance, the best way to achieve which is usually to get data that is used together frequently, as physically close together as possible (and there rarely is anything closer than together in the same row).
1,053,793
I'm implementing a small time tracking app and I can't decide between two database designs. The first has all the log entries in a single table, ie. ``` TimeLog ------------- job_id : long timestamp start : boolean [or perhaps 'type : enum'] _id : long ``` The other option is to have two tables, one for 'start' entries the other for 'stop' entries. ``` StartLog StopLog ------------- ------------- job_id : long job_id : long timestamp timestamp id : long id : long ``` What are the pros and cons of each approach? Is there another alternative? My specific app will be running on SQLite and I'd like to optimise it for speed - but I am interested in generic arguments.
2009/06/27
[ "https://Stackoverflow.com/questions/1053793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48234/" ]
I would use the first design: a single database table. As Cade Roux said, the entities are very similar and would have similar constraints and a common set of operations. Additionally, I suggest renaming the `start` field to one called `type` with data type `enum`. Suppose at some point you would like to record other times, not just start and stop times. The most obvious example involves employers recording employees' breaks. Some employers pay their employees for short breaks, perhaps 15-minutes or less in duration. You *don't* want them to punch out completely (i.e., go "off the clock"), but you *do* want to indicate the fact that they have started their break period, for payroll calculations and legal purposes (e.g., mandatory breaks every `n` hours, as required by law). ``` Table "TimeLog" --------------- job_id : LONG timestamp : TIMESTAMP type : ENUM [ "punch-in", "punch-out", "break-start", "break-stop" ] _id : LONG ``` This could be easily accomplished with a `type` field with data type `enum`. You could have a `punch-in`, `punch-out`, `break-start`, and `break-stop`, in the case of the above example.
The first option is the best by far. Both operations (Start/Stop) share common attributes. With this design you will be in a better position if the requirements change (for example if a "Cancel" operation gets created).
1,053,793
I'm implementing a small time tracking app and I can't decide between two database designs. The first has all the log entries in a single table, ie. ``` TimeLog ------------- job_id : long timestamp start : boolean [or perhaps 'type : enum'] _id : long ``` The other option is to have two tables, one for 'start' entries the other for 'stop' entries. ``` StartLog StopLog ------------- ------------- job_id : long job_id : long timestamp timestamp id : long id : long ``` What are the pros and cons of each approach? Is there another alternative? My specific app will be running on SQLite and I'd like to optimise it for speed - but I am interested in generic arguments.
2009/06/27
[ "https://Stackoverflow.com/questions/1053793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48234/" ]
The first option is the best by far. Both operations (Start/Stop) share common attributes. With this design you will be in a better position if the requirements change (for example if a "Cancel" operation gets created).
At the level of LOGICAL design, there is no question that the "two-tables" option is the correct one. At the level of PHYSICAL design, you might benefit frmo the one-table design if start/stop times are very often required together. You might wonder why to make this distinction. Keeping a clear view of logical design helps you keep a better overview of what kind of data is actually recorded in the database. Having a boolean attribute in one single table does not "obviously" tell you that it's about start versus stop times. Having two distinct "tables" (at the logical level) might better do that job, especially if they have the word "start" resp. "stop" in their names. The physical design level is where you must focus on performance, the best way to achieve which is usually to get data that is used together frequently, as physically close together as possible (and there rarely is anything closer than together in the same row).
1,053,793
I'm implementing a small time tracking app and I can't decide between two database designs. The first has all the log entries in a single table, ie. ``` TimeLog ------------- job_id : long timestamp start : boolean [or perhaps 'type : enum'] _id : long ``` The other option is to have two tables, one for 'start' entries the other for 'stop' entries. ``` StartLog StopLog ------------- ------------- job_id : long job_id : long timestamp timestamp id : long id : long ``` What are the pros and cons of each approach? Is there another alternative? My specific app will be running on SQLite and I'd like to optimise it for speed - but I am interested in generic arguments.
2009/06/27
[ "https://Stackoverflow.com/questions/1053793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48234/" ]
I would use the first design: a single database table. As Cade Roux said, the entities are very similar and would have similar constraints and a common set of operations. Additionally, I suggest renaming the `start` field to one called `type` with data type `enum`. Suppose at some point you would like to record other times, not just start and stop times. The most obvious example involves employers recording employees' breaks. Some employers pay their employees for short breaks, perhaps 15-minutes or less in duration. You *don't* want them to punch out completely (i.e., go "off the clock"), but you *do* want to indicate the fact that they have started their break period, for payroll calculations and legal purposes (e.g., mandatory breaks every `n` hours, as required by law). ``` Table "TimeLog" --------------- job_id : LONG timestamp : TIMESTAMP type : ENUM [ "punch-in", "punch-out", "break-start", "break-stop" ] _id : LONG ``` This could be easily accomplished with a `type` field with data type `enum`. You could have a `punch-in`, `punch-out`, `break-start`, and `break-stop`, in the case of the above example.
At the level of LOGICAL design, there is no question that the "two-tables" option is the correct one. At the level of PHYSICAL design, you might benefit frmo the one-table design if start/stop times are very often required together. You might wonder why to make this distinction. Keeping a clear view of logical design helps you keep a better overview of what kind of data is actually recorded in the database. Having a boolean attribute in one single table does not "obviously" tell you that it's about start versus stop times. Having two distinct "tables" (at the logical level) might better do that job, especially if they have the word "start" resp. "stop" in their names. The physical design level is where you must focus on performance, the best way to achieve which is usually to get data that is used together frequently, as physically close together as possible (and there rarely is anything closer than together in the same row).
193,398
Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow using the unsigned 64-bit integers, and then being able to put them back together in to a string (which would solve the issue of multiplied result storage). Any ideas?
2008/10/10
[ "https://Stackoverflow.com/questions/193398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14322/" ]
Most languages have functions or libraries that do this, usually called a Bignum library ([GMP](http://gmplib.org/) is a good one.) If you want to do it yourself, I would do it the same way that people do long multiplication on paper. To do this you could either work with strings containing the number, or do it in binary using bitwise operations. Example: ``` 45 x67 --- 315 +270 ---- 585 ``` Or in binary: ``` 101 x101 ---- 101 000 +101 ------ 11001 ``` **Edit:** After doing it in binary I realized that it would be much simpler (and faster of course) to code using bitwise operations instead of strings containing the base-10 numbers. I've edited my binary multiplying example to show a pattern: for each 1-bit in the bottom number, add the top number, bit-shifted left *the position of the 1-bit* times to a variable. At the end, that variable will contain the product. To store the product, you'll have to have two 64-bit numbers and imagine one of them being the first 64 bits and the other one the second 64 bits of the product. You'll have to write code that carries the addition from bit 63 of the second number to bit 0 of the first number.
```js //Here is a JavaScript version of an Karatsuba Algorithm running with less time than the usual multiplication method function range(start, stop, step) { if (typeof stop == 'undefined') { // one param defined stop = start; start = 0; } if (typeof step == 'undefined') { step = 1; } if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) { return []; } var result = []; for (var i = start; step > 0 ? i < stop : i > stop; i += step) { result.push(i); } return result; }; function zeroPad(numberString, zeros, left = true) { //Return the string with zeros added to the left or right. for (var i in range(zeros)) { if (left) numberString = '0' + numberString else numberString = numberString + '0' } return numberString } function largeMultiplication(x, y) { x = x.toString(); y = y.toString(); if (x.length == 1 && y.length == 1) return parseInt(x) * parseInt(y) if (x.length < y.length) x = zeroPad(x, y.length - x.length); else y = zeroPad(y, x.length - y.length); n = x.length j = Math.floor(n/2); //for odd digit integers if ( n % 2 != 0) j += 1 var BZeroPadding = n - j var AZeroPadding = BZeroPadding * 2 a = parseInt(x.substring(0,j)); b = parseInt(x.substring(j)); c = parseInt(y.substring(0,j)); d = parseInt(y.substring(j)); //recursively calculate ac = largeMultiplication(a, c) bd = largeMultiplication(b, d) k = largeMultiplication(a + b, c + d) A = parseInt(zeroPad(ac.toString(), AZeroPadding, false)) B = parseInt(zeroPad((k - ac - bd).toString(), BZeroPadding, false)) return A + B + bd } //testing the function here example = largeMultiplication(12, 34) console.log(example) ```
193,398
Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow using the unsigned 64-bit integers, and then being able to put them back together in to a string (which would solve the issue of multiplied result storage). Any ideas?
2008/10/10
[ "https://Stackoverflow.com/questions/193398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14322/" ]
Yes, you do it using a datatype that is effectively a string of digits (just like a normal 'string' is a string of characters). How you do this is highly language-dependent. For instance, Java uses BigDecimal. What language are you using?
Here is my code piece in C. Good old multiply method ```c char *multiply(char s1[], char s2[]) { int l1 = strlen(s1); int l2 = strlen(s2); int i, j, k = 0, c = 0; char *r = (char *) malloc (l1+l2+1); // add one byte for the zero terminating string int temp; strrev(s1); strrev(s2); for (i = 0;i <l1+l2; i++) { r[i] = 0 + '0'; } for (i = 0; i <l1; i ++) { c = 0; k = i; for (j = 0; j < l2; j++) { temp = get_int(s1[i]) * get_int(s2[j]); temp = temp + c + get_int(r[k]); c = temp /10; r[k] = temp%10 + '0'; k++; } if (c!=0) { r[k] = c + '0'; k++; } } r[k] = '\0'; strrev(r); return r; } ```
193,398
Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow using the unsigned 64-bit integers, and then being able to put them back together in to a string (which would solve the issue of multiplied result storage). Any ideas?
2008/10/10
[ "https://Stackoverflow.com/questions/193398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14322/" ]
This is often given as a homework assignment. The algorithm you learned in grade school will work. Use a library (several are mentioned in other posts) if you need this for a real application.
```js //Here is a JavaScript version of an Karatsuba Algorithm running with less time than the usual multiplication method function range(start, stop, step) { if (typeof stop == 'undefined') { // one param defined stop = start; start = 0; } if (typeof step == 'undefined') { step = 1; } if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) { return []; } var result = []; for (var i = start; step > 0 ? i < stop : i > stop; i += step) { result.push(i); } return result; }; function zeroPad(numberString, zeros, left = true) { //Return the string with zeros added to the left or right. for (var i in range(zeros)) { if (left) numberString = '0' + numberString else numberString = numberString + '0' } return numberString } function largeMultiplication(x, y) { x = x.toString(); y = y.toString(); if (x.length == 1 && y.length == 1) return parseInt(x) * parseInt(y) if (x.length < y.length) x = zeroPad(x, y.length - x.length); else y = zeroPad(y, x.length - y.length); n = x.length j = Math.floor(n/2); //for odd digit integers if ( n % 2 != 0) j += 1 var BZeroPadding = n - j var AZeroPadding = BZeroPadding * 2 a = parseInt(x.substring(0,j)); b = parseInt(x.substring(j)); c = parseInt(y.substring(0,j)); d = parseInt(y.substring(j)); //recursively calculate ac = largeMultiplication(a, c) bd = largeMultiplication(b, d) k = largeMultiplication(a + b, c + d) A = parseInt(zeroPad(ac.toString(), AZeroPadding, false)) B = parseInt(zeroPad((k - ac - bd).toString(), BZeroPadding, false)) return A + B + bd } //testing the function here example = largeMultiplication(12, 34) console.log(example) ```
193,398
Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow using the unsigned 64-bit integers, and then being able to put them back together in to a string (which would solve the issue of multiplied result storage). Any ideas?
2008/10/10
[ "https://Stackoverflow.com/questions/193398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14322/" ]
The simplest way would be to use the schoolbook mechanism, splitting your arbitrarily sized numbers into chunks of 32-bit each. Given A B C D \* E F G H (each chunk 32-bit, for a total 128 bit) You need an output array 9 dwords wide. Set Out[0..8] to 0 You'd start by doing: H \* D + out[8] => 64 bit result. Store the low 32-bits in out[8] and take the high 32-bits as carry Next: (H \* C) + out[7] + carry Again, store low 32-bit in out[7], use the high 32-bits as carry after doing H\*A + out[4] + carry, you need to continue looping until you have no carry. Then repeat with G, F, E. For G, you'd start at out[7] instead of out[8], and so forth. Finally, walk through and convert the large integer into digits (which will require a "divide large number by a single word" routine)
```js //Here is a JavaScript version of an Karatsuba Algorithm running with less time than the usual multiplication method function range(start, stop, step) { if (typeof stop == 'undefined') { // one param defined stop = start; start = 0; } if (typeof step == 'undefined') { step = 1; } if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) { return []; } var result = []; for (var i = start; step > 0 ? i < stop : i > stop; i += step) { result.push(i); } return result; }; function zeroPad(numberString, zeros, left = true) { //Return the string with zeros added to the left or right. for (var i in range(zeros)) { if (left) numberString = '0' + numberString else numberString = numberString + '0' } return numberString } function largeMultiplication(x, y) { x = x.toString(); y = y.toString(); if (x.length == 1 && y.length == 1) return parseInt(x) * parseInt(y) if (x.length < y.length) x = zeroPad(x, y.length - x.length); else y = zeroPad(y, x.length - y.length); n = x.length j = Math.floor(n/2); //for odd digit integers if ( n % 2 != 0) j += 1 var BZeroPadding = n - j var AZeroPadding = BZeroPadding * 2 a = parseInt(x.substring(0,j)); b = parseInt(x.substring(j)); c = parseInt(y.substring(0,j)); d = parseInt(y.substring(j)); //recursively calculate ac = largeMultiplication(a, c) bd = largeMultiplication(b, d) k = largeMultiplication(a + b, c + d) A = parseInt(zeroPad(ac.toString(), AZeroPadding, false)) B = parseInt(zeroPad((k - ac - bd).toString(), BZeroPadding, false)) return A + B + bd } //testing the function here example = largeMultiplication(12, 34) console.log(example) ```
193,398
Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow using the unsigned 64-bit integers, and then being able to put them back together in to a string (which would solve the issue of multiplied result storage). Any ideas?
2008/10/10
[ "https://Stackoverflow.com/questions/193398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14322/" ]
Yes, you do it using a datatype that is effectively a string of digits (just like a normal 'string' is a string of characters). How you do this is highly language-dependent. For instance, Java uses BigDecimal. What language are you using?
```js //Here is a JavaScript version of an Karatsuba Algorithm running with less time than the usual multiplication method function range(start, stop, step) { if (typeof stop == 'undefined') { // one param defined stop = start; start = 0; } if (typeof step == 'undefined') { step = 1; } if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) { return []; } var result = []; for (var i = start; step > 0 ? i < stop : i > stop; i += step) { result.push(i); } return result; }; function zeroPad(numberString, zeros, left = true) { //Return the string with zeros added to the left or right. for (var i in range(zeros)) { if (left) numberString = '0' + numberString else numberString = numberString + '0' } return numberString } function largeMultiplication(x, y) { x = x.toString(); y = y.toString(); if (x.length == 1 && y.length == 1) return parseInt(x) * parseInt(y) if (x.length < y.length) x = zeroPad(x, y.length - x.length); else y = zeroPad(y, x.length - y.length); n = x.length j = Math.floor(n/2); //for odd digit integers if ( n % 2 != 0) j += 1 var BZeroPadding = n - j var AZeroPadding = BZeroPadding * 2 a = parseInt(x.substring(0,j)); b = parseInt(x.substring(j)); c = parseInt(y.substring(0,j)); d = parseInt(y.substring(j)); //recursively calculate ac = largeMultiplication(a, c) bd = largeMultiplication(b, d) k = largeMultiplication(a + b, c + d) A = parseInt(zeroPad(ac.toString(), AZeroPadding, false)) B = parseInt(zeroPad((k - ac - bd).toString(), BZeroPadding, false)) return A + B + bd } //testing the function here example = largeMultiplication(12, 34) console.log(example) ```
193,398
Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow using the unsigned 64-bit integers, and then being able to put them back together in to a string (which would solve the issue of multiplied result storage). Any ideas?
2008/10/10
[ "https://Stackoverflow.com/questions/193398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14322/" ]
If you can't use an existing bignum library like GMP, check out [Wikipedia's article on binary multiplication with computers](http://en.wikipedia.org/wiki/Multiplication_algorithm#Multiplication_algorithms_for_computer_algebra). There are a number of good, efficient algorithms for this.
This is often given as a homework assignment. The algorithm you learned in grade school will work. Use a library (several are mentioned in other posts) if you need this for a real application.
193,398
Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow using the unsigned 64-bit integers, and then being able to put them back together in to a string (which would solve the issue of multiplied result storage). Any ideas?
2008/10/10
[ "https://Stackoverflow.com/questions/193398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14322/" ]
Most languages have functions or libraries that do this, usually called a Bignum library ([GMP](http://gmplib.org/) is a good one.) If you want to do it yourself, I would do it the same way that people do long multiplication on paper. To do this you could either work with strings containing the number, or do it in binary using bitwise operations. Example: ``` 45 x67 --- 315 +270 ---- 585 ``` Or in binary: ``` 101 x101 ---- 101 000 +101 ------ 11001 ``` **Edit:** After doing it in binary I realized that it would be much simpler (and faster of course) to code using bitwise operations instead of strings containing the base-10 numbers. I've edited my binary multiplying example to show a pattern: for each 1-bit in the bottom number, add the top number, bit-shifted left *the position of the 1-bit* times to a variable. At the end, that variable will contain the product. To store the product, you'll have to have two 64-bit numbers and imagine one of them being the first 64 bits and the other one the second 64 bits of the product. You'll have to write code that carries the addition from bit 63 of the second number to bit 0 of the first number.
Yes, you do it using a datatype that is effectively a string of digits (just like a normal 'string' is a string of characters). How you do this is highly language-dependent. For instance, Java uses BigDecimal. What language are you using?
193,398
Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow using the unsigned 64-bit integers, and then being able to put them back together in to a string (which would solve the issue of multiplied result storage). Any ideas?
2008/10/10
[ "https://Stackoverflow.com/questions/193398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14322/" ]
The simplest way would be to use the schoolbook mechanism, splitting your arbitrarily sized numbers into chunks of 32-bit each. Given A B C D \* E F G H (each chunk 32-bit, for a total 128 bit) You need an output array 9 dwords wide. Set Out[0..8] to 0 You'd start by doing: H \* D + out[8] => 64 bit result. Store the low 32-bits in out[8] and take the high 32-bits as carry Next: (H \* C) + out[7] + carry Again, store low 32-bit in out[7], use the high 32-bits as carry after doing H\*A + out[4] + carry, you need to continue looping until you have no carry. Then repeat with G, F, E. For G, you'd start at out[7] instead of out[8], and so forth. Finally, walk through and convert the large integer into digits (which will require a "divide large number by a single word" routine)
Here is my code piece in C. Good old multiply method ```c char *multiply(char s1[], char s2[]) { int l1 = strlen(s1); int l2 = strlen(s2); int i, j, k = 0, c = 0; char *r = (char *) malloc (l1+l2+1); // add one byte for the zero terminating string int temp; strrev(s1); strrev(s2); for (i = 0;i <l1+l2; i++) { r[i] = 0 + '0'; } for (i = 0; i <l1; i ++) { c = 0; k = i; for (j = 0; j < l2; j++) { temp = get_int(s1[i]) * get_int(s2[j]); temp = temp + c + get_int(r[k]); c = temp /10; r[k] = temp%10 + '0'; k++; } if (c!=0) { r[k] = c + '0'; k++; } } r[k] = '\0'; strrev(r); return r; } ```
193,398
Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow using the unsigned 64-bit integers, and then being able to put them back together in to a string (which would solve the issue of multiplied result storage). Any ideas?
2008/10/10
[ "https://Stackoverflow.com/questions/193398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14322/" ]
This is often given as a homework assignment. The algorithm you learned in grade school will work. Use a library (several are mentioned in other posts) if you need this for a real application.
Here is my code piece in C. Good old multiply method ```c char *multiply(char s1[], char s2[]) { int l1 = strlen(s1); int l2 = strlen(s2); int i, j, k = 0, c = 0; char *r = (char *) malloc (l1+l2+1); // add one byte for the zero terminating string int temp; strrev(s1); strrev(s2); for (i = 0;i <l1+l2; i++) { r[i] = 0 + '0'; } for (i = 0; i <l1; i ++) { c = 0; k = i; for (j = 0; j < l2; j++) { temp = get_int(s1[i]) * get_int(s2[j]); temp = temp + c + get_int(r[k]); c = temp /10; r[k] = temp%10 + '0'; k++; } if (c!=0) { r[k] = c + '0'; k++; } } r[k] = '\0'; strrev(r); return r; } ```
193,398
Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum integer size of 18446744073709551615). Realistically, I would like to be able to do this by breaking up each number, processing them somehow using the unsigned 64-bit integers, and then being able to put them back together in to a string (which would solve the issue of multiplied result storage). Any ideas?
2008/10/10
[ "https://Stackoverflow.com/questions/193398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14322/" ]
Most languages have functions or libraries that do this, usually called a Bignum library ([GMP](http://gmplib.org/) is a good one.) If you want to do it yourself, I would do it the same way that people do long multiplication on paper. To do this you could either work with strings containing the number, or do it in binary using bitwise operations. Example: ``` 45 x67 --- 315 +270 ---- 585 ``` Or in binary: ``` 101 x101 ---- 101 000 +101 ------ 11001 ``` **Edit:** After doing it in binary I realized that it would be much simpler (and faster of course) to code using bitwise operations instead of strings containing the base-10 numbers. I've edited my binary multiplying example to show a pattern: for each 1-bit in the bottom number, add the top number, bit-shifted left *the position of the 1-bit* times to a variable. At the end, that variable will contain the product. To store the product, you'll have to have two 64-bit numbers and imagine one of them being the first 64 bits and the other one the second 64 bits of the product. You'll have to write code that carries the addition from bit 63 of the second number to bit 0 of the first number.
Here is my code piece in C. Good old multiply method ```c char *multiply(char s1[], char s2[]) { int l1 = strlen(s1); int l2 = strlen(s2); int i, j, k = 0, c = 0; char *r = (char *) malloc (l1+l2+1); // add one byte for the zero terminating string int temp; strrev(s1); strrev(s2); for (i = 0;i <l1+l2; i++) { r[i] = 0 + '0'; } for (i = 0; i <l1; i ++) { c = 0; k = i; for (j = 0; j < l2; j++) { temp = get_int(s1[i]) * get_int(s2[j]); temp = temp + c + get_int(r[k]); c = temp /10; r[k] = temp%10 + '0'; k++; } if (c!=0) { r[k] = c + '0'; k++; } } r[k] = '\0'; strrev(r); return r; } ```
2,137,297
Like alert bar of stackoverflow here. It should not be `position:fixed`,because it's not supported by all browsers. Absolutely,neither will `position:absolute` do.
2010/01/26
[ "https://Stackoverflow.com/questions/2137297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/258968/" ]
Put the div under the body tag, give it position absolute, top:0, left:0 And if you want it to push the content, just put it there without the CSS I gave you.
Make sure the element is directly nested under the body tag, use css with absolute position and top:0; By the way, fixed is used by a large majority of the browsers.
2,137,297
Like alert bar of stackoverflow here. It should not be `position:fixed`,because it's not supported by all browsers. Absolutely,neither will `position:absolute` do.
2010/01/26
[ "https://Stackoverflow.com/questions/2137297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/258968/" ]
Put the div under the body tag, give it position absolute, top:0, left:0 And if you want it to push the content, just put it there without the CSS I gave you.
Only fixed positioning does this, unless you want to use javascript. Which you don't, because it's an ugly way of doing it.
2,137,297
Like alert bar of stackoverflow here. It should not be `position:fixed`,because it's not supported by all browsers. Absolutely,neither will `position:absolute` do.
2010/01/26
[ "https://Stackoverflow.com/questions/2137297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/258968/" ]
Put the div under the body tag, give it position absolute, top:0, left:0 And if you want it to push the content, just put it there without the CSS I gave you.
Just do it like SO does it. Use the "notifycontainer" and populate it with InnerHTML from JavaScript when you need to. Since it's a relative positioning, when you rewrite the InnerHTML the page rerenders based on the contents of the div as they are at that moment. Same deal when you want to clear the alert, you just rewrite the InnerHTML. You don't even need to write animation code. The way browsers render now, the animation will be automagical.
2,137,297
Like alert bar of stackoverflow here. It should not be `position:fixed`,because it's not supported by all browsers. Absolutely,neither will `position:absolute` do.
2010/01/26
[ "https://Stackoverflow.com/questions/2137297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/258968/" ]
You could always use EMCAscript or one of its forms (JScript, JavaScript) to calculate the position of the viewport and set the position equal to that. ``` function positionView() { return (window.pageYOffset) ? window.pageYOffset : (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop; } function setPosition(object) { object.style.top = positionView() + "px"; } ``` Then just pass in the DIV object you want to use, with `document.getElementById`. I'd use `position: fixed;`. Many people still use IE6, though, which does not support it.
Make sure the element is directly nested under the body tag, use css with absolute position and top:0; By the way, fixed is used by a large majority of the browsers.
2,137,297
Like alert bar of stackoverflow here. It should not be `position:fixed`,because it's not supported by all browsers. Absolutely,neither will `position:absolute` do.
2010/01/26
[ "https://Stackoverflow.com/questions/2137297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/258968/" ]
Its very simple step if you are using any class in css apply one more property **z-index = 1;** it will make that div to always on top, if that div is relative to its parent div.
Make sure the element is directly nested under the body tag, use css with absolute position and top:0; By the way, fixed is used by a large majority of the browsers.
2,137,297
Like alert bar of stackoverflow here. It should not be `position:fixed`,because it's not supported by all browsers. Absolutely,neither will `position:absolute` do.
2010/01/26
[ "https://Stackoverflow.com/questions/2137297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/258968/" ]
You could always use EMCAscript or one of its forms (JScript, JavaScript) to calculate the position of the viewport and set the position equal to that. ``` function positionView() { return (window.pageYOffset) ? window.pageYOffset : (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop; } function setPosition(object) { object.style.top = positionView() + "px"; } ``` Then just pass in the DIV object you want to use, with `document.getElementById`. I'd use `position: fixed;`. Many people still use IE6, though, which does not support it.
Only fixed positioning does this, unless you want to use javascript. Which you don't, because it's an ugly way of doing it.
2,137,297
Like alert bar of stackoverflow here. It should not be `position:fixed`,because it's not supported by all browsers. Absolutely,neither will `position:absolute` do.
2010/01/26
[ "https://Stackoverflow.com/questions/2137297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/258968/" ]
Its very simple step if you are using any class in css apply one more property **z-index = 1;** it will make that div to always on top, if that div is relative to its parent div.
Only fixed positioning does this, unless you want to use javascript. Which you don't, because it's an ugly way of doing it.
2,137,297
Like alert bar of stackoverflow here. It should not be `position:fixed`,because it's not supported by all browsers. Absolutely,neither will `position:absolute` do.
2010/01/26
[ "https://Stackoverflow.com/questions/2137297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/258968/" ]
You could always use EMCAscript or one of its forms (JScript, JavaScript) to calculate the position of the viewport and set the position equal to that. ``` function positionView() { return (window.pageYOffset) ? window.pageYOffset : (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop; } function setPosition(object) { object.style.top = positionView() + "px"; } ``` Then just pass in the DIV object you want to use, with `document.getElementById`. I'd use `position: fixed;`. Many people still use IE6, though, which does not support it.
Just do it like SO does it. Use the "notifycontainer" and populate it with InnerHTML from JavaScript when you need to. Since it's a relative positioning, when you rewrite the InnerHTML the page rerenders based on the contents of the div as they are at that moment. Same deal when you want to clear the alert, you just rewrite the InnerHTML. You don't even need to write animation code. The way browsers render now, the animation will be automagical.
2,137,297
Like alert bar of stackoverflow here. It should not be `position:fixed`,because it's not supported by all browsers. Absolutely,neither will `position:absolute` do.
2010/01/26
[ "https://Stackoverflow.com/questions/2137297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/258968/" ]
Its very simple step if you are using any class in css apply one more property **z-index = 1;** it will make that div to always on top, if that div is relative to its parent div.
Just do it like SO does it. Use the "notifycontainer" and populate it with InnerHTML from JavaScript when you need to. Since it's a relative positioning, when you rewrite the InnerHTML the page rerenders based on the contents of the div as they are at that moment. Same deal when you want to clear the alert, you just rewrite the InnerHTML. You don't even need to write animation code. The way browsers render now, the animation will be automagical.
394,871
This is about a school assignment so I'm trying to do things by the book. I feel like I'm getting the grips of Java, but good programming practice, design patterns, etc. are all rather new to me. I've made my model and it works fine. It contains a student class which contains a number of fields with student information (obviously). Now I want this information to be displayed in a couple of JLabels. It is easiest to pass a whole student object to the GUI and use JLabel.settext.getname() etc. a number of times and no doubt this will work perfectly. But I feel that the student object is part of the model and by passing it to the GUI I'm not using a MVC pattern anymore. Am I right here? I did make a controller object for passing data to and from the model and the GUI but for passing only strings to the labels or setting the JLabel text through the controller, I need either a lot of setters in the GUI, or I would have to make all JLabels global fields which doesn't feel good either. Any advice on this?
2008/12/27
[ "https://Stackoverflow.com/questions/394871", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49349/" ]
the GUI should worry about all the interface stuff. I guess you have a class that is your GUI for doing 'stuff' to the student with your JLabels. Just pass your student instance to this class and let it do what it needs to do. When it is done it will call a controller method to do whatever needs to be done. OOD deals with passing the objects around that you want to manipulate. You don't need to break the objects apart for passing in MVC. You are supposed to pass that around really if this is a general case. The model defines the data objects that you will be working with... or more specifically the system will be working with (controller) and the users will be working with (GUI). These class are built to be passed around. You will have to do a lot more work if you un-encapsulate all the information hehe :)
The view needs your model to create the UI (pull from model) and to receive updates from it (push by model). Ideally the model is presented to the view in read-only fashion. Controllers would provide the methods that the view will use to update the model, for a nice separation of concerns. There are many different forms and interpretations of what MVC exactly is, try Googling it. Also, you can often find MVC on different levels in your application (e.g. Swing model, your domain model, ...). With MVC and variants on MVC, the most important thing is that you can explain individual subpatterns (Observer, Facade, ...) and defend the design choices you made (advantages/disadvantages) instead of trying to implement **the** one and only unique MVC pattern, if it would exist. So my advice for your assignment, if possible of course, would be to implement something that works well, inspired by what you've read on MVC and its subpatterns, and only afterwards see how well it agrees or disagrees with some "traditional" descriptions of MVC patterns you can find.
394,871
This is about a school assignment so I'm trying to do things by the book. I feel like I'm getting the grips of Java, but good programming practice, design patterns, etc. are all rather new to me. I've made my model and it works fine. It contains a student class which contains a number of fields with student information (obviously). Now I want this information to be displayed in a couple of JLabels. It is easiest to pass a whole student object to the GUI and use JLabel.settext.getname() etc. a number of times and no doubt this will work perfectly. But I feel that the student object is part of the model and by passing it to the GUI I'm not using a MVC pattern anymore. Am I right here? I did make a controller object for passing data to and from the model and the GUI but for passing only strings to the labels or setting the JLabel text through the controller, I need either a lot of setters in the GUI, or I would have to make all JLabels global fields which doesn't feel good either. Any advice on this?
2008/12/27
[ "https://Stackoverflow.com/questions/394871", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49349/" ]
Note that the Swing components all use the MVC pattern internally, so they already have a model. This is more relevant with complex widgets like JTable, where you definitely want your model to implement the `TableModel` interface. The big question is how to reconcile your domain model with the internal models of the individual Swing components. One way to do this is to have `setModel()` and `getModel()` methods in your GUI class, which translate between them, i.e. `setModel()` takes your model and calls `setText()` on the individual JLabels, etc.
The view needs your model to create the UI (pull from model) and to receive updates from it (push by model). Ideally the model is presented to the view in read-only fashion. Controllers would provide the methods that the view will use to update the model, for a nice separation of concerns. There are many different forms and interpretations of what MVC exactly is, try Googling it. Also, you can often find MVC on different levels in your application (e.g. Swing model, your domain model, ...). With MVC and variants on MVC, the most important thing is that you can explain individual subpatterns (Observer, Facade, ...) and defend the design choices you made (advantages/disadvantages) instead of trying to implement **the** one and only unique MVC pattern, if it would exist. So my advice for your assignment, if possible of course, would be to implement something that works well, inspired by what you've read on MVC and its subpatterns, and only afterwards see how well it agrees or disagrees with some "traditional" descriptions of MVC patterns you can find.
133,648
I want to insert say 50,000 records into sql server database 2000 at a time. How to accomplish this?
2008/09/25
[ "https://Stackoverflow.com/questions/133648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1688440/" ]
You can use the SELECT TOP clause: in MSSQL 2005 it was extended allowing you to use a variable to specify the number of records (older version allowed only a numeric constant) You can try something like this: (untested, because I have no access to a MSSQL2005 at the moment) ``` begin declare @n int, @rows int select @rows = count(*) from sourcetable select @n=0 while @n < @rows begin insert into desttable select top 2000 * from sourcetable where id_sourcetable not in (select top (@n) id_sourcetable from sourcetable order by id_sourcetable) order by id_sourcetable select @n=@n+2000 end end ```
Do you mean for a test of some kind? ``` declare @index integer set @index = 0 while @index < 50000 begin insert into table values (x,y,z) set @index = @index + 1 end ``` But I expect this is not what you mean. If you mean the best way to do a bulk insert, use `BULK INSERT` or something like `bcp`
133,648
I want to insert say 50,000 records into sql server database 2000 at a time. How to accomplish this?
2008/09/25
[ "https://Stackoverflow.com/questions/133648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1688440/" ]
You can use the SELECT TOP clause: in MSSQL 2005 it was extended allowing you to use a variable to specify the number of records (older version allowed only a numeric constant) You can try something like this: (untested, because I have no access to a MSSQL2005 at the moment) ``` begin declare @n int, @rows int select @rows = count(*) from sourcetable select @n=0 while @n < @rows begin insert into desttable select top 2000 * from sourcetable where id_sourcetable not in (select top (@n) id_sourcetable from sourcetable order by id_sourcetable) order by id_sourcetable select @n=@n+2000 end end ```
Are you inserting from another db/table, programmatically or from a flat file?
133,648
I want to insert say 50,000 records into sql server database 2000 at a time. How to accomplish this?
2008/09/25
[ "https://Stackoverflow.com/questions/133648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1688440/" ]
You can use the SELECT TOP clause: in MSSQL 2005 it was extended allowing you to use a variable to specify the number of records (older version allowed only a numeric constant) You can try something like this: (untested, because I have no access to a MSSQL2005 at the moment) ``` begin declare @n int, @rows int select @rows = count(*) from sourcetable select @n=0 while @n < @rows begin insert into desttable select top 2000 * from sourcetable where id_sourcetable not in (select top (@n) id_sourcetable from sourcetable order by id_sourcetable) order by id_sourcetable select @n=@n+2000 end end ```
From an external data source [bcp](http://msdn.microsoft.com/en-us/library/ms162802.aspx) can be used to import the data. The -b switch allows you to specify a batch size.
133,648
I want to insert say 50,000 records into sql server database 2000 at a time. How to accomplish this?
2008/09/25
[ "https://Stackoverflow.com/questions/133648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1688440/" ]
You can use the SELECT TOP clause: in MSSQL 2005 it was extended allowing you to use a variable to specify the number of records (older version allowed only a numeric constant) You can try something like this: (untested, because I have no access to a MSSQL2005 at the moment) ``` begin declare @n int, @rows int select @rows = count(*) from sourcetable select @n=0 while @n < @rows begin insert into desttable select top 2000 * from sourcetable where id_sourcetable not in (select top (@n) id_sourcetable from sourcetable order by id_sourcetable) order by id_sourcetable select @n=@n+2000 end end ```
declare @rows as int set @rows = 1 while @rows >0 begin ----- ``` insert mytable (field1, field2, field3) select top 2000 pa.field1, pa.field2, pa.field3 from table1 pa (nolock) left join mytable ta (nolock)on ta.field2 = pa.feild2 and ta.field3 = pa.field3 and ta.field1 = pa.field1 where ta.field1 is null order by pa.field1 ``` set @rows = @@rowcount end This is code we are currently using in production in SQL Server 2000 with table and fieldnames changed.
133,648
I want to insert say 50,000 records into sql server database 2000 at a time. How to accomplish this?
2008/09/25
[ "https://Stackoverflow.com/questions/133648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1688440/" ]
You can use the SELECT TOP clause: in MSSQL 2005 it was extended allowing you to use a variable to specify the number of records (older version allowed only a numeric constant) You can try something like this: (untested, because I have no access to a MSSQL2005 at the moment) ``` begin declare @n int, @rows int select @rows = count(*) from sourcetable select @n=0 while @n < @rows begin insert into desttable select top 2000 * from sourcetable where id_sourcetable not in (select top (@n) id_sourcetable from sourcetable order by id_sourcetable) order by id_sourcetable select @n=@n+2000 end end ```
With SQL 2000, I'd probably lean on DTS to do this depending on where the data was located. You can specifically tell DTS what to use for a batch commit size. Otherwise, a modified version of the SQL 2005 batch solution would be good. I don't think you can use TOP with a variable in SQL 2000.
1,506,101
I'm working with an unchangeable legacy database schema where each instance of an object has its own table in the database with associated records. I need to change a model's `useTable` every time the model is instantiated, but retain Cake's nice caching and what not. Say I have many pad objects, which each have several note objects (Note belongsTo Pad, Pad hasMany Note). Each pad has a record in the pads table, however every note has it's own table in a database (say entitled 'pad\_{id}'). This schema is fixed and I must use it. Right now I don't have to do any saving, so I do this in the model's before find to support reading: ``` function beforeFind($query_data) { if(empty($query_data['pad_id'])) { return false; } else { $this->useTable = $query_data['pad_id']; parent::__construct(); return $query_data; } } ``` This changes the model's table used in the database, and works fine when `Core::debug > 0`. However, when it's zero, I think CakePHP caches the model code and doesn't properly change the table. In any case, I get a 404 error when I visit /pads/view/{pad\_id} or whatever action dynamically changes this table. I can't quite figure out what the exact error is, because it works fine when I turn debug on. So any pointers on debuging this issue would help also. Thanks!
2009/10/01
[ "https://Stackoverflow.com/questions/1506101", "https://Stackoverflow.com", "https://Stackoverflow.com/users/93943/" ]
You should be able to use `setSource()` to change the table the Model is using. `$this->setSource('pad_x')` will set the table to 'pad\_x' and reset the model's schema. [API reference](http://api.cakephp.org/class/model#method-ModelsetSource)
Try `var $persistModel = false;` in your controller or in the AppController. See: <http://www.pseudocoder.com/archives/2009/03/17/8-ways-to-speed-up-cakephp-apps/>
877,128
I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application's settings bundle. The Root.plist file contains a fragment like this... ``` <dict> <key>Type</key> <string>PSTitleValueSpecifier</string> <key>Title</key> <string>Version</string> <key>Key</key> <string>version_preference</string> <key>DefaultValue</key> <string>VersionValue</string> <key>Values</key> <array> <string>VersionValue</string> </array> <key>Titles</key> <array> <string>VersionValue</string> </array> </dict> ``` and I would like to replace the "VersionValue" string at build time. I have a script that can extract the version number from my repository, what I need is a way to process (pre-process) the Root.plist file, at build time, and replace the revision number without affecting the source file.
2009/05/18
[ "https://Stackoverflow.com/questions/877128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19331/" ]
The other answers do not work correctly for one reason: The run script build phase isn't executed until AFTER the Settings Bundle has been packaged. So, if your Info.plist version is 2.0.11 and you update it to 2.0.12, then build/archive your project, the Settings bundle will still say 2.0.11. If you open the Settings bundle Root.plist, you can see that the version number does not get updated until the END of the build process. You can build the project AGAIN to get the Settings bundle updated correctly, or you can add the script to a pre-build phase instead... * In XCode, Edit the Scheme for your project target * Click the disclosure arrow on the BUILD scheme * Then, click on the "Pre-actions" item * Click the plus sign and choose "New Run Script Action" * Set the shell value to /bin/sh * Set "Provide build settings from" to your project target * Add your script to the text area. The following script worked for me. You may need to modify the paths to match your project setup: versionString=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT\_DIR}/${INFOPLIST\_FILE}") /usr/libexec/PlistBuddy "$SRCROOT/Settings.bundle/Root.plist" -c "set PreferenceSpecifiers:0:DefaultValue $versionString" This will correctly run the script BEFORE the Settings bundle is packaged during the build/archive process. If you open the Settings bundle Root.plist and build/archive your project, you will now see the version number is updated at the beginning of the build process and your Settings bundle will display the correct version.
Above answers did not work for me hence I created my custom script. This dynamically updates the entry from Root.plist Use run script below. W ill work for sure verified in xcode 10.3. "var buildVersion" is the version to be displayed in title. And identifier name is "var version" below for title in settings.bundle Root.plist ``` cd "${BUILT_PRODUCTS_DIR}" #set version name to your title identifier's string from settings.bundle var version = "Version" #this will be the text displayed in title longVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_PATH}") shortVersion=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}) buildVersion="$shortVersion.$longVersion" path="${WRAPPER_NAME}/Settings.bundle/Root.plist" settingsCnt=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:" ${path} | grep "Dict"|wc -l` for (( idx=0; idx<$settingsCnt; idx++ )) do #echo "Welcome $idx times" val=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:${idx}:Key" ${path}` #echo $val #if ( "$val" == "Version" ) if [ $val == "Version" ] then #echo "the index of the entry whose 'Key' is 'version' is $idx." # now set it /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:${idx}:DefaultValue $buildVersion" $path # just to be sure that it worked ver=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:${idx}:DefaultValue" $path` #echo 'PreferenceSpecifiers:$idx:DefaultValue set to: ' $ver fi done ``` Example entry in Root.plist ``` <dict> <key>Type</key> <string>PSTitleValueSpecifier</string> <key>Title</key> <string>Version</string> <key>DefaultValue</key> <string>We Rock</string> <key>Key</key> <string>Version</string> </dict> ``` [![Working sample Root.plist entry](https://i.stack.imgur.com/fxiSx.png)](https://i.stack.imgur.com/fxiSx.png)
877,128
I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application's settings bundle. The Root.plist file contains a fragment like this... ``` <dict> <key>Type</key> <string>PSTitleValueSpecifier</string> <key>Title</key> <string>Version</string> <key>Key</key> <string>version_preference</string> <key>DefaultValue</key> <string>VersionValue</string> <key>Values</key> <array> <string>VersionValue</string> </array> <key>Titles</key> <array> <string>VersionValue</string> </array> </dict> ``` and I would like to replace the "VersionValue" string at build time. I have a script that can extract the version number from my repository, what I need is a way to process (pre-process) the Root.plist file, at build time, and replace the revision number without affecting the source file.
2009/05/18
[ "https://Stackoverflow.com/questions/877128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19331/" ]
Based on the example [here](http://web.me.com/maczealot/rantings_of_an_iron_geek/automatic_build_number_in_x.html"here"), here's the script I'm using to automatically update the settings bundle version number: ``` #! /usr/bin/env python import os from AppKit import NSMutableDictionary settings_file_path = 'Settings.bundle/Root.plist' # the relative path from the project folder to your settings bundle settings_key = 'version_preference' # the key of your settings version # these are used for testing only info_path = '/Users/mrwalker/developer/My_App/Info.plist' settings_path = '/Users/mrwalker/developer/My_App/Settings.bundle/Root.plist' # these environment variables are set in the XCode build phase if 'PRODUCT_SETTINGS_PATH' in os.environ.keys(): info_path = os.environ.get('PRODUCT_SETTINGS_PATH') if 'PROJECT_DIR' in os.environ.keys(): settings_path = os.path.join(os.environ.get('PROJECT_DIR'), settings_file_path) # reading info.plist file project_plist = NSMutableDictionary.dictionaryWithContentsOfFile_(info_path) project_bundle_version = project_plist['CFBundleVersion'] # print 'project_bundle_version: '+project_bundle_version # reading settings plist settings_plist = NSMutableDictionary.dictionaryWithContentsOfFile_(settings_path) for dictionary in settings_plist['PreferenceSpecifiers']: if 'Key' in dictionary and dictionary['Key'] == settings_key: dictionary['DefaultValue'] = project_bundle_version # print repr(settings_plist) settings_plist.writeToFile_atomically_(settings_path, True) ``` Here's the Root.plist I've got in Settings.bundle: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>PreferenceSpecifiers</key> <array> <dict> <key>Title</key> <string>About</string> <key>Type</key> <string>PSGroupSpecifier</string> </dict> <dict> <key>DefaultValue</key> <string>1.0.0.0</string> <key>Key</key> <string>version_preference</string> <key>Title</key> <string>Version</string> <key>Type</key> <string>PSTitleValueSpecifier</string> </dict> </array> <key>StringsTable</key> <string>Root</string> </dict> </plist> ```
My working Example based on @Ben Clayton answer and the comments of @Luis Ascorbe and @Vahid Amiri: > > Note: This approach modifies the *Settings.bundle/Root.plist* file in working copy of repository > > > 1. Add a settings bundle to your project root. Don't rename it 2. Open Settings.bundle/Root.plist as SourceCode Replace the contents with: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>PreferenceSpecifiers</key> <array> <dict> <key>DefaultValue</key> <string></string> <key>Key</key> <string>version_preference</string> <key>Title</key> <string>Version</string> <key>Type</key> <string>PSTitleValueSpecifier</string> </dict> </array> <key>StringsTable</key> <string>Root</string> </dict> </plist> ``` 3. Add the following script to the Build, Pre-actions section of the project (target) scheme ``` version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$PROJECT_DIR/$INFOPLIST_FILE") build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$PROJECT_DIR/$INFOPLIST_FILE") /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:0:DefaultValue $version ($build)" "${SRCROOT}/Settings.bundle/Root.plist" ``` 4. Build and Run the current scheme
877,128
I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application's settings bundle. The Root.plist file contains a fragment like this... ``` <dict> <key>Type</key> <string>PSTitleValueSpecifier</string> <key>Title</key> <string>Version</string> <key>Key</key> <string>version_preference</string> <key>DefaultValue</key> <string>VersionValue</string> <key>Values</key> <array> <string>VersionValue</string> </array> <key>Titles</key> <array> <string>VersionValue</string> </array> </dict> ``` and I would like to replace the "VersionValue" string at build time. I have a script that can extract the version number from my repository, what I need is a way to process (pre-process) the Root.plist file, at build time, and replace the revision number without affecting the source file.
2009/05/18
[ "https://Stackoverflow.com/questions/877128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19331/" ]
My lazy man's solution was to update the version number from my application code. You could have a default (or blank) value in the Root.plist and then, somewhere in your startup code: ``` NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; [[NSUserDefaults standardUserDefaults] setObject:version forKey:@"version_preference"]; ``` The only catch is that your app would have to be run at least once for the updated version to appear in the settings panel. You could take the idea further and update, for instance, a counter of how many times your app has been launched, or other interesting bits of information.
My working Example based on @Ben Clayton answer and the comments of @Luis Ascorbe and @Vahid Amiri: > > Note: This approach modifies the *Settings.bundle/Root.plist* file in working copy of repository > > > 1. Add a settings bundle to your project root. Don't rename it 2. Open Settings.bundle/Root.plist as SourceCode Replace the contents with: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>PreferenceSpecifiers</key> <array> <dict> <key>DefaultValue</key> <string></string> <key>Key</key> <string>version_preference</string> <key>Title</key> <string>Version</string> <key>Type</key> <string>PSTitleValueSpecifier</string> </dict> </array> <key>StringsTable</key> <string>Root</string> </dict> </plist> ``` 3. Add the following script to the Build, Pre-actions section of the project (target) scheme ``` version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$PROJECT_DIR/$INFOPLIST_FILE") build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$PROJECT_DIR/$INFOPLIST_FILE") /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:0:DefaultValue $version ($build)" "${SRCROOT}/Settings.bundle/Root.plist" ``` 4. Build and Run the current scheme
877,128
I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application's settings bundle. The Root.plist file contains a fragment like this... ``` <dict> <key>Type</key> <string>PSTitleValueSpecifier</string> <key>Title</key> <string>Version</string> <key>Key</key> <string>version_preference</string> <key>DefaultValue</key> <string>VersionValue</string> <key>Values</key> <array> <string>VersionValue</string> </array> <key>Titles</key> <array> <string>VersionValue</string> </array> </dict> ``` and I would like to replace the "VersionValue" string at build time. I have a script that can extract the version number from my repository, what I need is a way to process (pre-process) the Root.plist file, at build time, and replace the revision number without affecting the source file.
2009/05/18
[ "https://Stackoverflow.com/questions/877128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19331/" ]
There is another solution that can be much simpler than either of the previous answers. Apple bundles a command-line tool called **PlistBuddy** inside most of its installers, and has included it in Leopard at `/usr/libexec/PlistBuddy`. Since you want to replace `VersionValue`, assuming you have the version value extracted into `$newVersion`, you could use this command: ``` /usr/libexec/PlistBuddy -c "Set :VersionValue $newVersion" /path/to/Root.plist ``` No need to fiddle with sed or regular expressions, this approach is quite straightforward. See the [man page](http://developer.apple.com/documentation/Darwin/Reference/ManPages/man8/PlistBuddy.8.html) for detailed instructions. You can use PlistBuddy to add, remove, or modify any entry in a property list. For example, a friend of mine blogged about [incrementing build numbers in Xcode](http://davedelong.com/blog/2009/04/15/incrementing-build-numbers-xcode) using PlistBuddy. **Note:** If you supply just the path to the plist, PlistBuddy enters interactive mode, so you can issue multiple commands before deciding to save changes. I definitely recommend doing this before plopping it in your build script.
The other answers do not work correctly for one reason: The run script build phase isn't executed until AFTER the Settings Bundle has been packaged. So, if your Info.plist version is 2.0.11 and you update it to 2.0.12, then build/archive your project, the Settings bundle will still say 2.0.11. If you open the Settings bundle Root.plist, you can see that the version number does not get updated until the END of the build process. You can build the project AGAIN to get the Settings bundle updated correctly, or you can add the script to a pre-build phase instead... * In XCode, Edit the Scheme for your project target * Click the disclosure arrow on the BUILD scheme * Then, click on the "Pre-actions" item * Click the plus sign and choose "New Run Script Action" * Set the shell value to /bin/sh * Set "Provide build settings from" to your project target * Add your script to the text area. The following script worked for me. You may need to modify the paths to match your project setup: versionString=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT\_DIR}/${INFOPLIST\_FILE}") /usr/libexec/PlistBuddy "$SRCROOT/Settings.bundle/Root.plist" -c "set PreferenceSpecifiers:0:DefaultValue $versionString" This will correctly run the script BEFORE the Settings bundle is packaged during the build/archive process. If you open the Settings bundle Root.plist and build/archive your project, you will now see the version number is updated at the beginning of the build process and your Settings bundle will display the correct version.
877,128
I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application's settings bundle. The Root.plist file contains a fragment like this... ``` <dict> <key>Type</key> <string>PSTitleValueSpecifier</string> <key>Title</key> <string>Version</string> <key>Key</key> <string>version_preference</string> <key>DefaultValue</key> <string>VersionValue</string> <key>Values</key> <array> <string>VersionValue</string> </array> <key>Titles</key> <array> <string>VersionValue</string> </array> </dict> ``` and I would like to replace the "VersionValue" string at build time. I have a script that can extract the version number from my repository, what I need is a way to process (pre-process) the Root.plist file, at build time, and replace the revision number without affecting the source file.
2009/05/18
[ "https://Stackoverflow.com/questions/877128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19331/" ]
I believe you can do this using a way that's similar to what I describe in [this answer](https://stackoverflow.com/questions/372218/insert-subversion-revision-number-in-xcode#414792) (based on [this post](http://www.latenightcode.com/devblog/automated-build-numbering-in-xcode/)). First, you can make VersionValue a variable within Xcode by renaming it to ${VERSIONVALUE}. Create a file named versionvalue.xcconfig and add it to your project. Go to your application target and go to the Build settings for that target. I believe that you need to add VERSIONVALUE as a user-defined build setting. In the lower-right-corner of that window, change the Based On value to "versionvalue". Finally, go to your target and create a Run Script build phase. Inspect that Run Script phase and paste in your script within the Script text field. For example, my script to tag my BUILD\_NUMBER setting with the current Subversion build is as follows: ``` REV=`/usr/bin/svnversion -nc ${PROJECT_DIR} | /usr/bin/sed -e 's/^[^:]*://;s/[A-Za-z]//'` echo "BUILD_NUMBER = $REV" > ${PROJECT_DIR}/buildnumber.xcconfig ``` This should do the trick of replacing the variable when these values change within your project.
For me this was the easiest solution: Add new script build phase before Copy Bundle Resources step Shell: `/usr/bin/env python` Content: ``` #! /usr/bin/env python import os from AppKit import NSMutableDictionary # Key to replace settings_key = 'version_preference' # the key of your settings version # File path settings_path = os.environ.get('SRCROOT') + "/TheBeautifulNameOfYourOwnApp/Settings.bundle/Root.plist" # Composing version string version_string = os.environ.get('MARKETING_VERSION') + " (" + os.environ.get('CURRENT_PROJECT_VERSION') + ")" # Reading settings plist settings_plist = NSMutableDictionary.dictionaryWithContentsOfFile_(settings_path) for dictionary in settings_plist['PreferenceSpecifiers']: if 'Key' in dictionary and dictionary['Key'] == settings_key: dictionary['DefaultValue'] = version_string # Save new settings settings_plist.writeToFile_atomically_(settings_path, True) ```
877,128
I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application's settings bundle. The Root.plist file contains a fragment like this... ``` <dict> <key>Type</key> <string>PSTitleValueSpecifier</string> <key>Title</key> <string>Version</string> <key>Key</key> <string>version_preference</string> <key>DefaultValue</key> <string>VersionValue</string> <key>Values</key> <array> <string>VersionValue</string> </array> <key>Titles</key> <array> <string>VersionValue</string> </array> </dict> ``` and I would like to replace the "VersionValue" string at build time. I have a script that can extract the version number from my repository, what I need is a way to process (pre-process) the Root.plist file, at build time, and replace the revision number without affecting the source file.
2009/05/18
[ "https://Stackoverflow.com/questions/877128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19331/" ]
With Xcode 11.4, you can use the following steps to display the app version in your application's settings bundle. --- Set `$(MARKETING_VERSION)` and `$(CURRENT_PROJECT_VERSION)` variables --------------------------------------------------------------------- Note: if `$(MARKETING_VERSION)` and `$(CURRENT_PROJECT_VERSION)` variables appear for `Bundle version string (short)` and `Bundle version` keys in **Info.plist**, you can skip the following steps and jump to the next section. 1. Open the Xcode project. 2. Open **Project Navigator** (`cmd``1`), select your project to reveal your project's settings then select the app target. 3. Select the **General** tab. 4. In the **Identity** section, change the **Version** field content to some new value (e.g. `0.1.0`) and change the **Build** field content to some new value (e.g. `12`). These 2 changes will create `$(MARKETING_VERSION)` and `$(CURRENT_PROJECT_VERSION)` variables in **Info.plist** file. --- Create and configure Settings Bundle ------------------------------------ 1. In the **Project Navigator**, select your project. 2. Select **File** > **New** > **File…** (`cmd``N`). 3. Select the **iOS** tab. 4. Select **Settings Bundle** in the **Resource** section, then click **Next** and **Create**. 5. Select **Root.plist** and open it as source code. Replace its content with the code below: ```xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>PreferenceSpecifiers</key> <array> <dict> <key>DefaultValue</key> <string></string> <key>Key</key> <string>version_preference</string> <key>Title</key> <string>Version</string> <key>Type</key> <string>PSTitleValueSpecifier</string> </dict> </array> <key>StringsTable</key> <string>Root</string> </dict> </plist> ``` --- Add a Run Script ---------------- 1. In the **Project Navigator**, select your project. 2. Select the app target. 3. Select the **Build Phases** tab. 4. Click **+** > **New Run Script Phase**. 5. Drag and drop the new phase somewhere above **Copy Bundle Resources** section. In this way, the script will be executed before compiling the application. 6. Open the newly added **Run Script** phase and add the following script: ```sh version="$MARKETING_VERSION" build="$CURRENT_PROJECT_VERSION" /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:0:DefaultValue $version ($build)" "${SRCROOT}/Settings.bundle/Root.plist" ``` --- Launch app ---------- 1. Run the product (`cmd``R`) on device or simulator. 2. On the device or simulator, once the app is launched, open **Settings** app and select your app in the list of third-party apps. The app's version should be displayed as shown below: ![](https://i.stack.imgur.com/osnPr.png) --- Sources ------- * [How To Manage Plist Files With PlistBuddy](https://marcosantadev.com/manage-plist-files-plistbuddy/)
I managed to do what I wanted by using the pListcompiler (<http://sourceforge.net/projects/plistcompiler>) open source porject. 1. Using this compiler you can write the property file in a .plc file using the following format: ``` plist { dictionary { key "StringsTable" value string "Root" key "PreferenceSpecifiers" value array [ dictionary { key "Type" value string "PSGroupSpecifier" key "Title" value string "AboutSection" } dictionary { key "Type" value string "PSTitleValueSpecifier" key "Title" value string "Version" key "Key" value string "version" key "DefaultValue" value string "VersionValue" key "Values" value array [ string "VersionValue" ] key "Titles" value array [ string "r" kRevisionNumber ] } ] } } ``` 2. I had a custom run script build phase that was extracting my repository revision to .h file as described by brad-larson [here](https://stackoverflow.com/questions/877128/how-can-i-display-the-application-version-revision-in-my-applications-settings-b/877589#877589). 3. The plc file can contain preprocessor directives, like #define, #message, #if, #elif, #include, #warning, #ifdef, #else, #pragma, #error, #ifndef, #endif, xcode environment variables. So I was able to reference the variable kRevisionNumber by adding the following directive ``` #include "Revision.h" ``` 4. I also added a custom script build phase to my xcode target to run the plcompiler every time the project is beeing build ``` /usr/local/plistcompiler0.6/plcompile -dest Settings.bundle -o Root.plist Settings.plc ``` And that was it!
877,128
I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application's settings bundle. The Root.plist file contains a fragment like this... ``` <dict> <key>Type</key> <string>PSTitleValueSpecifier</string> <key>Title</key> <string>Version</string> <key>Key</key> <string>version_preference</string> <key>DefaultValue</key> <string>VersionValue</string> <key>Values</key> <array> <string>VersionValue</string> </array> <key>Titles</key> <array> <string>VersionValue</string> </array> </dict> ``` and I would like to replace the "VersionValue" string at build time. I have a script that can extract the version number from my repository, what I need is a way to process (pre-process) the Root.plist file, at build time, and replace the revision number without affecting the source file.
2009/05/18
[ "https://Stackoverflow.com/questions/877128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19331/" ]
Using Ben Clayton's plist <https://stackoverflow.com/a/12842530/338986> Add `Run script` with following snippet after `Copy Bundle Resources`. ``` version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$PROJECT_DIR/$INFOPLIST_FILE") build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$PROJECT_DIR/$INFOPLIST_FILE") /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $version ($build)" "$CODESIGNING_FOLDER_PATH/Settings.bundle/Root.plist" ``` Appending `CFBundleVersion` in addition of `CFBundleShortVersionString`. It emit version like this: ![](https://i.stack.imgur.com/mfZLl.png) By writing to `$CODESIGNING_FOLDER_PATH/Settings.bundle/Root.plist` instead of the one in `$SRCROOT` have some benefits. 1. It dosen't modify files in working copy of repository. 2. You don't need to case path to `Settings.bundle` in `$SRCROOT`. The path may vary. Testing on Xcode 7.3.1
My working Example based on @Ben Clayton answer and the comments of @Luis Ascorbe and @Vahid Amiri: > > Note: This approach modifies the *Settings.bundle/Root.plist* file in working copy of repository > > > 1. Add a settings bundle to your project root. Don't rename it 2. Open Settings.bundle/Root.plist as SourceCode Replace the contents with: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>PreferenceSpecifiers</key> <array> <dict> <key>DefaultValue</key> <string></string> <key>Key</key> <string>version_preference</string> <key>Title</key> <string>Version</string> <key>Type</key> <string>PSTitleValueSpecifier</string> </dict> </array> <key>StringsTable</key> <string>Root</string> </dict> </plist> ``` 3. Add the following script to the Build, Pre-actions section of the project (target) scheme ``` version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$PROJECT_DIR/$INFOPLIST_FILE") build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$PROJECT_DIR/$INFOPLIST_FILE") /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:0:DefaultValue $version ($build)" "${SRCROOT}/Settings.bundle/Root.plist" ``` 4. Build and Run the current scheme
877,128
I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application's settings bundle. The Root.plist file contains a fragment like this... ``` <dict> <key>Type</key> <string>PSTitleValueSpecifier</string> <key>Title</key> <string>Version</string> <key>Key</key> <string>version_preference</string> <key>DefaultValue</key> <string>VersionValue</string> <key>Values</key> <array> <string>VersionValue</string> </array> <key>Titles</key> <array> <string>VersionValue</string> </array> </dict> ``` and I would like to replace the "VersionValue" string at build time. I have a script that can extract the version number from my repository, what I need is a way to process (pre-process) the Root.plist file, at build time, and replace the revision number without affecting the source file.
2009/05/18
[ "https://Stackoverflow.com/questions/877128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19331/" ]
These are the variables I had to use for a swift project with Xcode 12.2 ``` version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$PROJECT_DIR/$INFOPLIST_FILE") build="$CURRENT_PROJECT_VERSION" /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:0:FooterText Version $version" "$CODESIGNING_FOLDER_PATH/Settings.bundle/ServerURLSettings.plist" /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:0:FooterText Version $version($build)" "$CODESIGNING_FOLDER_PATH/Settings.bundle/DeveloperSettings.plist" ```
For me this was the easiest solution: Add new script build phase before Copy Bundle Resources step Shell: `/usr/bin/env python` Content: ``` #! /usr/bin/env python import os from AppKit import NSMutableDictionary # Key to replace settings_key = 'version_preference' # the key of your settings version # File path settings_path = os.environ.get('SRCROOT') + "/TheBeautifulNameOfYourOwnApp/Settings.bundle/Root.plist" # Composing version string version_string = os.environ.get('MARKETING_VERSION') + " (" + os.environ.get('CURRENT_PROJECT_VERSION') + ")" # Reading settings plist settings_plist = NSMutableDictionary.dictionaryWithContentsOfFile_(settings_path) for dictionary in settings_plist['PreferenceSpecifiers']: if 'Key' in dictionary and dictionary['Key'] == settings_key: dictionary['DefaultValue'] = version_string # Save new settings settings_plist.writeToFile_atomically_(settings_path, True) ```
877,128
I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application's settings bundle. The Root.plist file contains a fragment like this... ``` <dict> <key>Type</key> <string>PSTitleValueSpecifier</string> <key>Title</key> <string>Version</string> <key>Key</key> <string>version_preference</string> <key>DefaultValue</key> <string>VersionValue</string> <key>Values</key> <array> <string>VersionValue</string> </array> <key>Titles</key> <array> <string>VersionValue</string> </array> </dict> ``` and I would like to replace the "VersionValue" string at build time. I have a script that can extract the version number from my repository, what I need is a way to process (pre-process) the Root.plist file, at build time, and replace the revision number without affecting the source file.
2009/05/18
[ "https://Stackoverflow.com/questions/877128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19331/" ]
I managed to do what I wanted by using the pListcompiler (<http://sourceforge.net/projects/plistcompiler>) open source porject. 1. Using this compiler you can write the property file in a .plc file using the following format: ``` plist { dictionary { key "StringsTable" value string "Root" key "PreferenceSpecifiers" value array [ dictionary { key "Type" value string "PSGroupSpecifier" key "Title" value string "AboutSection" } dictionary { key "Type" value string "PSTitleValueSpecifier" key "Title" value string "Version" key "Key" value string "version" key "DefaultValue" value string "VersionValue" key "Values" value array [ string "VersionValue" ] key "Titles" value array [ string "r" kRevisionNumber ] } ] } } ``` 2. I had a custom run script build phase that was extracting my repository revision to .h file as described by brad-larson [here](https://stackoverflow.com/questions/877128/how-can-i-display-the-application-version-revision-in-my-applications-settings-b/877589#877589). 3. The plc file can contain preprocessor directives, like #define, #message, #if, #elif, #include, #warning, #ifdef, #else, #pragma, #error, #ifndef, #endif, xcode environment variables. So I was able to reference the variable kRevisionNumber by adding the following directive ``` #include "Revision.h" ``` 4. I also added a custom script build phase to my xcode target to run the plcompiler every time the project is beeing build ``` /usr/local/plistcompiler0.6/plcompile -dest Settings.bundle -o Root.plist Settings.plc ``` And that was it!
These are the variables I had to use for a swift project with Xcode 12.2 ``` version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$PROJECT_DIR/$INFOPLIST_FILE") build="$CURRENT_PROJECT_VERSION" /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:0:FooterText Version $version" "$CODESIGNING_FOLDER_PATH/Settings.bundle/ServerURLSettings.plist" /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:0:FooterText Version $version($build)" "$CODESIGNING_FOLDER_PATH/Settings.bundle/DeveloperSettings.plist" ```
877,128
I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application's settings bundle. The Root.plist file contains a fragment like this... ``` <dict> <key>Type</key> <string>PSTitleValueSpecifier</string> <key>Title</key> <string>Version</string> <key>Key</key> <string>version_preference</string> <key>DefaultValue</key> <string>VersionValue</string> <key>Values</key> <array> <string>VersionValue</string> </array> <key>Titles</key> <array> <string>VersionValue</string> </array> </dict> ``` and I would like to replace the "VersionValue" string at build time. I have a script that can extract the version number from my repository, what I need is a way to process (pre-process) the Root.plist file, at build time, and replace the revision number without affecting the source file.
2009/05/18
[ "https://Stackoverflow.com/questions/877128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19331/" ]
Based on the example [here](http://web.me.com/maczealot/rantings_of_an_iron_geek/automatic_build_number_in_x.html"here"), here's the script I'm using to automatically update the settings bundle version number: ``` #! /usr/bin/env python import os from AppKit import NSMutableDictionary settings_file_path = 'Settings.bundle/Root.plist' # the relative path from the project folder to your settings bundle settings_key = 'version_preference' # the key of your settings version # these are used for testing only info_path = '/Users/mrwalker/developer/My_App/Info.plist' settings_path = '/Users/mrwalker/developer/My_App/Settings.bundle/Root.plist' # these environment variables are set in the XCode build phase if 'PRODUCT_SETTINGS_PATH' in os.environ.keys(): info_path = os.environ.get('PRODUCT_SETTINGS_PATH') if 'PROJECT_DIR' in os.environ.keys(): settings_path = os.path.join(os.environ.get('PROJECT_DIR'), settings_file_path) # reading info.plist file project_plist = NSMutableDictionary.dictionaryWithContentsOfFile_(info_path) project_bundle_version = project_plist['CFBundleVersion'] # print 'project_bundle_version: '+project_bundle_version # reading settings plist settings_plist = NSMutableDictionary.dictionaryWithContentsOfFile_(settings_path) for dictionary in settings_plist['PreferenceSpecifiers']: if 'Key' in dictionary and dictionary['Key'] == settings_key: dictionary['DefaultValue'] = project_bundle_version # print repr(settings_plist) settings_plist.writeToFile_atomically_(settings_path, True) ``` Here's the Root.plist I've got in Settings.bundle: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>PreferenceSpecifiers</key> <array> <dict> <key>Title</key> <string>About</string> <key>Type</key> <string>PSGroupSpecifier</string> </dict> <dict> <key>DefaultValue</key> <string>1.0.0.0</string> <key>Key</key> <string>version_preference</string> <key>Title</key> <string>Version</string> <key>Type</key> <string>PSTitleValueSpecifier</string> </dict> </array> <key>StringsTable</key> <string>Root</string> </dict> </plist> ```
The other answers do not work correctly for one reason: The run script build phase isn't executed until AFTER the Settings Bundle has been packaged. So, if your Info.plist version is 2.0.11 and you update it to 2.0.12, then build/archive your project, the Settings bundle will still say 2.0.11. If you open the Settings bundle Root.plist, you can see that the version number does not get updated until the END of the build process. You can build the project AGAIN to get the Settings bundle updated correctly, or you can add the script to a pre-build phase instead... * In XCode, Edit the Scheme for your project target * Click the disclosure arrow on the BUILD scheme * Then, click on the "Pre-actions" item * Click the plus sign and choose "New Run Script Action" * Set the shell value to /bin/sh * Set "Provide build settings from" to your project target * Add your script to the text area. The following script worked for me. You may need to modify the paths to match your project setup: versionString=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT\_DIR}/${INFOPLIST\_FILE}") /usr/libexec/PlistBuddy "$SRCROOT/Settings.bundle/Root.plist" -c "set PreferenceSpecifiers:0:DefaultValue $versionString" This will correctly run the script BEFORE the Settings bundle is packaged during the build/archive process. If you open the Settings bundle Root.plist and build/archive your project, you will now see the version number is updated at the beginning of the build process and your Settings bundle will display the correct version.
1,377,270
**Can a KPID (as `select kpid from master..sysprocesses`) be assumed to be globally and always unique?** (I've found that for my small sample set `KPID(n+1) ~= KPID(n) + 65536` (2^16) but I want to know if I can assume, previous db connections kpid is unique, even if it's previous loginame and spid match a new `loginame` and `spid`) Cheers. BLT. (*Already answered*) \*B) Loginame: *how can I get the loginame from a current spid*? *`loginame` isn't a column in `sysprocesses`, and I can't find any table other than `sysobjects` that has a column with `loginame`, and I can't programatically get the `loginame` out of sp\_who. Maybe the sql used to generate `sp_who` would help..*
2009/09/04
[ "https://Stackoverflow.com/questions/1377270", "https://Stackoverflow.com", "https://Stackoverflow.com/users/124019/" ]
Based on [these docs](http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc36556_1500/html/histserv/X23555.htm) KPID is unique within the machine. It may be unique within a cluster but this seems unlikely since it refers to an identifier within the underlying operating system. Since it is only a 32bit value there is no way it can be globally unique. Based on [this glossary](http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc36556.1502/html/histserv/X14352.htm) > > Kernel Process ID Version: 11.0 and later > > An Adaptive Server process identifier that remains unique over long periods of time. > > > The 'uniqueness' of the value has some sort of timeframe but it is not guaranteed.
Answer to part B) ``` master..syslogins.suid <-> master..sysprocesses.suid ``` As in, you can get the name of a connection a la sp\_who by going ``` select p.spid, l.name, p.loggedindatetime from master..syslogins l, master..sysprocesses p where l.suid = p.suid ``` By answering my own questions I'm helping to grow stackoverflow ^\_^
1,377,270
**Can a KPID (as `select kpid from master..sysprocesses`) be assumed to be globally and always unique?** (I've found that for my small sample set `KPID(n+1) ~= KPID(n) + 65536` (2^16) but I want to know if I can assume, previous db connections kpid is unique, even if it's previous loginame and spid match a new `loginame` and `spid`) Cheers. BLT. (*Already answered*) \*B) Loginame: *how can I get the loginame from a current spid*? *`loginame` isn't a column in `sysprocesses`, and I can't find any table other than `sysobjects` that has a column with `loginame`, and I can't programatically get the `loginame` out of sp\_who. Maybe the sql used to generate `sp_who` would help..*
2009/09/04
[ "https://Stackoverflow.com/questions/1377270", "https://Stackoverflow.com", "https://Stackoverflow.com/users/124019/" ]
Based on [these docs](http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc36556_1500/html/histserv/X23555.htm) KPID is unique within the machine. It may be unique within a cluster but this seems unlikely since it refers to an identifier within the underlying operating system. Since it is only a 32bit value there is no way it can be globally unique. Based on [this glossary](http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc36556.1502/html/histserv/X14352.htm) > > Kernel Process ID Version: 11.0 and later > > An Adaptive Server process identifier that remains unique over long periods of time. > > > The 'uniqueness' of the value has some sort of timeframe but it is not guaranteed.
You can translate a suid to a login name by using the `SUSER_NAME()` function e.g. ``` SELECT spid, SUSER_NAME(suid) AS login_name FROM master..sysprocesses ORDER BY login_name ASC ```
1,256,182
I am using this: ``` SELECT * FROM sys.dm_exec_query_stats s CROSS APPLY sys.dm_exec_sql_text( s.sql_handle ) t ORDER BY s.max_elapsed_time DESC ``` to get the longest running queries on the server level. How do I get the longest running queries per database? I would like to focus only on one database at a time.
2009/08/10
[ "https://Stackoverflow.com/questions/1256182", "https://Stackoverflow.com", "https://Stackoverflow.com/users/94967/" ]
The BOL entry for [`sys.dm_exec_query_stats`](http://msdn.microsoft.com/en-us/library/ms189741(SQL.90).aspx) mentions [`sys.dm_exec_query_plan`](http://msdn.microsoft.com/en-us/library/ms189747(SQL.90).aspx) ``` SELECT * FROM sys.dm_exec_query_stats s CROSS APPLY sys.dm_exec_sql_text( s.sql_handle ) t CROSS APPLY sys.dm_exec_query_plan(s.plan_handle) foo WHERE foo.dbid = DB_ID('My_DB') ORDER BY s.max_elapsed_time DESC ``` Edit: I've not tried it. I generally worry about server load...
``` SELECT * FROM database1.dbo.table JOIN database2.dbo.table ``` In which database did the query above run? What if the current context at the moment of execution was database3? What if it was executed once in database4 and once in database5? The idea is that execution plans are not tied to a database.
1,256,182
I am using this: ``` SELECT * FROM sys.dm_exec_query_stats s CROSS APPLY sys.dm_exec_sql_text( s.sql_handle ) t ORDER BY s.max_elapsed_time DESC ``` to get the longest running queries on the server level. How do I get the longest running queries per database? I would like to focus only on one database at a time.
2009/08/10
[ "https://Stackoverflow.com/questions/1256182", "https://Stackoverflow.com", "https://Stackoverflow.com/users/94967/" ]
The BOL entry for [`sys.dm_exec_query_stats`](http://msdn.microsoft.com/en-us/library/ms189741(SQL.90).aspx) mentions [`sys.dm_exec_query_plan`](http://msdn.microsoft.com/en-us/library/ms189747(SQL.90).aspx) ``` SELECT * FROM sys.dm_exec_query_stats s CROSS APPLY sys.dm_exec_sql_text( s.sql_handle ) t CROSS APPLY sys.dm_exec_query_plan(s.plan_handle) foo WHERE foo.dbid = DB_ID('My_DB') ORDER BY s.max_elapsed_time DESC ``` Edit: I've not tried it. I generally worry about server load...
It sounds like you are trying to tune the databases. Your longest running queries may not be your costliest ones, or the ones that you will benefit from the most. You should read up on the SQL Server Profiler to identify the queries that use the most resources and work on them.
337,789
I have at my SQL Server 2000 Database a column with type **Image**. How can I map it into NHibernate?
2008/12/03
[ "https://Stackoverflow.com/questions/337789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21668/" ]
We used BinaryBlob on the mapping config file, and byte[] on the property.
Below is the sample code that i have used to map an image field. Where BlogImage was a column of Image Datatype mapped to byte type property BlogImage. length="2147483647" was used to ensure copy of full image in to database as nhibernate some times limit the max size of data that is going to be inserted. ``` <?xml version="1.0" encoding="utf-8" standalone="yes"?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"> <class name="EAS.MINDSPACE.Infrastructure.Business.Entities.BlogMaster,EAS.MINDSPACE.Infrastructure.Business.Entities" lazy="false" table="BlogMaster" schema="dbo" > <id name="BlogId" column="BlogId"> <generator class="native" /> </id> <property name="BlogData" column="BlogData" /> <property name="BlogImage" column="BlogImage" length="2147483647" /> <property name="UserId" column="UserId" /> <property name="CreatedByName" column="CreatedBy" /> <property name="CreatedOn" column="CreatedOn" /> <property name="ReplyCount" column="ReplyCount" /> </class> </hibernate-mapping> ```
337,789
I have at my SQL Server 2000 Database a column with type **Image**. How can I map it into NHibernate?
2008/12/03
[ "https://Stackoverflow.com/questions/337789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21668/" ]
We used BinaryBlob on the mapping config file, and byte[] on the property.
NHibernate 3.x does all the magic it self. Sql: ``` Create table tblCompany (..., Logo image); ``` NHibernate-Mapping (important to set length!!!): ``` <class name="Company" table="tblCompany"> ... <property name="_logo" column="Logo" not-null="false" length="2147483647" access="field" /> ... </class> ``` C#-Class: ``` public class Company { ... private Image _logo; ... } ```
337,789
I have at my SQL Server 2000 Database a column with type **Image**. How can I map it into NHibernate?
2008/12/03
[ "https://Stackoverflow.com/questions/337789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21668/" ]
Below is the sample code that i have used to map an image field. Where BlogImage was a column of Image Datatype mapped to byte type property BlogImage. length="2147483647" was used to ensure copy of full image in to database as nhibernate some times limit the max size of data that is going to be inserted. ``` <?xml version="1.0" encoding="utf-8" standalone="yes"?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"> <class name="EAS.MINDSPACE.Infrastructure.Business.Entities.BlogMaster,EAS.MINDSPACE.Infrastructure.Business.Entities" lazy="false" table="BlogMaster" schema="dbo" > <id name="BlogId" column="BlogId"> <generator class="native" /> </id> <property name="BlogData" column="BlogData" /> <property name="BlogImage" column="BlogImage" length="2147483647" /> <property name="UserId" column="UserId" /> <property name="CreatedByName" column="CreatedBy" /> <property name="CreatedOn" column="CreatedOn" /> <property name="ReplyCount" column="ReplyCount" /> </class> </hibernate-mapping> ```
NHibernate 3.x does all the magic it self. Sql: ``` Create table tblCompany (..., Logo image); ``` NHibernate-Mapping (important to set length!!!): ``` <class name="Company" table="tblCompany"> ... <property name="_logo" column="Logo" not-null="false" length="2147483647" access="field" /> ... </class> ``` C#-Class: ``` public class Company { ... private Image _logo; ... } ```
615,100
I`m currently studying C++ and want to learn another language. For work I use C# + ASP (just started learning it, actually), but I want something "less Microsoft" and powerful. I have heard Python is a popular and powerful language, not so complicated as C++. But many people mentioned it was hard for them to get back to C++/Java from Python because they started thinking in it, get used to absence of memory management, etc. What do you recommend?
2009/03/05
[ "https://Stackoverflow.com/questions/615100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
Many would argue that you would benefit from learning Python *before* C++. * The syntax hurdles are much, much lower; * Debugging is much more friendly * There are a plethora of libraries---batteries included, you know. It's easy to experiment with web scraping, XML, etc. in Python. Again, the barriers to entry in C++ are much higher. It's still good to learn C/C++, because of its close connection to the machine. But a new programmer can learn an awful lot from exploring in Python.
Try LISP instead (or afterwards, it's your call). You are at least partially right, though. using Python for a while makes you not want to go back to a statically typed and compiled language. It's just sooo much more comfortable not to have to please the compiler like ALL THE TIME ;). And yet another aspect is the readability of python code, which is awesome.
615,100
I`m currently studying C++ and want to learn another language. For work I use C# + ASP (just started learning it, actually), but I want something "less Microsoft" and powerful. I have heard Python is a popular and powerful language, not so complicated as C++. But many people mentioned it was hard for them to get back to C++/Java from Python because they started thinking in it, get used to absence of memory management, etc. What do you recommend?
2009/03/05
[ "https://Stackoverflow.com/questions/615100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
Flex your brain and improve your skill set. Give a functional language a whirl.
I learned, in order: * BASIC * Pascal * Ada * (A little bit of Haskell) * Java * Python * C++ * C# I don't feel Python inhibited my ability to learn or use C++. I am glad though that I learned pointers in Pascal before encountering reference types in Java, Python and C#, because I feel it gave me a good basis to understand the idea of the differences between "value types" and "reference types". I think **for me** the most important of those languages are Python, Haskell and C++. All of them complement each other, and although there are times I'm working in one and wish I had a feature from another, on the whole I think I benefit greatly from a deeper understanding of things like type systems, object orientation and metaprogramming by seeing the different ways these languages approach these things.
615,100
I`m currently studying C++ and want to learn another language. For work I use C# + ASP (just started learning it, actually), but I want something "less Microsoft" and powerful. I have heard Python is a popular and powerful language, not so complicated as C++. But many people mentioned it was hard for them to get back to C++/Java from Python because they started thinking in it, get used to absence of memory management, etc. What do you recommend?
2009/03/05
[ "https://Stackoverflow.com/questions/615100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
Python is complementary to C++ and easy to integrate with C++. (As evidence of this claim, the C++ gurus from Boost use Python.) And as you said, Python gives you a way to get a perspective outside the Microsoft orbit. But even there, if you need to integrate Python with MS tools, there's IronPython.
Try LISP instead (or afterwards, it's your call). You are at least partially right, though. using Python for a while makes you not want to go back to a statically typed and compiled language. It's just sooo much more comfortable not to have to please the compiler like ALL THE TIME ;). And yet another aspect is the readability of python code, which is awesome.
615,100
I`m currently studying C++ and want to learn another language. For work I use C# + ASP (just started learning it, actually), but I want something "less Microsoft" and powerful. I have heard Python is a popular and powerful language, not so complicated as C++. But many people mentioned it was hard for them to get back to C++/Java from Python because they started thinking in it, get used to absence of memory management, etc. What do you recommend?
2009/03/05
[ "https://Stackoverflow.com/questions/615100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
Python is complementary to C++ and easy to integrate with C++. (As evidence of this claim, the C++ gurus from Boost use Python.) And as you said, Python gives you a way to get a perspective outside the Microsoft orbit. But even there, if you need to integrate Python with MS tools, there's IronPython.
Learning more languages can only make you a better developer, regardless of their approach. Besides, your experience with C++ (or, at least C) will come in handy for writing high-performance parts of your applications using Python's C API, which lets "raw" C and C++ code intermingle nicely with the pure Python stuff. I still write code in Objective-C (1.0... before memory management) and Python on a daily basis. The variety is actually fun, rather than confusing; keeps things from being boring.
615,100
I`m currently studying C++ and want to learn another language. For work I use C# + ASP (just started learning it, actually), but I want something "less Microsoft" and powerful. I have heard Python is a popular and powerful language, not so complicated as C++. But many people mentioned it was hard for them to get back to C++/Java from Python because they started thinking in it, get used to absence of memory management, etc. What do you recommend?
2009/03/05
[ "https://Stackoverflow.com/questions/615100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
Many would argue that you would benefit from learning Python *before* C++. * The syntax hurdles are much, much lower; * Debugging is much more friendly * There are a plethora of libraries---batteries included, you know. It's easy to experiment with web scraping, XML, etc. in Python. Again, the barriers to entry in C++ are much higher. It's still good to learn C/C++, because of its close connection to the machine. But a new programmer can learn an awful lot from exploring in Python.
I think it is always good to know several programming languages. I've learned c++ at school and I've used it a lot in the past years because it is really a standard in the industry. I've learned python by my own and I am using it to make a lot of nice tools that would be too long to write in c++. Python has just a very positive influence on my c++ skills. It gives another way to think.
615,100
I`m currently studying C++ and want to learn another language. For work I use C# + ASP (just started learning it, actually), but I want something "less Microsoft" and powerful. I have heard Python is a popular and powerful language, not so complicated as C++. But many people mentioned it was hard for them to get back to C++/Java from Python because they started thinking in it, get used to absence of memory management, etc. What do you recommend?
2009/03/05
[ "https://Stackoverflow.com/questions/615100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
There's no right or wrong answer, really. But I think you'll benefit more from learning Python. Given the similarities between C# and C++, you'll learn a different way of thinking from Python. The more ways you learn to think about a problem, the better it makes you as a programmer, regardless of the language.
I don't think that "Python makes you lazy" (nice title, anyway!). On the contrary, in programming as in life, knowing more than one language is important; I think you'll find python amusing and sufficiently different from C++ or C# so that the languages will not get mixed in your head...
615,100
I`m currently studying C++ and want to learn another language. For work I use C# + ASP (just started learning it, actually), but I want something "less Microsoft" and powerful. I have heard Python is a popular and powerful language, not so complicated as C++. But many people mentioned it was hard for them to get back to C++/Java from Python because they started thinking in it, get used to absence of memory management, etc. What do you recommend?
2009/03/05
[ "https://Stackoverflow.com/questions/615100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
I don't think that "Python makes you lazy" (nice title, anyway!). On the contrary, in programming as in life, knowing more than one language is important; I think you'll find python amusing and sufficiently different from C++ or C# so that the languages will not get mixed in your head...
From a utility perspective, it is good to learn one of the more dynamic languages like Python (or Ruby or Perl) too. Not only do they stretch your mind, but they are superior for certain kinds of tasks. If you want to manipulate text, for example, C++ is a lot harder to use than Python. It gives you another arrow in your quiver to use when appropriate.
615,100
I`m currently studying C++ and want to learn another language. For work I use C# + ASP (just started learning it, actually), but I want something "less Microsoft" and powerful. I have heard Python is a popular and powerful language, not so complicated as C++. But many people mentioned it was hard for them to get back to C++/Java from Python because they started thinking in it, get used to absence of memory management, etc. What do you recommend?
2009/03/05
[ "https://Stackoverflow.com/questions/615100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
It is up to what exactly is the kind of applications you want to program, for example for Websites that need access to databases I would go for Ruby( and Ruby on Rails framework ) , for financial applications or applications that need a lot of parallel processing I would go for a funcional programming language like Haskell, oCaml or the new F#, these last 3 wil make you a better programer even if you don't programm a lot in them , by the way c# has been lately in the latest versions adding more and more funcional programming features. I would learn Python for a security and exploits kinds of applications.
I learned, in order: * BASIC * Pascal * Ada * (A little bit of Haskell) * Java * Python * C++ * C# I don't feel Python inhibited my ability to learn or use C++. I am glad though that I learned pointers in Pascal before encountering reference types in Java, Python and C#, because I feel it gave me a good basis to understand the idea of the differences between "value types" and "reference types". I think **for me** the most important of those languages are Python, Haskell and C++. All of them complement each other, and although there are times I'm working in one and wish I had a feature from another, on the whole I think I benefit greatly from a deeper understanding of things like type systems, object orientation and metaprogramming by seeing the different ways these languages approach these things.
615,100
I`m currently studying C++ and want to learn another language. For work I use C# + ASP (just started learning it, actually), but I want something "less Microsoft" and powerful. I have heard Python is a popular and powerful language, not so complicated as C++. But many people mentioned it was hard for them to get back to C++/Java from Python because they started thinking in it, get used to absence of memory management, etc. What do you recommend?
2009/03/05
[ "https://Stackoverflow.com/questions/615100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
There's no right or wrong answer, really. But I think you'll benefit more from learning Python. Given the similarities between C# and C++, you'll learn a different way of thinking from Python. The more ways you learn to think about a problem, the better it makes you as a programmer, regardless of the language.
From a utility perspective, it is good to learn one of the more dynamic languages like Python (or Ruby or Perl) too. Not only do they stretch your mind, but they are superior for certain kinds of tasks. If you want to manipulate text, for example, C++ is a lot harder to use than Python. It gives you another arrow in your quiver to use when appropriate.
615,100
I`m currently studying C++ and want to learn another language. For work I use C# + ASP (just started learning it, actually), but I want something "less Microsoft" and powerful. I have heard Python is a popular and powerful language, not so complicated as C++. But many people mentioned it was hard for them to get back to C++/Java from Python because they started thinking in it, get used to absence of memory management, etc. What do you recommend?
2009/03/05
[ "https://Stackoverflow.com/questions/615100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
Learning more languages can only make you a better developer, regardless of their approach. Besides, your experience with C++ (or, at least C) will come in handy for writing high-performance parts of your applications using Python's C API, which lets "raw" C and C++ code intermingle nicely with the pure Python stuff. I still write code in Objective-C (1.0... before memory management) and Python on a daily basis. The variety is actually fun, rather than confusing; keeps things from being boring.
It is true. After learning python, everything else will seem like too much effort for the same amount of real work being done. You'll get used to the clean, small syntax and the freedom of GC. You will enjoy working in list comps, generators, etc. You'll start to think in python and C++ and Java will be like building a ship in a bottle one twiggy little stick at a time. But since it's *that* much easier, doesn't it tempt you to try it all the more?
1,932,604
I am using [Vim](http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and I have set the path (`set path+= c:/work/etc/etc`) to my project directory (for C#), but still using command 'gf' give me error: > > E:447 Can't find file. > > > Is there anything I am doing wrong over here?
2009/12/19
[ "https://Stackoverflow.com/questions/1932604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235071/" ]
I also found out that ``` :set path+=./foo/bar ``` adds a search location relative to the directory of the current file, just like '.' does. My vim didn't want to search for such include ``` #include <common/util/string.h> ``` So what I needed to do was ``` :set path+=foo/bar ``` instead of ``` :set path+=./foo/bar ``` The former adds a search path relative to current working directory. Hopefully it helps someone.
I know this is an old question, but I also had some troubles with this for another reason and it took me some time to find out why. I hope this might be helpful to someone. When a directory is matched with `wildignore`, `gf` does not work for files in it, nor does :find. This is obvious if you read wildignore's documentation, but I forgot I ever changed this variable, and what it was for exactly. Also I used a glob, and it was not immediately apparent to me that the directory I was using gf in, was also matched with this glob.
1,932,604
I am using [Vim](http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and I have set the path (`set path+= c:/work/etc/etc`) to my project directory (for C#), but still using command 'gf' give me error: > > E:447 Can't find file. > > > Is there anything I am doing wrong over here?
2009/12/19
[ "https://Stackoverflow.com/questions/1932604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235071/" ]
G'day, To get a bit more detail on your current path settings you can see what's being included and the files vim can't find by entering the command: ``` :checkpath ``` and you'll get a dump of the files not found, e.g. ``` --- Included files not found in path --- <io.h> vim.h --> <functions.h> <clib/exec_protos.h> ``` Or you can get a listing of all included files, both found and not found, by entering ``` :checkpath! ``` Enter ``` :help path ``` to get more info on the path syntax. **Edit:** Don't forget that using the syntax ``` set path=/work ``` will completely reset your path variable to what you've just declared. I'd suggest using ``` set path+=/work ``` instead. This won't clobber the current path and will just add your /work directory instead. HTH
I also found out that ``` :set path+=./foo/bar ``` adds a search location relative to the directory of the current file, just like '.' does. My vim didn't want to search for such include ``` #include <common/util/string.h> ``` So what I needed to do was ``` :set path+=foo/bar ``` instead of ``` :set path+=./foo/bar ``` The former adds a search path relative to current working directory. Hopefully it helps someone.
1,932,604
I am using [Vim](http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and I have set the path (`set path+= c:/work/etc/etc`) to my project directory (for C#), but still using command 'gf' give me error: > > E:447 Can't find file. > > > Is there anything I am doing wrong over here?
2009/12/19
[ "https://Stackoverflow.com/questions/1932604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235071/" ]
G'day, To get a bit more detail on your current path settings you can see what's being included and the files vim can't find by entering the command: ``` :checkpath ``` and you'll get a dump of the files not found, e.g. ``` --- Included files not found in path --- <io.h> vim.h --> <functions.h> <clib/exec_protos.h> ``` Or you can get a listing of all included files, both found and not found, by entering ``` :checkpath! ``` Enter ``` :help path ``` to get more info on the path syntax. **Edit:** Don't forget that using the syntax ``` set path=/work ``` will completely reset your path variable to what you've just declared. I'd suggest using ``` set path+=/work ``` instead. This won't clobber the current path and will just add your /work directory instead. HTH
Make sure there is no leading character to the file name if you press `gf`, i.e. using `gf` when the cursor is on help.txt will not work here: ``` file=help.txt ```
1,932,604
I am using [Vim](http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and I have set the path (`set path+= c:/work/etc/etc`) to my project directory (for C#), but still using command 'gf' give me error: > > E:447 Can't find file. > > > Is there anything I am doing wrong over here?
2009/12/19
[ "https://Stackoverflow.com/questions/1932604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235071/" ]
G'day, To get a bit more detail on your current path settings you can see what's being included and the files vim can't find by entering the command: ``` :checkpath ``` and you'll get a dump of the files not found, e.g. ``` --- Included files not found in path --- <io.h> vim.h --> <functions.h> <clib/exec_protos.h> ``` Or you can get a listing of all included files, both found and not found, by entering ``` :checkpath! ``` Enter ``` :help path ``` to get more info on the path syntax. **Edit:** Don't forget that using the syntax ``` set path=/work ``` will completely reset your path variable to what you've just declared. I'd suggest using ``` set path+=/work ``` instead. This won't clobber the current path and will just add your /work directory instead. HTH
I know this is an old question, but I also had some troubles with this for another reason and it took me some time to find out why. I hope this might be helpful to someone. When a directory is matched with `wildignore`, `gf` does not work for files in it, nor does :find. This is obvious if you read wildignore's documentation, but I forgot I ever changed this variable, and what it was for exactly. Also I used a glob, and it was not immediately apparent to me that the directory I was using gf in, was also matched with this glob.
1,932,604
I am using [Vim](http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and I have set the path (`set path+= c:/work/etc/etc`) to my project directory (for C#), but still using command 'gf' give me error: > > E:447 Can't find file. > > > Is there anything I am doing wrong over here?
2009/12/19
[ "https://Stackoverflow.com/questions/1932604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235071/" ]
First can you open the file using **:find file.name** ? (**:help find** for more info). If this does not work then your path is wrong. If **:find** does locate your file then do the following: 1. Insure that you are not in **Visual/Insert** mode 2. Place cursor on the first letter of the filename and press **gf**
If you are talking about the ***`gf` tool wri††en by tomnomnom*** then here's how to set-up: ============================================================================================ **Setting PATH for GO** (if you have not setup yet). ``` export GOROOT=$HOME/go export PATH=$PATH:$GOROOT/bin ``` Step 1: **Download tool** from [github](https://github.com/tomnomnom/gf.git) Step 2: `cp -r path/to/tomnomnom/gf/examples ~/.gf` Step 3: `source ~/tools/gf/gf-completion.bash` Now gf should work along with auto-completion from anywhere. Source: Original sources are present at his [repo.](https://github.com/tomnomnom/gf)
1,932,604
I am using [Vim](http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and I have set the path (`set path+= c:/work/etc/etc`) to my project directory (for C#), but still using command 'gf' give me error: > > E:447 Can't find file. > > > Is there anything I am doing wrong over here?
2009/12/19
[ "https://Stackoverflow.com/questions/1932604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235071/" ]
I also found out that ``` :set path+=./foo/bar ``` adds a search location relative to the directory of the current file, just like '.' does. My vim didn't want to search for such include ``` #include <common/util/string.h> ``` So what I needed to do was ``` :set path+=foo/bar ``` instead of ``` :set path+=./foo/bar ``` The former adds a search path relative to current working directory. Hopefully it helps someone.
If you are talking about the ***`gf` tool wri††en by tomnomnom*** then here's how to set-up: ============================================================================================ **Setting PATH for GO** (if you have not setup yet). ``` export GOROOT=$HOME/go export PATH=$PATH:$GOROOT/bin ``` Step 1: **Download tool** from [github](https://github.com/tomnomnom/gf.git) Step 2: `cp -r path/to/tomnomnom/gf/examples ~/.gf` Step 3: `source ~/tools/gf/gf-completion.bash` Now gf should work along with auto-completion from anywhere. Source: Original sources are present at his [repo.](https://github.com/tomnomnom/gf)
1,932,604
I am using [Vim](http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and I have set the path (`set path+= c:/work/etc/etc`) to my project directory (for C#), but still using command 'gf' give me error: > > E:447 Can't find file. > > > Is there anything I am doing wrong over here?
2009/12/19
[ "https://Stackoverflow.com/questions/1932604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235071/" ]
First can you open the file using **:find file.name** ? (**:help find** for more info). If this does not work then your path is wrong. If **:find** does locate your file then do the following: 1. Insure that you are not in **Visual/Insert** mode 2. Place cursor on the first letter of the filename and press **gf**
Make sure there is no leading character to the file name if you press `gf`, i.e. using `gf` when the cursor is on help.txt will not work here: ``` file=help.txt ```
1,932,604
I am using [Vim](http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and I have set the path (`set path+= c:/work/etc/etc`) to my project directory (for C#), but still using command 'gf' give me error: > > E:447 Can't find file. > > > Is there anything I am doing wrong over here?
2009/12/19
[ "https://Stackoverflow.com/questions/1932604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235071/" ]
G'day, To get a bit more detail on your current path settings you can see what's being included and the files vim can't find by entering the command: ``` :checkpath ``` and you'll get a dump of the files not found, e.g. ``` --- Included files not found in path --- <io.h> vim.h --> <functions.h> <clib/exec_protos.h> ``` Or you can get a listing of all included files, both found and not found, by entering ``` :checkpath! ``` Enter ``` :help path ``` to get more info on the path syntax. **Edit:** Don't forget that using the syntax ``` set path=/work ``` will completely reset your path variable to what you've just declared. I'd suggest using ``` set path+=/work ``` instead. This won't clobber the current path and will just add your /work directory instead. HTH
If you are talking about the ***`gf` tool wri††en by tomnomnom*** then here's how to set-up: ============================================================================================ **Setting PATH for GO** (if you have not setup yet). ``` export GOROOT=$HOME/go export PATH=$PATH:$GOROOT/bin ``` Step 1: **Download tool** from [github](https://github.com/tomnomnom/gf.git) Step 2: `cp -r path/to/tomnomnom/gf/examples ~/.gf` Step 3: `source ~/tools/gf/gf-completion.bash` Now gf should work along with auto-completion from anywhere. Source: Original sources are present at his [repo.](https://github.com/tomnomnom/gf)
1,932,604
I am using [Vim](http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and I have set the path (`set path+= c:/work/etc/etc`) to my project directory (for C#), but still using command 'gf' give me error: > > E:447 Can't find file. > > > Is there anything I am doing wrong over here?
2009/12/19
[ "https://Stackoverflow.com/questions/1932604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235071/" ]
First can you open the file using **:find file.name** ? (**:help find** for more info). If this does not work then your path is wrong. If **:find** does locate your file then do the following: 1. Insure that you are not in **Visual/Insert** mode 2. Place cursor on the first letter of the filename and press **gf**
I know this is an old question, but I also had some troubles with this for another reason and it took me some time to find out why. I hope this might be helpful to someone. When a directory is matched with `wildignore`, `gf` does not work for files in it, nor does :find. This is obvious if you read wildignore's documentation, but I forgot I ever changed this variable, and what it was for exactly. Also I used a glob, and it was not immediately apparent to me that the directory I was using gf in, was also matched with this glob.
1,932,604
I am using [Vim](http://en.wikipedia.org/wiki/Vim_%28text_editor%29) and I have set the path (`set path+= c:/work/etc/etc`) to my project directory (for C#), but still using command 'gf' give me error: > > E:447 Can't find file. > > > Is there anything I am doing wrong over here?
2009/12/19
[ "https://Stackoverflow.com/questions/1932604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235071/" ]
I know this is an old question, but I also had some troubles with this for another reason and it took me some time to find out why. I hope this might be helpful to someone. When a directory is matched with `wildignore`, `gf` does not work for files in it, nor does :find. This is obvious if you read wildignore's documentation, but I forgot I ever changed this variable, and what it was for exactly. Also I used a glob, and it was not immediately apparent to me that the directory I was using gf in, was also matched with this glob.
If you are talking about the ***`gf` tool wri††en by tomnomnom*** then here's how to set-up: ============================================================================================ **Setting PATH for GO** (if you have not setup yet). ``` export GOROOT=$HOME/go export PATH=$PATH:$GOROOT/bin ``` Step 1: **Download tool** from [github](https://github.com/tomnomnom/gf.git) Step 2: `cp -r path/to/tomnomnom/gf/examples ~/.gf` Step 3: `source ~/tools/gf/gf-completion.bash` Now gf should work along with auto-completion from anywhere. Source: Original sources are present at his [repo.](https://github.com/tomnomnom/gf)
1,452,023
I could use some guidance on the following problem. The whole "No use of XML libraries is allowed" part is throwing me for a loop. Thanks! > > Create a java program that takes XML as input, parses the input and > writes all the element names to the console indented with tabs to > their nesting level. You should handle xml attributes, but you don't > have to display or otherwise interpret them. There is no need to > handle CDATA or any xml processing instructions. No use of xml > libraries is allowed. > > >
2009/09/20
[ "https://Stackoverflow.com/questions/1452023", "https://Stackoverflow.com", "https://Stackoverflow.com/users/139203/" ]
I'm not sure what level is bothering you. First of all you will be iterating over all the XML characters. Personally I'd use StringTokenizer. I know it's a little outdated, but you can easily have it parse on the two angle-bracket characters you are interested in, and you can set it up to return "Tokens". Each token you get will therefore be left-angle, right-angle or some string without angles. In XML, angle's don't nest, that actually saves you quite a bit of work. so let's say your XML looked like this (Outside the code blocks I'm converting angle-brackets to parens because I don't feel like typing all the ampersand crap, anyone uncomfortable with this is encouraged to edit my post and fix it): `<tag var="meh">between</tag>` Your first token is "<", then "tag var="meh", then ">", then "between", then "<", then "/tag", then ">" So far so good. You need to know if you are inside angle-brackets or outside to know what to do with your strings so track that as a boolean. Since there is no nesting, a single boolean should suffice. You also need to know about nesting levels of your tags. That should automatically make your brain flash the word "Stack". Stacks are how you implement nesting, period. So your process is, read a token. If it's "<" set the inside boolean to true and continue, if it's ">" set the boolean to false and continue. Got those two out of the way! You're half done! Next if you are inside, I would instantiate an object with the following properties: ``` String tagName HashMap<String, String> attributes // Why the heck do angle-brackets correctly display here SO?!? String value ``` and push it onto your stack. (Note, LinkedList has a Stack API) So you would store the name in "tagName" and the variables in the HashMap and continue. If it were me, this little class would have a constructor that took a string, and the string it took would be the string between the angle-brackets. It would parse the string itself and store the tagName and attributes before returning. If you did that, then your loop, you just say if you are "inside=true" and the value is not an angle-bracket (you know it's not, those cases were already removed!), then simply: ``` push(new XMLObject(token)); ``` (whoops, if the "token" at this point starts with a "/", you have to do something different, keep on reading). Very concise and readable, no? Finally, the one case remaining is when you are outside and your string is a token. In this case, you know the most recent stack entry was an XMLObject which was filled out except for the "value". The Value should be the token you have right now. You're done except for printing. Oh, I forgot, when you hit your closing tag, you need to pop the value off the stack and print it (push for open tag, pop for closing tag) You can get your indent level by checking the size of the stack (stack.size() should determine how many tabs to print). If you actually want to divide the responsibilities, I'd have XMLObject implement a toString that formatted the data the way you wanted it printed, then when you reach the end tag, all you have to do is: ``` Pop the XMLObject. Print out stack.size() tabs (use print not println!) Print XMLObject.toString(); ``` That's actually your entire project (aside from the legwork of actually coding it). Learn to go through an analysis process of examining your data and developing a simple program like this should quickly become second nature. Good luck with your budding career! This got a little complicated so I made this list of possibilities. Iterate over it for each token, and handle each case. I'm pretty sure this covers every possibility, and if you put in the error checking where I've specified, it'll actually be production quality (I think). Note: you can't actually do this as a case. Consider if/if else statements. ``` case token = "<" //note, if already "inside", this is an error if(inside) throw exception // Indicates < tagname < inside=true; case token = ">" if(!inside) throw exception // Indicates > text or not > inside=false; case inside = false stack.peek().setValue(token) case inside (inside = true) sub-case token startsWith "!-- & endsWith "--" comment, ignore sub-case token startsWith "/" and endsWith "/" and is more than 1 char long create the object, then act as though you found a close tag sub-case token = "" (throw exception/print error/bail! // inside must have a tag!) sub-case token.startsWtih("/") create & push sub-case token doesn't .startWith "/" sub-sub-case length=1 (just the slash, lazy close tag) pop & print sub-sub-case length > 1 print an error unless (stack.peek().getTagName().equals(tagWithoutSlash)) pop & print ``` That's about it. I think each of these cases were 1 line, maybe 2 or 3 if you don't nest things like stack.push(new XMLObject(token)). I wouldn't have provided this much, but it got more complicated than I thought since I'm including all the error checking and stuff. I've tried to avoid actual java wherever possible, so use your own style! The XMLObject class as described is a really good idea though. Get in the habit of making new classes wherever possible (I've literally never seen code with too many classes). This is way too much help, but it's so much fun I may write an XML parser just for the hell of it.
Id use Test Driven Development here I would write tests like assertEquals("test", parse("<test />")); assertEquals("test", parse("<test></test>")); assertEquals("test\n\tfun", parse("<test><fun></fun></test>")); etc. and make them all pass. remember to handle corner cases and bad xml. parsing you can do: 1) with String.indexOf find first(<) and last(>) xml element in a loop and handle what is inside. using recursion will get you a better grade. 2) you could also use String.split. you could split on first and last xml element or use regex to get what is inside of the xml elements. 2a is the easiest to do, 2b might be the fastest to write if you know regex, but 1 is best because its faster(you might not see it, but it sounds faster) and many teachers only care about performance.
1,452,023
I could use some guidance on the following problem. The whole "No use of XML libraries is allowed" part is throwing me for a loop. Thanks! > > Create a java program that takes XML as input, parses the input and > writes all the element names to the console indented with tabs to > their nesting level. You should handle xml attributes, but you don't > have to display or otherwise interpret them. There is no need to > handle CDATA or any xml processing instructions. No use of xml > libraries is allowed. > > >
2009/09/20
[ "https://Stackoverflow.com/questions/1452023", "https://Stackoverflow.com", "https://Stackoverflow.com/users/139203/" ]
I'm not sure what level is bothering you. First of all you will be iterating over all the XML characters. Personally I'd use StringTokenizer. I know it's a little outdated, but you can easily have it parse on the two angle-bracket characters you are interested in, and you can set it up to return "Tokens". Each token you get will therefore be left-angle, right-angle or some string without angles. In XML, angle's don't nest, that actually saves you quite a bit of work. so let's say your XML looked like this (Outside the code blocks I'm converting angle-brackets to parens because I don't feel like typing all the ampersand crap, anyone uncomfortable with this is encouraged to edit my post and fix it): `<tag var="meh">between</tag>` Your first token is "<", then "tag var="meh", then ">", then "between", then "<", then "/tag", then ">" So far so good. You need to know if you are inside angle-brackets or outside to know what to do with your strings so track that as a boolean. Since there is no nesting, a single boolean should suffice. You also need to know about nesting levels of your tags. That should automatically make your brain flash the word "Stack". Stacks are how you implement nesting, period. So your process is, read a token. If it's "<" set the inside boolean to true and continue, if it's ">" set the boolean to false and continue. Got those two out of the way! You're half done! Next if you are inside, I would instantiate an object with the following properties: ``` String tagName HashMap<String, String> attributes // Why the heck do angle-brackets correctly display here SO?!? String value ``` and push it onto your stack. (Note, LinkedList has a Stack API) So you would store the name in "tagName" and the variables in the HashMap and continue. If it were me, this little class would have a constructor that took a string, and the string it took would be the string between the angle-brackets. It would parse the string itself and store the tagName and attributes before returning. If you did that, then your loop, you just say if you are "inside=true" and the value is not an angle-bracket (you know it's not, those cases were already removed!), then simply: ``` push(new XMLObject(token)); ``` (whoops, if the "token" at this point starts with a "/", you have to do something different, keep on reading). Very concise and readable, no? Finally, the one case remaining is when you are outside and your string is a token. In this case, you know the most recent stack entry was an XMLObject which was filled out except for the "value". The Value should be the token you have right now. You're done except for printing. Oh, I forgot, when you hit your closing tag, you need to pop the value off the stack and print it (push for open tag, pop for closing tag) You can get your indent level by checking the size of the stack (stack.size() should determine how many tabs to print). If you actually want to divide the responsibilities, I'd have XMLObject implement a toString that formatted the data the way you wanted it printed, then when you reach the end tag, all you have to do is: ``` Pop the XMLObject. Print out stack.size() tabs (use print not println!) Print XMLObject.toString(); ``` That's actually your entire project (aside from the legwork of actually coding it). Learn to go through an analysis process of examining your data and developing a simple program like this should quickly become second nature. Good luck with your budding career! This got a little complicated so I made this list of possibilities. Iterate over it for each token, and handle each case. I'm pretty sure this covers every possibility, and if you put in the error checking where I've specified, it'll actually be production quality (I think). Note: you can't actually do this as a case. Consider if/if else statements. ``` case token = "<" //note, if already "inside", this is an error if(inside) throw exception // Indicates < tagname < inside=true; case token = ">" if(!inside) throw exception // Indicates > text or not > inside=false; case inside = false stack.peek().setValue(token) case inside (inside = true) sub-case token startsWith "!-- & endsWith "--" comment, ignore sub-case token startsWith "/" and endsWith "/" and is more than 1 char long create the object, then act as though you found a close tag sub-case token = "" (throw exception/print error/bail! // inside must have a tag!) sub-case token.startsWtih("/") create & push sub-case token doesn't .startWith "/" sub-sub-case length=1 (just the slash, lazy close tag) pop & print sub-sub-case length > 1 print an error unless (stack.peek().getTagName().equals(tagWithoutSlash)) pop & print ``` That's about it. I think each of these cases were 1 line, maybe 2 or 3 if you don't nest things like stack.push(new XMLObject(token)). I wouldn't have provided this much, but it got more complicated than I thought since I'm including all the error checking and stuff. I've tried to avoid actual java wherever possible, so use your own style! The XMLObject class as described is a really good idea though. Get in the habit of making new classes wherever possible (I've literally never seen code with too many classes). This is way too much help, but it's so much fun I may write an XML parser just for the hell of it.
Slightly tricky cases to be aware of: * comments e.g. `<!-- this is a comment-->` * empty tags (`/>` ending the tag e.g. `<element foo='1' bar='2' baz='3' />`)
1,452,023
I could use some guidance on the following problem. The whole "No use of XML libraries is allowed" part is throwing me for a loop. Thanks! > > Create a java program that takes XML as input, parses the input and > writes all the element names to the console indented with tabs to > their nesting level. You should handle xml attributes, but you don't > have to display or otherwise interpret them. There is no need to > handle CDATA or any xml processing instructions. No use of xml > libraries is allowed. > > >
2009/09/20
[ "https://Stackoverflow.com/questions/1452023", "https://Stackoverflow.com", "https://Stackoverflow.com/users/139203/" ]
I'm not sure what level is bothering you. First of all you will be iterating over all the XML characters. Personally I'd use StringTokenizer. I know it's a little outdated, but you can easily have it parse on the two angle-bracket characters you are interested in, and you can set it up to return "Tokens". Each token you get will therefore be left-angle, right-angle or some string without angles. In XML, angle's don't nest, that actually saves you quite a bit of work. so let's say your XML looked like this (Outside the code blocks I'm converting angle-brackets to parens because I don't feel like typing all the ampersand crap, anyone uncomfortable with this is encouraged to edit my post and fix it): `<tag var="meh">between</tag>` Your first token is "<", then "tag var="meh", then ">", then "between", then "<", then "/tag", then ">" So far so good. You need to know if you are inside angle-brackets or outside to know what to do with your strings so track that as a boolean. Since there is no nesting, a single boolean should suffice. You also need to know about nesting levels of your tags. That should automatically make your brain flash the word "Stack". Stacks are how you implement nesting, period. So your process is, read a token. If it's "<" set the inside boolean to true and continue, if it's ">" set the boolean to false and continue. Got those two out of the way! You're half done! Next if you are inside, I would instantiate an object with the following properties: ``` String tagName HashMap<String, String> attributes // Why the heck do angle-brackets correctly display here SO?!? String value ``` and push it onto your stack. (Note, LinkedList has a Stack API) So you would store the name in "tagName" and the variables in the HashMap and continue. If it were me, this little class would have a constructor that took a string, and the string it took would be the string between the angle-brackets. It would parse the string itself and store the tagName and attributes before returning. If you did that, then your loop, you just say if you are "inside=true" and the value is not an angle-bracket (you know it's not, those cases were already removed!), then simply: ``` push(new XMLObject(token)); ``` (whoops, if the "token" at this point starts with a "/", you have to do something different, keep on reading). Very concise and readable, no? Finally, the one case remaining is when you are outside and your string is a token. In this case, you know the most recent stack entry was an XMLObject which was filled out except for the "value". The Value should be the token you have right now. You're done except for printing. Oh, I forgot, when you hit your closing tag, you need to pop the value off the stack and print it (push for open tag, pop for closing tag) You can get your indent level by checking the size of the stack (stack.size() should determine how many tabs to print). If you actually want to divide the responsibilities, I'd have XMLObject implement a toString that formatted the data the way you wanted it printed, then when you reach the end tag, all you have to do is: ``` Pop the XMLObject. Print out stack.size() tabs (use print not println!) Print XMLObject.toString(); ``` That's actually your entire project (aside from the legwork of actually coding it). Learn to go through an analysis process of examining your data and developing a simple program like this should quickly become second nature. Good luck with your budding career! This got a little complicated so I made this list of possibilities. Iterate over it for each token, and handle each case. I'm pretty sure this covers every possibility, and if you put in the error checking where I've specified, it'll actually be production quality (I think). Note: you can't actually do this as a case. Consider if/if else statements. ``` case token = "<" //note, if already "inside", this is an error if(inside) throw exception // Indicates < tagname < inside=true; case token = ">" if(!inside) throw exception // Indicates > text or not > inside=false; case inside = false stack.peek().setValue(token) case inside (inside = true) sub-case token startsWith "!-- & endsWith "--" comment, ignore sub-case token startsWith "/" and endsWith "/" and is more than 1 char long create the object, then act as though you found a close tag sub-case token = "" (throw exception/print error/bail! // inside must have a tag!) sub-case token.startsWtih("/") create & push sub-case token doesn't .startWith "/" sub-sub-case length=1 (just the slash, lazy close tag) pop & print sub-sub-case length > 1 print an error unless (stack.peek().getTagName().equals(tagWithoutSlash)) pop & print ``` That's about it. I think each of these cases were 1 line, maybe 2 or 3 if you don't nest things like stack.push(new XMLObject(token)). I wouldn't have provided this much, but it got more complicated than I thought since I'm including all the error checking and stuff. I've tried to avoid actual java wherever possible, so use your own style! The XMLObject class as described is a really good idea though. Get in the habit of making new classes wherever possible (I've literally never seen code with too many classes). This is way too much help, but it's so much fun I may write an XML parser just for the hell of it.
Just go through the XML file character by character and do what you have to do. 1. Set up some state variable (with values like waiting for opening tag, reading element name, waiting for attribute name, reading attribute value, reading element content -- waiting for closing tag etc.). 2. Set up depth counter (because you need that for pretty printing). 3. Use state variable and current character to decide how to change the state or add the new character to what you have read so far. 4. Assume that your XML is well-formed. Your actual task is much easier than 'XML parser' sounds.
1,799,376
I am seeing the following error in the event log. It is coming from our ASP.Net application. I am having trouble tracking down what is causing the error. Any suggestions appreciated! * **OS**: Windows Server 2000 * **WebServer**: IIS 6 * **Application**: ASP.Net v3.5 **Error Log** > > [MachineName] has logged the following > Error for IIS > > > Details: ComputerName=[ComputerName] > User=Not specified Logfile=Application > Type=Error EventType=1 > SourceName=ASP.NET 2.0.50727.0 > Category=0 CategoryString=Not > specified EventCode=1334 > EventID=-1073740490 > TimeGenerated=20091125101806.000000-360 > TimeWritten=20091125101806.000000-360 > Message=An unhandled exception > occurred and the process was > terminated. > > > Application ID: DefaultDomain Process > ID: 1440 Exception: > System.Runtime.Serialization.SerializationException > Message: Unable to find assembly > 'Company.Common, Version=1.0.0.0, > Culture=neutral, PublicKeyToken=null'. > > > StackTrace: at > System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() > at > System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo > assemblyInfo, String name) at > System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String > objectName, String[] memberNames, > BinaryTypeEnum[] binaryTypeEnumA, > Object[] typeInformationA, Int32[] > memberAssemIds, ObjectReader > objectReader, Int32 objectId, > BinaryAssemblyInfo assemblyInfo, > SizedArray assemIdToAssemblyTable) > > at > System.Runtime.Serialization.Formatters.Binary.\_\_BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped > record) at > System.Runtime.Serialization.Formatters.Binary.\_\_BinaryParser.Run() > at > System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler > handler, \_\_BinaryParser serParser, > Boolean fCheck, Boolean > isCrossAppDomain, IMethodCallMessage > methodCallMessage) at > System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream > serializationStream, HeaderHandler > handler, Boolean fCheck, Boolean > isCrossAppDomain, IMethodCallMessage > methodCallMessage) at > System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream > stm) at > System.AppDomain.Deserialize(Byte[] > blob) at > System.AppDomain.UnmarshalObject(Byte[] > blob) > > >
2009/11/25
[ "https://Stackoverflow.com/questions/1799376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/82696/" ]
I created a custom unhanded exception module, which allowed retrieval of more information about the origin of the bug, and the eventual resolution of the issue. Here is a link to a codeplex project that has code for an unhanded exception module: <http://unhandledexception.codeplex.com/SourceControl/changeset/view/80132>
I'm looking at the text "Unable to find assembly 'Company.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'". Are you missing an assembly, or do you have a version problem?
1,799,376
I am seeing the following error in the event log. It is coming from our ASP.Net application. I am having trouble tracking down what is causing the error. Any suggestions appreciated! * **OS**: Windows Server 2000 * **WebServer**: IIS 6 * **Application**: ASP.Net v3.5 **Error Log** > > [MachineName] has logged the following > Error for IIS > > > Details: ComputerName=[ComputerName] > User=Not specified Logfile=Application > Type=Error EventType=1 > SourceName=ASP.NET 2.0.50727.0 > Category=0 CategoryString=Not > specified EventCode=1334 > EventID=-1073740490 > TimeGenerated=20091125101806.000000-360 > TimeWritten=20091125101806.000000-360 > Message=An unhandled exception > occurred and the process was > terminated. > > > Application ID: DefaultDomain Process > ID: 1440 Exception: > System.Runtime.Serialization.SerializationException > Message: Unable to find assembly > 'Company.Common, Version=1.0.0.0, > Culture=neutral, PublicKeyToken=null'. > > > StackTrace: at > System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() > at > System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo > assemblyInfo, String name) at > System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String > objectName, String[] memberNames, > BinaryTypeEnum[] binaryTypeEnumA, > Object[] typeInformationA, Int32[] > memberAssemIds, ObjectReader > objectReader, Int32 objectId, > BinaryAssemblyInfo assemblyInfo, > SizedArray assemIdToAssemblyTable) > > at > System.Runtime.Serialization.Formatters.Binary.\_\_BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped > record) at > System.Runtime.Serialization.Formatters.Binary.\_\_BinaryParser.Run() > at > System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler > handler, \_\_BinaryParser serParser, > Boolean fCheck, Boolean > isCrossAppDomain, IMethodCallMessage > methodCallMessage) at > System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream > serializationStream, HeaderHandler > handler, Boolean fCheck, Boolean > isCrossAppDomain, IMethodCallMessage > methodCallMessage) at > System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream > stm) at > System.AppDomain.Deserialize(Byte[] > blob) at > System.AppDomain.UnmarshalObject(Byte[] > blob) > > >
2009/11/25
[ "https://Stackoverflow.com/questions/1799376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/82696/" ]
Try the IIS Debug Diagnostics tools <http://support.microsoft.com/kb/919789>
I'm looking at the text "Unable to find assembly 'Company.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'". Are you missing an assembly, or do you have a version problem?
1,799,376
I am seeing the following error in the event log. It is coming from our ASP.Net application. I am having trouble tracking down what is causing the error. Any suggestions appreciated! * **OS**: Windows Server 2000 * **WebServer**: IIS 6 * **Application**: ASP.Net v3.5 **Error Log** > > [MachineName] has logged the following > Error for IIS > > > Details: ComputerName=[ComputerName] > User=Not specified Logfile=Application > Type=Error EventType=1 > SourceName=ASP.NET 2.0.50727.0 > Category=0 CategoryString=Not > specified EventCode=1334 > EventID=-1073740490 > TimeGenerated=20091125101806.000000-360 > TimeWritten=20091125101806.000000-360 > Message=An unhandled exception > occurred and the process was > terminated. > > > Application ID: DefaultDomain Process > ID: 1440 Exception: > System.Runtime.Serialization.SerializationException > Message: Unable to find assembly > 'Company.Common, Version=1.0.0.0, > Culture=neutral, PublicKeyToken=null'. > > > StackTrace: at > System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() > at > System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo > assemblyInfo, String name) at > System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String > objectName, String[] memberNames, > BinaryTypeEnum[] binaryTypeEnumA, > Object[] typeInformationA, Int32[] > memberAssemIds, ObjectReader > objectReader, Int32 objectId, > BinaryAssemblyInfo assemblyInfo, > SizedArray assemIdToAssemblyTable) > > at > System.Runtime.Serialization.Formatters.Binary.\_\_BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped > record) at > System.Runtime.Serialization.Formatters.Binary.\_\_BinaryParser.Run() > at > System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler > handler, \_\_BinaryParser serParser, > Boolean fCheck, Boolean > isCrossAppDomain, IMethodCallMessage > methodCallMessage) at > System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream > serializationStream, HeaderHandler > handler, Boolean fCheck, Boolean > isCrossAppDomain, IMethodCallMessage > methodCallMessage) at > System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream > stm) at > System.AppDomain.Deserialize(Byte[] > blob) at > System.AppDomain.UnmarshalObject(Byte[] > blob) > > >
2009/11/25
[ "https://Stackoverflow.com/questions/1799376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/82696/" ]
I created a custom unhanded exception module, which allowed retrieval of more information about the origin of the bug, and the eventual resolution of the issue. Here is a link to a codeplex project that has code for an unhanded exception module: <http://unhandledexception.codeplex.com/SourceControl/changeset/view/80132>
The error says the assembly can't be found. If it's in the bin folder and correctly formatted, then perhaps it's a permission error? Does your Company.Common assembly have permissions that allow it to be read by your IIS AppPool identity? You might also double-check to make sure that the assembly is listed in the system.web / compilation / assemblies section of your web.config.
1,799,376
I am seeing the following error in the event log. It is coming from our ASP.Net application. I am having trouble tracking down what is causing the error. Any suggestions appreciated! * **OS**: Windows Server 2000 * **WebServer**: IIS 6 * **Application**: ASP.Net v3.5 **Error Log** > > [MachineName] has logged the following > Error for IIS > > > Details: ComputerName=[ComputerName] > User=Not specified Logfile=Application > Type=Error EventType=1 > SourceName=ASP.NET 2.0.50727.0 > Category=0 CategoryString=Not > specified EventCode=1334 > EventID=-1073740490 > TimeGenerated=20091125101806.000000-360 > TimeWritten=20091125101806.000000-360 > Message=An unhandled exception > occurred and the process was > terminated. > > > Application ID: DefaultDomain Process > ID: 1440 Exception: > System.Runtime.Serialization.SerializationException > Message: Unable to find assembly > 'Company.Common, Version=1.0.0.0, > Culture=neutral, PublicKeyToken=null'. > > > StackTrace: at > System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() > at > System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo > assemblyInfo, String name) at > System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String > objectName, String[] memberNames, > BinaryTypeEnum[] binaryTypeEnumA, > Object[] typeInformationA, Int32[] > memberAssemIds, ObjectReader > objectReader, Int32 objectId, > BinaryAssemblyInfo assemblyInfo, > SizedArray assemIdToAssemblyTable) > > at > System.Runtime.Serialization.Formatters.Binary.\_\_BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped > record) at > System.Runtime.Serialization.Formatters.Binary.\_\_BinaryParser.Run() > at > System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler > handler, \_\_BinaryParser serParser, > Boolean fCheck, Boolean > isCrossAppDomain, IMethodCallMessage > methodCallMessage) at > System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream > serializationStream, HeaderHandler > handler, Boolean fCheck, Boolean > isCrossAppDomain, IMethodCallMessage > methodCallMessage) at > System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream > stm) at > System.AppDomain.Deserialize(Byte[] > blob) at > System.AppDomain.UnmarshalObject(Byte[] > blob) > > >
2009/11/25
[ "https://Stackoverflow.com/questions/1799376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/82696/" ]
Try the IIS Debug Diagnostics tools <http://support.microsoft.com/kb/919789>
The error says the assembly can't be found. If it's in the bin folder and correctly formatted, then perhaps it's a permission error? Does your Company.Common assembly have permissions that allow it to be read by your IIS AppPool identity? You might also double-check to make sure that the assembly is listed in the system.web / compilation / assemblies section of your web.config.
1,799,376
I am seeing the following error in the event log. It is coming from our ASP.Net application. I am having trouble tracking down what is causing the error. Any suggestions appreciated! * **OS**: Windows Server 2000 * **WebServer**: IIS 6 * **Application**: ASP.Net v3.5 **Error Log** > > [MachineName] has logged the following > Error for IIS > > > Details: ComputerName=[ComputerName] > User=Not specified Logfile=Application > Type=Error EventType=1 > SourceName=ASP.NET 2.0.50727.0 > Category=0 CategoryString=Not > specified EventCode=1334 > EventID=-1073740490 > TimeGenerated=20091125101806.000000-360 > TimeWritten=20091125101806.000000-360 > Message=An unhandled exception > occurred and the process was > terminated. > > > Application ID: DefaultDomain Process > ID: 1440 Exception: > System.Runtime.Serialization.SerializationException > Message: Unable to find assembly > 'Company.Common, Version=1.0.0.0, > Culture=neutral, PublicKeyToken=null'. > > > StackTrace: at > System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() > at > System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo > assemblyInfo, String name) at > System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String > objectName, String[] memberNames, > BinaryTypeEnum[] binaryTypeEnumA, > Object[] typeInformationA, Int32[] > memberAssemIds, ObjectReader > objectReader, Int32 objectId, > BinaryAssemblyInfo assemblyInfo, > SizedArray assemIdToAssemblyTable) > > at > System.Runtime.Serialization.Formatters.Binary.\_\_BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped > record) at > System.Runtime.Serialization.Formatters.Binary.\_\_BinaryParser.Run() > at > System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler > handler, \_\_BinaryParser serParser, > Boolean fCheck, Boolean > isCrossAppDomain, IMethodCallMessage > methodCallMessage) at > System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream > serializationStream, HeaderHandler > handler, Boolean fCheck, Boolean > isCrossAppDomain, IMethodCallMessage > methodCallMessage) at > System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream > stm) at > System.AppDomain.Deserialize(Byte[] > blob) at > System.AppDomain.UnmarshalObject(Byte[] > blob) > > >
2009/11/25
[ "https://Stackoverflow.com/questions/1799376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/82696/" ]
I created a custom unhanded exception module, which allowed retrieval of more information about the origin of the bug, and the eventual resolution of the issue. Here is a link to a codeplex project that has code for an unhanded exception module: <http://unhandledexception.codeplex.com/SourceControl/changeset/view/80132>
Try the IIS Debug Diagnostics tools <http://support.microsoft.com/kb/919789>