qid
int64
1
82.4k
question
stringlengths
27
22.5k
answers
stringlengths
509
252k
date
stringlengths
10
10
metadata
stringlengths
108
162
78,560
<p>I have an SQL Server database where I have the data and log files stored on an external USB drive. I switch the external drive between my main development machine in my office and my laptop when not in my office. I am trying to use sp_detach_db and sp_attach_db when moving between desktop and laptop machines. I find that this works OK on the desktop - I can detach and reattach the database there no problems. But on the laptop I cannot reattach the database (the database was actually originally created on the laptop and the first detach happened there). When I try to reattach on the laptop I get the following error:</p> <p>Unable to open the physical file "p:\SQLData\AppManager.mdf". Operating system error 5: "5(error not found)"</p> <p>I find a lot of references to this error all stating that it is a permissions issue. So I went down this path and made sure that the SQL Server service account has appropriate permissions. I have also created a new database on this same path and been able to succesfully detach and reattach it. So I am confident permissions is not the issue.</p> <p>Further investigation reveals that I cannot rename, copy or move the data files as Windows thinks they are locked - even when the SQL Server service is stopped. Process Explorer does not show up any process locking the files. </p> <p>How can I find out what is locking the files and unlock them.</p> <p>I have verified that the databases do not show up in SSMS - so SQL Server does not still think they exist.</p> <p><strong>Update 18/09/2008</strong></p> <p>I have tried all of the suggested answers to date with no success. However trying these suggestions has helped to clarify the situation. I can verify the following:</p> <ol> <li>I can successfully detach and reattach the database only when the external drive is attached to the server that a copy of the database is restored to - effectively the server where the database is "created" - lets call this the "Source Server". </li> <li>I can move, copy or rename the data and log files, after detaching the database, while the external drive is still attached to the Source Server. </li> <li>As soon as I move the external drive to another machine the data and log files are "locked", although the 2 tools that I have tried - Process Explorer and Unlocker, both find no locking handles attached to the files. </li> </ol> <p>NB. After detaching the database I tried both stopping the SQL Server service and shutting down the Source Server prior to moving the external drive - still with no success.</p> <p>So at this stage all that I can do to move data between desktop and laptop is to make a backup of the data onto the external drive, move the external drive, restore the data from the backup. Works OK but takes a bit more time as the database is a reasonable size (1gb). Anyway this is the only choice I have at this stage even though I was trying to avoid having to go down this path.</p>
[{'answer_id': 78596, 'author': 'Charles Graham', 'author_id': 7705, 'author_profile': 'https://Stackoverflow.com/users/7705', 'pm_score': 0, 'selected': False, 'text': "<p>When you are in Enterprise Manager or SSMS, can you see the name of the database that you are talking about? There might be a leftover database in a funky state. I'd make sure that you have a backup or a copy of the mdf somewhere safe. If this is the case, maybe try dropping the database and then re-attaching it.</p>\n"}, {'answer_id': 78635, 'author': 'Bryant', 'author_id': 10893, 'author_profile': 'https://Stackoverflow.com/users/10893', 'pm_score': 1, 'selected': False, 'text': '<p>Can you copy the files? I\'d be curious to know if you can copy the files to your laptop and then attach them there. I would guess it is some kind of permissions error also, but it sounds like you\'ve done the work to fix this. </p>\n\n<p>Are there any attributes on the file?</p>\n\n<p>Update: If you can\'t copy the files then something must be locking them. I would check out <a href="http://www.emptyloop.com/unlocker/" rel="nofollow noreferrer">Unlocker</a> which I haven\'t tried but sounds like a good starting point. You might also try taking ownership of the files under the file permissions.</p>\n'}, {'answer_id': 78636, 'author': 'tbreffni', 'author_id': 637, 'author_profile': 'https://Stackoverflow.com/users/637', 'pm_score': 0, 'selected': False, 'text': "<p>I would try backing up the database on the desktop, and then see if it will restore successfully on the laptop. Doesn't explain your issue but at least you can move forward.</p>\n"}, {'answer_id': 78650, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Run sqlservr.exe in debug mode with the /c switch and see what happens starting up. Any locking or permissions issue can be put to bed by making a copy of the file and transfering the copy to the origional. </p>\n\n<p>Also check the associated log file (.ldf) .. If that file is missing or unavaliable you will not be able to mount the database to any sane/consistant state without resorting to emergency bypass mode.</p>\n'}, {'answer_id': 1141567, 'author': 'onupdatecascade', 'author_id': 139938, 'author_profile': 'https://Stackoverflow.com/users/139938', 'pm_score': 2, 'selected': False, 'text': '<p>Crazy as it sounds, did you try manually granting yourself perms on the files via right-click / properties / security? I think SQL Server 2005 will set permissions on a detached file exclusively to the principal that did the detach (maybe your account, maybe the account under which the SQL Server service runs) and no-one else can manipulate the file. To get around this I have had to manually grant myself file permissions on MDF and LDF files before moving or deleting them. See also blog post at onupdatecascade.com</p>\n'}, {'answer_id': 5528819, 'author': 'Alex from Jitbit', 'author_id': 56621, 'author_profile': 'https://Stackoverflow.com/users/56621', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve had a similar issue. Nothing seemed to resolve it - even tried to reboot the machine completely, restarting SQL services etc. ProcMon and ProcessExplorer were showing nothing so I figured - the "lock" is done by OS.</p>\n\n<p><strong>I resolved it by DELETING the file and restoring it back from the drive mounted under another drive letter.</strong></p>\n\n<p>PS. My database file was not on a USB drive, but on a TrueCrypt-drive (in some you can say it\'s a "removable drive" as well)</p>\n'}, {'answer_id': 14593498, 'author': 'mattpm', 'author_id': 590021, 'author_profile': 'https://Stackoverflow.com/users/590021', 'pm_score': 0, 'selected': False, 'text': "<p>Within SQL Server Configuration Manager, look in SQL Server Services. For all your SQL Server instances, look at which account is selected in the Log On Tab - Log On As:. I've found for instance, changing it to the Local System account resolves the issue you've had. It was the only thing that actually worked for me - and certainly, no shortage of people have had the same problem.</p>\n"}, {'answer_id': 20780330, 'author': 'sarah', 'author_id': 3135953, 'author_profile': 'https://Stackoverflow.com/users/3135953', 'pm_score': 0, 'selected': False, 'text': '<p>It\'s a security issue on -file level security - you have detached db with different credential and attaching it with other credential - just browse the article <a href="http://www.sqlservermanagementstudio.net/2013/12/troubleshooting-with-attaching-and.html" rel="nofollow">http://www.sqlservermanagementstudio.net/2013/12/troubleshooting-with-attaching-and.html</a> \nAnd try copy pasting it to different location.</p>\n'}, {'answer_id': 47219578, 'author': 'Ali Sheikhpour', 'author_id': 4700922, 'author_profile': 'https://Stackoverflow.com/users/4700922', 'pm_score': 0, 'selected': False, 'text': '<p>I solved similar issue by granting system administrator to all permissions:</p>\n\n<ol>\n<li>right click > properties</li>\n<li>security tab</li>\n<li>in <code>group or usernames</code> click edit.</li>\n<li>click add > advanced</li>\n<li>click <code>find now</code> to list all available permissions.</li>\n<li>choose administrator and add it to list.</li>\n<li>grant it to has full permission.</li>\n</ol>\n'}, {'answer_id': 51802582, 'author': 'manisha', 'author_id': 10213163, 'author_profile': 'https://Stackoverflow.com/users/10213163', 'pm_score': -1, 'selected': False, 'text': '<p>I had the same issue. Someone had detached the files and left, and we were unable to move it to another drive. But after taking ownership of the file (security-->advanced-->take ownership to your login id), and then adding your login id to the security tab and giving access on the file, was able to move.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78560', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10135/']
78,570
<p>I need a JavaScript library that supports Ajax as well as help me in making simple and neat animation effects <a href="http://www.voidy.com/" rel="nofollow noreferrer">in a website</a> I am working on.</p> <p>Which library do you recommend?</p>
[{'answer_id': 78573, 'author': 'mopoke', 'author_id': 14054, 'author_profile': 'https://Stackoverflow.com/users/14054', 'pm_score': 4, 'selected': True, 'text': '<p>I would definitely recommend JQuery as the easiest to use and the one which requires you to write the least code. <a href="http://jquery.com/" rel="nofollow noreferrer">http://jquery.com/</a></p>\n'}, {'answer_id': 78584, 'author': 'zmf', 'author_id': 13285, 'author_profile': 'https://Stackoverflow.com/users/13285', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://script.aculo.us/" rel="nofollow noreferrer">http://script.aculo.us/</a></p>\n\n<p>I think it fits your \'neat animation effects\' requirement.</p>\n'}, {'answer_id': 78585, 'author': 'Adam Pierce', 'author_id': 5324, 'author_profile': 'https://Stackoverflow.com/users/5324', 'pm_score': 1, 'selected': False, 'text': '<p>I\'ve been playing with <a href="http://script.aculo.us/" rel="nofollow noreferrer">Scriptaculous</a> and <a href="http://jquery.com/" rel="nofollow noreferrer">jQuery</a>. Both are good although I\'m leaning more toward jQuery.</p>\n'}, {'answer_id': 78597, 'author': 'Joe Skora', 'author_id': 14057, 'author_profile': 'https://Stackoverflow.com/users/14057', 'pm_score': 2, 'selected': False, 'text': '<p>That\'s a pretty broad question, some of the top open source stacks are\n - <a href="http://developer.yahoo.com/yui/" rel="nofollow noreferrer">YUI</a> (Yahoo)\n - Prototype with <a href="http://script.aculo.us/" rel="nofollow noreferrer">Scriptaculuous</a>\n - <a href="http://extjs.com/" rel="nofollow noreferrer">ExtJs</a>\n - <a href="http://dojotoolkit.org/" rel="nofollow noreferrer">Dojo</a></p>\n\n<p>It\'s a pretty personal choice based on code style, look and feel, and which one you prefer.</p>\n'}, {'answer_id': 78598, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 0, 'selected': False, 'text': '<ol>\n<li>If you want to implement some basic animation jQuery is ok.</li>\n<li>Also personally I like the prototype.js</li>\n<li>For more difficult thing we using some features of Microsoft AJAX client library</li>\n</ol>\n'}, {'answer_id': 78730, 'author': 'Scott Swezey', 'author_id': 9439, 'author_profile': 'https://Stackoverflow.com/users/9439', 'pm_score': 2, 'selected': False, 'text': '<p>Take a look at Dojo/Dijit/Dojox (<a href="http://dojotoolkit.org" rel="nofollow noreferrer">http://dojotoolkit.org</a>). They have a lot of cool special effects, and a lot more that will come in handy to anyone working with Javascript.</p>\n\n<p>They also keep docs and related articles at <a href="http://dojocampus.org/" rel="nofollow noreferrer">http://dojocampus.org/</a></p>\n'}, {'answer_id': 79401, 'author': 'Mashed Potato', 'author_id': 14396, 'author_profile': 'https://Stackoverflow.com/users/14396', 'pm_score': 1, 'selected': False, 'text': '<p>I am a fan of <a href="http://developer.yahoo.com/yui/" rel="nofollow noreferrer">YUI</a>. It supports <a href="http://developer.yahoo.com/yui/animation/" rel="nofollow noreferrer">Animation</a> and <a href="http://developer.yahoo.com/yui/connection/" rel="nofollow noreferrer">Ajax</a>.</p>\n\n<p>In addition, there is just a plethora of controls: menus, movable windows, tree controls, sliders, tabview, the list goes on and on. I have used their code and I\'ve had a good <a href="http://developer.yahoo.com/yui/articles/gbs/" rel="nofollow noreferrer">cross-browser</a> experience with it. Doesn\'t surprise me. They do extensive testing on the toolkit.</p>\n'}, {'answer_id': 79429, 'author': 'JP Richardson', 'author_id': 10333, 'author_profile': 'https://Stackoverflow.com/users/10333', 'pm_score': 2, 'selected': False, 'text': "<p>I like ExtJS a lot. It's a great library for developing complex interfaces with javascript.</p>\n"}, {'answer_id': 79488, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Stack Overflow uses jQuery if that matters. Scriptaculous tries pretty hard to do everything that you can do in Flash. Dojo has an SVG abstraction that lets you do things that are not directly supported in JavaScript.</p>\n'}, {'answer_id': 80229, 'author': 'jeannicolas', 'author_id': 14981, 'author_profile': 'https://Stackoverflow.com/users/14981', 'pm_score': 1, 'selected': False, 'text': '<p>Personally, I\'m a fan of <a href="http://www.mootools.net" rel="nofollow noreferrer">MooTools</a>\' animation classes (<a href="http://docs.mootools.net/Fx/Fx.Tween" rel="nofollow noreferrer">Fx.Tween</a>, <a href="http://docs.mootools.net/Fx/Fx.Morph" rel="nofollow noreferrer">Fx.Morph</a>, <a href="http://docs.mootools.net/Fx/Fx.Transitions" rel="nofollow noreferrer">Fx.Transitions</a>). Very straight-forward and easy to use. For more advance animation Fx.Slide, Fx.Scroll and Fx.Elements are also available...</p>\n\n<p>It also has a neat Ajax class (Request) that will take care of all your ajax needs.</p>\n\n<p>Obviously though this is my personal opinion... Any of the big ones (Yahoo UI, jQuery, MooTools, Prototype etc...) will all be able to do both Ajax and Animation so I\'d suggest looking at sample code from all those libraries and chose the one you like the most!</p>\n'}, {'answer_id': 84708, 'author': 'Mike Cornell', 'author_id': 419788, 'author_profile': 'https://Stackoverflow.com/users/419788', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://labs.adobe.com/technologies/spry/articles/data_api/index.html" rel="nofollow noreferrer">Spry</a> has a lot of effects that seem to be relatively easy to use. </p>\n\n<p>The downside (upside?) with Spry is its packaging. It\'s split into many separate pieces and parts. </p>\n\n<p>So if you want to use a lot of Spry, you\'ll either be making several calls to external javascript files, or you\'ll be gluing them together on your own. Spry won\'t do it for you neatly (like YUI does). </p>\n\n<p>However if you want to just use a single component or effect, Spry is very lightweight!</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78570', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/184/']
78,586
<p>I've been googling for a while now, and can't figure out how to create an event in the calendar on a newer Palm OS device. Any ideas on how to do this? I'm guessing that I'll be creating a record in the calendar database, but the format of the data in that record, and which database to put it in, I don't know.</p>
[{'answer_id': 78617, 'author': 'Matt McMinn', 'author_id': 1322, 'author_profile': 'https://Stackoverflow.com/users/1322', 'pm_score': 1, 'selected': False, 'text': '<p>Ok, literally ten seconds after I posted this question, I got an email from the palm developer network that led me right where I needed to go. Frustrating. It appears that you\'ll need the PIM SDK, which is available through the Palm Developer network <a href="https://dts.pdn.palm.com/cgi-bin/palmdev.cfg/php/enduser/std_adp.php?p_faqid=418&amp;p_lva=1378&amp;p_sid=zaz2d2ej&amp;p_redirect=1" rel="nofollow noreferrer">here</a>. </p>\n'}, {'answer_id': 90318, 'author': 'Ben Combee', 'author_id': 1323, 'author_profile': 'https://Stackoverflow.com/users/1323', 'pm_score': 3, 'selected': True, 'text': '<p>In Palm\'s later devices, they moved to an extended format for the PIM applications like Contacts and Calendar. This was done to allow better mapping between the device\'s databases and those used by Microsoft Outlook, but it meant that the format changed from the traditional format in the original PIMs.</p>\n\n<p>Palm has a PIM Access SDk available from <a href="https://pdnet.palm.com/" rel="nofollow noreferrer">the Palm Developer Network site</a> that includes code for accessing these database formats. The devices also support the original database using a shadow version of the DB and system libraries that translate changes back and forth to the shadows. However, the shadow DBs don\'t have all the data that the extended DBs have, and the conversion isn\'t always triggered.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78586', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1322/']
78,590
<p>In Ruby on Rails, there's RJS templates that help do AJAX by returning javascript code that will be executed in the client browser. How can I do a similar thing in the Java/J2EE world? Is Google Widget Toolkit similar to RJS? What options do I have? </p>
[{'answer_id': 78711, 'author': 'Alejandro Bologna', 'author_id': 9263, 'author_profile': 'https://Stackoverflow.com/users/9263', 'pm_score': 1, 'selected': False, 'text': '<p>Yes, I think <a href="http://code.google.com/webtoolkit/" rel="nofollow noreferrer">Google Web Toolkit</a> is the java equivalent to RJS templates.</p>\n'}, {'answer_id': 612216, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>There is no direct equivalent. GWT is great if you want to do all or most of the client side in java. Also worth checking out is <a href="http://directwebremoting.org/" rel="nofollow noreferrer">DWR</a>, which gives you remote procedure call style access to your server code.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78590', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14470/']
78,592
<p>In perl one would simply do the following to store and iterate over a list of names</p> <pre><code>my @fruit = (apple, orange, kiwi); foreach (@fruit) { print $_; } </code></pre> <p>What would the equivalent be in bash?</p>
[{'answer_id': 78600, 'author': 'JBB', 'author_id': 12332, 'author_profile': 'https://Stackoverflow.com/users/12332', 'pm_score': 2, 'selected': False, 'text': '<pre>\nfor i in apple orange kiwi\ndo\n echo $i\ndone\n</pre>\n'}, {'answer_id': 78601, 'author': 'emk', 'author_id': 12089, 'author_profile': 'https://Stackoverflow.com/users/12089', 'pm_score': 4, 'selected': False, 'text': '<p>Like this:</p>\n\n<pre><code>FRUITS="apple orange kiwi"\nfor FRUIT in $FRUITS; do\n echo $FRUIT\ndone\n</code></pre>\n\n<p>Notice this won\'t work if there are spaces in the names of your fruits. In that case, see <a href="https://stackoverflow.com/questions/78592/what-is-a-good-equivalent-to-perl-lists-in-bash#78631">this answer</a> instead, which is slightly less portable but much more robust.</p>\n'}, {'answer_id': 78618, 'author': 'C. K. Young', 'author_id': 13, 'author_profile': 'https://Stackoverflow.com/users/13', 'pm_score': 3, 'selected': False, 'text': '<p>Now that the answer I like has been accepted as the correct answer, I\'ll now move into another topic: how to use <code>IFS</code> for personal gain. :-P</p>\n\n<pre><code>fruits="apple,orange,kiwifruit,dried mango"\n(IFS=,\n for fruit in $fruits; do\n echo "$fruit"\n done)\n</code></pre>\n\n<p>I\'ve put the code in brackets so that the <code>IFS</code> change is isolated into its own subprocess; thus at the end of the bracketed section, <code>IFS</code> is reverted back to its old value. :-)</p>\n'}, {'answer_id': 78631, 'author': 'Charles Duffy', 'author_id': 14122, 'author_profile': 'https://Stackoverflow.com/users/14122', 'pm_score': 7, 'selected': True, 'text': '<p>bash (unlike POSIX sh) supports arrays:</p>\n\n<pre><code>fruits=(apple orange kiwi "dried mango")\nfor fruit in "${fruits[@]}"; do\n echo "${fruit}"\ndone\n</code></pre>\n\n<p>This has the advantage that array elements may contain spaces or other members of $IFS; as long as they were correctly inserted as separate elements, they are read out the same way.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78592', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10747/']
78,599
<p>I'm working on a game for the iPhone and would like it to be able to submit scores back to the server. Simple enough, but I want the scores to be verified to actually come from a game-play. With the (defacto) prohibition on real crypto with the export conditions, what would be the best way to get information back in a secure/verified channel?</p> <p>All my thoughts lead back to an RSA-style digital signature algorithm, but would prefer something less "crypto" to get past that export question.</p> <p>Thanks!</p>
[{'answer_id': 78642, 'author': 'Hank Gay', 'author_id': 4203, 'author_profile': 'https://Stackoverflow.com/users/4203', 'pm_score': 1, 'selected': False, 'text': "<p>Couldn't you just use a client certificate (signed by you) and establish an HTTPS connection to your server, which has been configured to only accept connections begun with a client certificate signed by you?</p>\n"}, {'answer_id': 78688, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 0, 'selected': False, 'text': '<p>generate a random, something fairly long, then tack the score to the end, and maybe the name or something else static, then sha1/md5 it, and pass both to the server, verify that the random hashes, to be equal to the hash.</p>\n\n<p>After-thought: If you want to make it harder to reverse engenier, then multiply your random by the numerical representation of the day (monday=1, tuesday=2,...)</p>\n'}, {'answer_id': 78710, 'author': 'emk', 'author_id': 12089, 'author_profile': 'https://Stackoverflow.com/users/12089', 'pm_score': 1, 'selected': False, 'text': '<p>To make a long story <em>very</em> short, you\'re allowed to export digital signature code with very few restrictions. To learn more, <a href="http://www.bis.doc.gov/exportlicensingqanda.htm" rel="nofollow noreferrer">start at the BIS export FAQ</a>.</p>\n\n<p>You probably want to look at <a href="http://www.access.gpo.gov/bis/ear/pdf/742.pdf" rel="nofollow noreferrer">EAR 742.15(b)3</a>, which covers the digital signature exemptions.</p>\n\n<p>Of course, I Am Not A Lawyer, and the rules may have changed in the last year.</p>\n'}, {'answer_id': 90843, 'author': 'benzado', 'author_id': 10947, 'author_profile': 'https://Stackoverflow.com/users/10947', 'pm_score': 0, 'selected': False, 'text': "<p>One idea that might be Good Enough:</p>\n\n<ul>\n<li>Let Secret1, Secret2, Secret3 be any random strings.</li>\n<li>Let DeviceID be the iPhone's unique device ID.</li>\n<li>Let Hash(Foo + Bar) mean I concatenate Foo and Bar and then compute a hash.</li>\n</ul>\n\n<p>Then:</p>\n\n<ol>\n<li><p>The first time the app talks to the server, it makes a request for a DevicePassword. iPhone sends: DeviceID, Hash(DeviceID + Secret1)</p></li>\n<li><p>The server uses Secret1 to verify the request came from the app. If so, it generates a DevicePassword and saves the association between DeviceID and DevicePassword on the server.</p></li>\n<li><p>The server replies: DevicePassword, Hash(DevicePassword + Secret2)</p></li>\n<li><p>The app uses Secret2 to verify that the password came from the server. If so, it saves it.</p></li>\n<li><p>To submit a score, iPhone sends: DeviceID, Score, Hash(Score + DevicePassword + Secret3)</p></li>\n<li><p>The server verifies using Secret3 and the DevicePassword.</p></li>\n</ol>\n\n<p>The advantage of the DevicePassword is that each device effectively has a unique secret, and if I didn't know that it would make it harder to determine the secret by packet sniffing the submitted scores.</p>\n\n<p>Also, in normal cases the app should only request a DevicePassword once per install, so you could easily identify suspicious requests for a DevicePassword or simply limit it to once per day.</p>\n\n<p>Disclaimer: This solution is off the top of my head, so I can't guarantee there isn't a major flaw in this scheme.</p>\n"}, {'answer_id': 3989637, 'author': 'benzado', 'author_id': 10947, 'author_profile': 'https://Stackoverflow.com/users/10947', 'pm_score': 1, 'selected': False, 'text': '<p>Using real crypto won\'t actually buy you anything here. You basically have the reverse of the typical DRM problem. In that case, you want to prevent people from decrypting content, but they have to decrypt it to watch it, so you have to give them to key anyway.</p>\n\n<p>In your case, you want to prevent people from signing fake scores, but they have to be able to sign real scores, so you have to give them the key anyway.</p>\n\n<p>All you need to do is make sure your scheme requires more effort to crack than the potential rewards. Since we\'re talking about a game leader board, the stakes are not that high. Make it so that someone using tcpdump won\'t figure it out too quickly, and you should be fine. If your server is smart enough to detect "experimentation" (a lot of failed submissions from one source) you will be safer than relying on any cryptographic algorithm.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78599', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
78,619
<p>What is the fastest way you know to convert a floating-point number to an int on an x86 CPU. Preferrably in C or assembly (that can be in-lined in C) for any combination of the following:</p> <ul> <li>32/64/80-bit float -> 32/64-bit integer</li> </ul> <p>I'm looking for some technique that is faster than to just let the compiler do it.</p>
[{'answer_id': 78645, 'author': 'Dark Shikari', 'author_id': 11206, 'author_profile': 'https://Stackoverflow.com/users/11206', 'pm_score': 4, 'selected': False, 'text': '<p>Packed conversion using SSE is by far the fastest method, since you can convert multiple values in the same instruction. <a href="https://github.com/FFmpeg/FFmpeg" rel="nofollow noreferrer">ffmpeg</a> has a lot of assembly for this (mostly for converting the decoded output of audio to integer samples); check it for some examples.</p>\n'}, {'answer_id': 78655, 'author': 'dreamlax', 'author_id': 10320, 'author_profile': 'https://Stackoverflow.com/users/10320', 'pm_score': 3, 'selected': False, 'text': "<p>There is one instruction to convert a floating point to an int in assembly: use the FISTP instruction. It pops the value off the floating-point stack, converts it to an integer, and then stores at at the address specified. I don't think there would be a faster way (unless you use extended instruction sets like MMX or SSE, which I am not familiar with).</p>\n\n<p>Another instruction, FIST, leaves the value on the FP stack but I'm not sure it works with quad-word sized destinations.</p>\n"}, {'answer_id': 78668, 'author': 'Don Neufeld', 'author_id': 13097, 'author_profile': 'https://Stackoverflow.com/users/13097', 'pm_score': 2, 'selected': False, 'text': '<p>If you really care about the speed of this make sure your compiler is generating the FIST instruction. In MSVC you can do this with /QIfist, <a href="http://msdn.microsoft.com/en-us/library/6d9xx1d2.aspx" rel="nofollow noreferrer">see this MSDN overview</a></p>\n\n<p>You can also consider using SSE intrinsics to do the work for you, see this article from Intel: <a href="http://softwarecommunity.intel.com/articles/eng/2076.htm" rel="nofollow noreferrer">http://softwarecommunity.intel.com/articles/eng/2076.htm</a></p>\n'}, {'answer_id': 78681, 'author': 'Zach Burlingame', 'author_id': 2233, 'author_profile': 'https://Stackoverflow.com/users/2233', 'pm_score': 5, 'selected': True, 'text': '<p>It depends on if you want a truncating conversion or a rounding one and at what precision. By default, C will perform a truncating conversion when you go from float to int. There are FPU instructions that do it but it\'s not an ANSI C conversion and there are significant caveats to using it (such as knowing the FPU rounding state). Since the answer to your problem is quite complex and depends on some variables you haven\'t expressed, I recommend this article on the issue:</p>\n\n<p><a href="http://www.stereopsis.com/FPU.html" rel="noreferrer">http://www.stereopsis.com/FPU.html</a></p>\n'}, {'answer_id': 78687, 'author': 'user14504', 'author_id': 14504, 'author_profile': 'https://Stackoverflow.com/users/14504', 'pm_score': -1, 'selected': False, 'text': '<p>Generally, you can trust the compiler to be efficient and correct. There is usually nothing to be gained by rolling your own functions for something that already exists in the compiler.</p>\n'}, {'answer_id': 78820, 'author': 'akauppi', 'author_id': 14455, 'author_profile': 'https://Stackoverflow.com/users/14455', 'pm_score': 3, 'selected': False, 'text': "<p>The Lua code base has the following snippet to do this (check in src/luaconf.h from www.lua.org).\nIf you find (SO finds) a faster way, I'm sure they'd be thrilled.</p>\n\n<p>Oh, <code>lua_Number</code> means double. :)</p>\n\n<pre><code>/*\n@@ lua_number2int is a macro to convert lua_Number to int.\n@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.\n** CHANGE them if you know a faster way to convert a lua_Number to\n** int (with any rounding method and without throwing errors) in your\n** system. In Pentium machines, a naive typecast from double to int\n** in C is extremely slow, so any alternative is worth trying.\n*/\n\n/* On a Pentium, resort to a trick */\n#if defined(LUA_NUMBER_DOUBLE) &amp;&amp; !defined(LUA_ANSI) &amp;&amp; !defined(__SSE2__) &amp;&amp; \\\n (defined(__i386) || defined (_M_IX86) || defined(__i386__))\n\n/* On a Microsoft compiler, use assembler */\n#if defined(_MSC_VER)\n\n#define lua_number2int(i,d) __asm fld d __asm fistp i\n#define lua_number2integer(i,n) lua_number2int(i, n)\n\n/* the next trick should work on any Pentium, but sometimes clashes\n with a DirectX idiosyncrasy */\n#else\n\nunion luai_Cast { double l_d; long l_l; };\n#define lua_number2int(i,d) \\\n { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }\n#define lua_number2integer(i,n) lua_number2int(i, n)\n\n#endif\n\n/* this option always works, but may be slow */\n#else\n#define lua_number2int(i,d) ((i)=(int)(d))\n#define lua_number2integer(i,d) ((i)=(lua_Integer)(d))\n\n#endif\n</code></pre>\n"}, {'answer_id': 119538, 'author': 'Suma', 'author_id': 16673, 'author_profile': 'https://Stackoverflow.com/users/16673', 'pm_score': 3, 'selected': False, 'text': '<p>A commonly used trick for plain x86/x87 code is to force the mantissa part of the float to represent the int. 32 bit version follows.</p>\n\n<p>The 64-bit version is analogical. The Lua version posted above is faster, but relies on the truncation of double to a 32-bit result, therefore it requires the x87 unit to be set to double precision, and cannot be adapted for double to 64-bit int conversion.</p>\n\n<p>The nice thing about this code is it is completely portable for all platforms conforming to IEEE 754, the only assumption made is the floating point rounding mode is set to nearest. Note: Portable in the sense it compiles and works. Platforms other than x86 usually do not benefit much from this technique, if at all.</p>\n\n<pre><code>static const float Snapper=3&lt;&lt;22;\n\nunion UFloatInt {\n int i;\n float f;\n};\n\n/** by Vlad Kaipetsky\nportable assuming FP24 set to nearest rounding mode\nefficient on x86 platform\n*/\ninline int toInt( float fval )\n{\n Assert( fabs(fval)&lt;=0x003fffff ); // only 23 bit values handled\n UFloatInt &amp;fi = *(UFloatInt *)&amp;fval;\n fi.f += Snapper;\n return ( (fi.i)&amp;0x007fffff ) - 0x00400000;\n}\n</code></pre>\n'}, {'answer_id': 647671, 'author': 'akauppi', 'author_id': 14455, 'author_profile': 'https://Stackoverflow.com/users/14455', 'pm_score': 3, 'selected': False, 'text': '<p>If you can guarantee the CPU running your code is SSE3 compatible (even Pentium 5 is, JBB), you can allow the compiler to use its FISTTP instruction (i.e. -msse3 for gcc). It seems to do the thing like it should always have been done:</p>\n\n<p><a href="http://software.intel.com/en-us/articles/how-to-implement-the-fisttp-streaming-simd-extensions-3-instruction/" rel="noreferrer">http://software.intel.com/en-us/articles/how-to-implement-the-fisttp-streaming-simd-extensions-3-instruction/</a></p>\n\n<p>Note that FISTTP is different from FISTP (that has its problems, causing the slowness). It comes as part of SSE3 but is actually (the only) X87-side refinement.</p>\n\n<p>Other then X86 CPU\'s would probably do the conversion just fine, anyways. :)</p>\n\n<p><a href="http://en.wikipedia.org/wiki/SSE3#CPUs_with_SSE3" rel="noreferrer">Processors with SSE3 support</a></p>\n'}, {'answer_id': 16874325, 'author': 'Jan', 'author_id': 2016181, 'author_profile': 'https://Stackoverflow.com/users/2016181', 'pm_score': 2, 'selected': False, 'text': '<p>Since MS scews us out of inline assembly in X64 and forces us to use intrinsics, I looked up which to use. <a href="http://msdn.microsoft.com/en-us/library/shf1ys5b%28v=vs.90%29.aspx" rel="nofollow">MSDN doc</a> gives <code>_mm_cvtsd_si64x</code> with an example.</p>\n\n<p>The example works, but is horribly inefficient, using an unaligned load of 2 doubles, where we need just a single load, so getting rid of the additional alignment requirement. Then a lot of needless loads and reloads are produced, but they can be eliminated as follows:</p>\n\n<pre><code> #include &lt;intrin.h&gt;\n #pragma intrinsic(_mm_cvtsd_si64x)\n long long _inline double2int(const double &amp;d)\n {\n return _mm_cvtsd_si64x(*(__m128d*)&amp;d);\n }\n</code></pre>\n\n<p>Result:</p>\n\n<pre><code> i=double2int(d);\n000000013F651085 cvtsd2si rax,mmword ptr [rsp+38h] \n000000013F65108C mov qword ptr [rsp+28h],rax \n</code></pre>\n\n<p>The rounding mode can be set without inline assembly, e.g.</p>\n\n<pre><code> _control87(_RC_NEAR,_MCW_RC);\n</code></pre>\n\n<p>where rounding to nearest is default (anyway).</p>\n\n<p>The question whether to set the rounding mode at each call or to assume it will be restored (third party libs) will have to be answered by experience, I guess.\nYou will have to include <code>float.h</code> for <code>_control87()</code> and related constants.</p>\n\n<p>And, no, this will not work in 32 bits, so keep using the FISTP instruction:</p>\n\n<pre><code>_asm fld d\n_asm fistp i\n</code></pre>\n'}, {'answer_id': 22048816, 'author': 'the swine', 'author_id': 1140976, 'author_profile': 'https://Stackoverflow.com/users/1140976', 'pm_score': 3, 'selected': False, 'text': '<p>I assume truncation is required, same as if one writes <code>i = (int)f</code> in "C".</p>\n\n<p>If you have SSE3, you can use:</p>\n\n<pre><code>int convert(float x)\n{\n int n;\n __asm {\n fld x\n fisttp n // the extra \'t\' means truncate\n }\n return n;\n}\n</code></pre>\n\n<p>Alternately, with SSE2 (or in x64 where inline assembly might not be available), you can use almost as fast:</p>\n\n<pre><code>#include &lt;xmmintrin.h&gt;\nint convert(float x)\n{\n return _mm_cvtt_ss2si(_mm_load_ss(&amp;x)); // extra \'t\' means truncate\n}\n</code></pre>\n\n<p>On older computers there is an option to set the rounding mode manually and perform conversion using the ordinary <code>fistp</code> instruction. That will probably only work for arrays of floats, otherwise care must be taken to not use any constructs that would make the compiler change rounding mode (such as casting). It is done like this:</p>\n\n<pre><code>void Set_Trunc()\n{\n // cw is a 16-bit register [_ _ _ ic rc1 rc0 pc1 pc0 iem _ pm um om zm dm im]\n __asm {\n push ax // use stack to store the control word\n fnstcw word ptr [esp]\n fwait // needed to make sure the control word is there\n mov ax, word ptr [esp] // or pop ax ...\n or ax, 0xc00 // set both rc bits (alternately "or ah, 0xc")\n mov word ptr [esp], ax // ... and push ax\n fldcw word ptr [esp]\n pop ax\n }\n}\n\nvoid convertArray(int *dest, const float *src, int n)\n{\n Set_Trunc();\n __asm {\n mov eax, src\n mov edx, dest\n mov ecx, n // load loop variables\n\n cmp ecx, 0\n je bottom // handle zero-length arrays\n\n top:\n fld dword ptr [eax]\n fistp dword ptr [edx]\n loop top // decrement ecx, jump to top\n bottom:\n }\n}\n</code></pre>\n\n<p>Note that the inline assembly only works with Microsoft\'s Visual Studio compilers (and maybe Borland), it would have to be rewritten to GNU assembly in order to compile with gcc.\nThe SSE2 solution with intrinsics should be quite portable, however.</p>\n\n<p>Other rounding modes are possible by different SSE2 intrinsics or by manually setting the FPU control word to a different rounding mode.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78619', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10184/']
78,626
<p>I'm starting work on a program which is perhaps most naturally described as a batch of calculations on database tables, and will be executed once a month. All input is in Oracle database tables, and all output will be to Oracle database tables. The program should stay maintainable for many years to come.</p> <p>It seems straight-forward to implement this as a series of stored procedures, each performing a sensible transformation, for example distributing costs among departments according to some business rules. I can then write unit tests to check if the output of each transformation is as I expected.</p> <p>Is it a bad idea to do this all in PL/SQL? Would you rather do heavy batch calculations in a typical object oriented programming language, such as C#? Isn't it more expressive to use a database centric programming language such as PL/SQL?</p>
[{'answer_id': 78646, 'author': 'user13276', 'author_id': 13276, 'author_profile': 'https://Stackoverflow.com/users/13276', 'pm_score': 3, 'selected': True, 'text': '<p>Normally I say put as little in PL/SQL as possible - it is typically a lot less maintainable - at one of my last jobs I really saw how messy and hard to work with it could get. </p>\n\n<p>However, since it is batch processing - and since the input and output are both the DB - it makes good sense to put the logic into PL/SQL - to minimize "moving parts". However, if it were business logic - or components used by other pieces of your system - I would say don\'t do it.. </p>\n'}, {'answer_id': 78651, 'author': 'Craig Trader', 'author_id': 12895, 'author_profile': 'https://Stackoverflow.com/users/12895', 'pm_score': 2, 'selected': False, 'text': "<p>As long as the calculations you need to perform can be adequately AND readably captured in PL/SQL, then using only PL/SQL would make the most sense.</p>\n\n<p>The real catch is maintainability -- it's very easy to write unmaintainable SQL, if only because every RDBMS has a different syntax and different function set once you step outside of simple SQL DML, and no real standards for formatting. commenting, etc.</p>\n"}, {'answer_id': 78656, 'author': 'Vinko Vrsalovic', 'author_id': 5190, 'author_profile': 'https://Stackoverflow.com/users/5190', 'pm_score': 0, 'selected': False, 'text': "<p>It's not usually more expressive because most stored procedure languages suck by design. But it will probably run faster than in an external app.</p>\n\n<p>I guess it boils down to how familiar you are with PL/SQL, how much time you have to write this, how important is performance and if you can reasonably expect maintainers to be familiar enough with PL/SQL to maintain a big program written in it.</p>\n\n<p>If speed is not relevant and maintainers will probably be not PL/SQL proficient, you might be better using a 'traditional' language.</p>\n\n<p>You could also use a hybrid approach, where you use PL/SQL to generate intermediate data (say, table joins and sums or whatever) and a separate application to control flow and check values and errors.</p>\n"}, {'answer_id': 78666, 'author': 'Joe Skora', 'author_id': 14057, 'author_profile': 'https://Stackoverflow.com/users/14057', 'pm_score': 3, 'selected': False, 'text': "<p>No, it isn't necessarily a bad idea. If the solution seems straightforward to you and allows you to test and verify each process, its sounds like it could be a good idea. OO platforms can be (though they don't have to be) bad for large data sets, as object creation and overhead can kill performance.</p>\n\n<p>Oracle designed PL/SQL with problems like yours in mind, if there is sufficient corporate knowledge of the database and PL/SQL this seems like a reasonable solution. Keep large batch sets in mind, as each call from PL/SQL to the actual SQL engine is a context switch, so single record processes should be batched together where possible to improve performance.</p>\n"}, {'answer_id': 78686, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>This is a loaded question :)\nThere\'s a couple of database programming architecture designs you should know of, and what their costs/benefits are.\n2 Tier generally means you have a client connecting to a DB, issuing direct SQL calls.\n3 Tier generally means you have an "application server" that is issuing direct SQL calls to the DB, but the client is talking to the app server. Generally, this affords "scaling out".\nFinally, you have 2 1/2 tiered apps that employ a 2 Tier like format, only the work is compartmentalized within stored procedures.</p>\n\n<p>Your process sounds like a "back office" kind of thing, and clients/processes just need results that are being aggregated and cached on a once a month basis.\nThat is, there is no agent that connects, and connects often, and says "do these calculations". Instead you allude to a process that happens once in a while, and you can get away with non-real time.</p>\n\n<p>Therefore, given those requirements, I\'d say that generally, it will be faster to be closer to the data, and let SQL server do all the calculations.\nI think you\'ll find that proximity to the data will serve you well.</p>\n\n<p>However, in performing these calculations, you may find that some calculations are not amenable to SQL Servers. Take for example calculating the accrued interest of a bond, or any fixed income instrument. Not very pretty in SQL, and much more suited for a richer programming language. However, if you just have simple averages and other relatively sane aggregates, I\'d stick to stored procedures, on the SQL side. </p>\n\n<p>So again, there\'s not enough information as to the nature of your calculations, or what your house mandates in terms of SQL capabilities of devs for support, or what your boss says...but since I know my way around SQL, and like to stay close to the data, I\'d stay pure SQL/Stored Procedures for a task like this.</p>\n\n<p>YMMV :)</p>\n'}, {'answer_id': 78694, 'author': 'Mashed Potato', 'author_id': 14396, 'author_profile': 'https://Stackoverflow.com/users/14396', 'pm_score': 2, 'selected': False, 'text': "<p>I've created batch programs using C# and SQL.</p>\n<p>Pros of C#:</p>\n<ul>\n<li>You've got the full library of .NET and all the power of an OO\nlanguage.</li>\n</ul>\n<p>Cons of C#:</p>\n<ul>\n<li>Batch program and db separate - this means, you'll have to manage your batch program separate from the database.</li>\n<li>You need to escape all that dang sql code</li>\n</ul>\n<p>Pros of SQL:</p>\n<ul>\n<li>Integrates nicely with the DBMS. If this job only manipulates the database, it would make sense to include it with the database. You end up with a single db and all of its components in one package.</li>\n<li>No need to escape sql code</li>\n<li>keeping it real - you are programming in your problem domain</li>\n</ul>\n<p>Cons of SQL:</p>\n<ul>\n<li>Its SQL and I personally just don't know it as well as C#.</li>\n</ul>\n<p>In general, I would stick with using SQL because of the Pros outlined above.</p>\n"}, {'answer_id': 78914, 'author': 'Evan', 'author_id': 6277, 'author_profile': 'https://Stackoverflow.com/users/6277', 'pm_score': 2, 'selected': False, 'text': '<p>I wrote a huge amount of batch processing and report generation programs in both PL/SQL and Pro<em>C for one project. They generally preferred I write in PL/SQL as their own developers who would maintain in the future found that easier to understand than Pro</em>C code.</p>\n\n<p>It ended up being only the really funky processing or reports that ended up being written in Pro*C.</p>\n\n<p>It is not necessary to write these as stored procedures as other people have alluded to, they can be just script files that are run as necessary, kind of like a shell script. Make source code revision control and migration between test and production systems a heck of a lot easier, too.</p>\n'}, {'answer_id': 79586, 'author': 'Milan Babuškov', 'author_id': 14690, 'author_profile': 'https://Stackoverflow.com/users/14690', 'pm_score': 2, 'selected': False, 'text': "<p>Just make sure you somehow log what is happening while it's working. Otherwise you'll have a black box and if it gets stuck somewhere for hours, you'll be wondering whether to stop it or let it work 'a little bit more'. </p>\n"}, {'answer_id': 84645, 'author': 'Mike McAllister', 'author_id': 16247, 'author_profile': 'https://Stackoverflow.com/users/16247', 'pm_score': 3, 'selected': False, 'text': "<p>Something for other commenters to note - the question is about PL/SQL, not about SQL. Some of the answers have obviously been about SQL, not PL/SQL. PL/SQL is a fully functional database language, and it's mature as well. There are some shortcomings, but for the type of thing the poster wants to do, it's very good.</p>\n"}, {'answer_id': 88721, 'author': 'Sergey Stadnik', 'author_id': 10557, 'author_profile': 'https://Stackoverflow.com/users/10557', 'pm_score': 2, 'selected': False, 'text': '<p>PL/SQL is a mature language that integrates well with SQL. With each version of Oracle it becomes more and more powerful.\nAlso starting from Oracle 11, PL/SQL compiles to machine code by default.</p>\n'}, {'answer_id': 91953, 'author': 'mathewbutler', 'author_id': 2288, 'author_profile': 'https://Stackoverflow.com/users/2288', 'pm_score': 3, 'selected': False, 'text': "<p>You describe the following requirements</p>\n\n<p>a) Must be able to implement Batch Processing\nb) Result must be maintainable</p>\n\n<p>My Response:</p>\n\n<ol>\n<li>PL/SQL was designed to achieve just what you describe. It's also important to note that there are efficiencies in PL/SQL that are not available in other tools. An stored procedure language put the processing next to the data - which is where batch processing ought to sit.</li>\n<li>It easy enough to write poorly maintainable code in any language.</li>\n</ol>\n\n<p>Having said the above, your implementation will depend on the available skills, a proper design and adherence to good quality processes.</p>\n\n<p>To be efficient your implementation must process data in batches ( select in batches and insert/update in batches ). The danger with an OO approach is that it is easy to be led towards a design that processes data row by row. This type of approach contains unnecessary overhead, and will be significantly less efficient than a design that processes data in batches of rows.</p>\n\n<p>It is possible to use both approaches successfully.</p>\n\n<p>Mathew Butler</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/78626', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9754/']
78,641
<p>I'm looking for a good 3D Mesh library</p> <ul> <li>Should be able to read popular formats (OFF, OBJ...)</li> <li>Should support both half-edge structure and a triangle soup</li> <li>Should be tolerant to faults and illegal meshes.</li> <li>Basic geometric operations - intersections, normal calculation, etc'</li> <li>Most importantly - Should not be convoluted with endless template and inheritance hierarchies.</li> </ul> <p>I've tried both CGAL and OpenMesh but both fail miserably in the last point.</p> <p>Specifically CGAL which is impossible to follow even with the most advanced code analysis tools.</p> <p>So far I'm seriously considering to pull my own.</p> <p>My preference is C++ but I'm open to other options.</p>
[{'answer_id': 78746, 'author': 'HappyDude', 'author_id': 14266, 'author_profile': 'https://Stackoverflow.com/users/14266', 'pm_score': 4, 'selected': False, 'text': '<p>May I ask why the last point is a requirement?</p>\n\n<p>Libraries written for public consumption are designed to be as generic as possible so that it is usable by the widest possible audience. In C++, this is often best done using templates. It would suck tremendously if found a good library, only to discover it was useless for your purposes because it used floats instead of doubles.</p>\n\n<p>CGAL, for example, appears to have adopted the well-known and well-tested STL paradigm of writing generic and extensible C++ libraries. This does indeed make it difficult to follow with code analysis tools; I doubt they\'re much good at following STL headers either.</p>\n\n<p>But are you trying to use the library or modify it? Either way, they seem to have some extremely high-quality documentation (e.g. <a href="http://www.cgal.org/Manual/3.3/doc_html/cgal_manual/Kernel_23/Chapter_main.html" rel="noreferrer">Kernel Manual</a>) that should make it relatively simple to figure out what you need to do, without having to resort to reading their code.</p>\n\n<p>Disclaimer: I know this isn\'t what you\'re asking for. But I don\'t think what you\'re looking for exists. It is <strong>extraordinarily</strong> rare to find open source code with documentation as good as what I\'ve seen scanning through CGAL. I would strongly suggest that you take another look at it.</p>\n'}, {'answer_id': 88895, 'author': 'Camille', 'author_id': 16990, 'author_profile': 'https://Stackoverflow.com/users/16990', 'pm_score': 2, 'selected': False, 'text': '<p>First, some general comments about you requirements:</p>\n\n<ul>\n<li>reading OBJ or OFF files is very easy. You could implement it yourself, on top of a library providing the more geometric features, in a few minutes. On the other hand, the geometric part of such libraries is so much more tricky that you should certainly focus on your requirements which really deal with the geometric algorithms, and try to find something which suits your needs. Then, of course, if there is a tie, start considering this interface issue.</li>\n<li>in terms of geometric operations, you ask for intersection. Do you mean primitives intersection ? (for which good and simple algorithms can be found and implemented) or computation of the intersection of two meshes ? or collision detection ? (which are delicate questions, with no simple answer)</li>\n<li>if you are more specific, from a higher level point of view, about the kind of tools you want to build, then people will be able to direct you to the right tool. Your requirements are too low-level.</li>\n</ul>\n\n<p>As far as I understand your question, it seems to me that you do not clearly see the point of libraries like CGAL and OpenMesh. Such libraries may not provide all the higher level tools you need, but their aim is to provide you (especially in the CGAL case) all the geometric framework upon which you can build a geometric application. Such geometric frameworks are very delicate to design, especially because of the robustness issue, which is very specific to computational geometry. And without such a framework, building a robust application is an horrendous effort.</p>\n\n<p>If you do not find a library which suits your need, you should seriously consider using a library such as CGAL as the underlying framework for your development. It will prevent the appearance of the robustness related problems, that you will typically only start noticing late in your development process, when changing the underlying framework will be painful. As an aside, CGAL has an extensive documentation, and a very active users\' mailing-list.</p>\n\n<p>If you do not know about robustness issues in geometry software, have a look at this page:\n<a href="http://www.mpi-inf.mpg.de/departments/d1/ClassroomExamples/" rel="nofollow noreferrer">robustness issues</a></p>\n'}, {'answer_id': 11021095, 'author': 'David', 'author_id': 1454439, 'author_profile': 'https://Stackoverflow.com/users/1454439', 'pm_score': 0, 'selected': False, 'text': '<p>I don\'t know if it can be useful for you. There is also another library, which is called the Mangrove TDS Library, freely available at <a href="http://mangrovetds.sourceforge.net" rel="nofollow">http://mangrovetds.sourceforge.net</a> It supports any type of shapes (2d, 3d, any dimension), with any domains (manifold, non-manifold, pseudo-manifolds, iqm complexes, simplicial complexes, and so on). It possibly supports non-regular shapes, i.e., formed by pieces of different dimensionalities.</p>\n\n<p>Its main property is that it is extensible, in the sense that any topological data structure is supported. It is a plugin, which can be changed and loaded at run-time.</p>\n\n<p>Its implementation is based on the array-based indexing of entities, encoded in a data structure, supporting iterators. It also supports dynamic properties.</p>\n\n<p>Finally, it supports an implicit representation of entities not directly encoded in a data structure (ghost entities), which improve efficiency of topological queries</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78641', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9611/']
78,669
<p>After installing VS2008, the platform builder mod, and the WM7 aku, VS usually prompts you, upon first startup, for your default mode. If you make a mistake and select something other than PB7, how do you get back into PB mode?</p> <p>I can get the device window, but it is always greyed out. I can also configure my normal connection settings, but VS will never connect to the device.</p> <p>I have other machines, where I did select the default option correctly. They work just fine.</p> <p>I'm hoping I do not have to reinstall everything.</p> <p>namaste, Mark</p>
[{'answer_id': 78701, 'author': 'Vijay', 'author_id': 14523, 'author_profile': 'https://Stackoverflow.com/users/14523', 'pm_score': 3, 'selected': True, 'text': '<p>Go to the Tool menu and select "Import and Export Settings..." option. Then select "Reset all settings" in the Wizard. On the next screen you can save current settings. Then on the final screen, it should allow you to select which collection of settings you want to use. I don\'t have platform builder but hopefully that option should show up there.</p>\n'}, {'answer_id': 78709, 'author': 'Nescio', 'author_id': 14484, 'author_profile': 'https://Stackoverflow.com/users/14484', 'pm_score': 1, 'selected': False, 'text': "<p>Tools > Import and Export Settings...\nX Reset All Settings\n(Save or don't save)\nSelect new Setting.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/78669', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14424/']
78,696
<p>I'm trying to find out if there is any way to elevate a specific function within an application. For example, I have an app with system and user settings that are stored in the registry, I only need elevation for when the system settings need to be changed. </p> <p>Unfortunately all of the info I've come across talks about only starting a new process with elevated privileges. </p>
[{'answer_id': 78707, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 3, 'selected': True, 'text': '<p>What you really need to do is store your settings the Application Data folder.</p>\n'}, {'answer_id': 78734, 'author': 'Bryant', 'author_id': 10893, 'author_profile': 'https://Stackoverflow.com/users/10893', 'pm_score': 2, 'selected': False, 'text': '<p>Found a <a href="http://msdn.microsoft.com/en-us/magazine/cc163486.aspx" rel="nofollow noreferrer">nice article that covers this here</a>:</p>\n\n<blockquote>\n <p>Most applications do not require administrator privileges at run time. If your application doesn\'t maintain cross-session state while it executes and doesn\'t do something like modifying the local security policy, it should be just fine running with a standard-user token. Sometimes certain parts of your application will require administrator privileges, and you should separate out those pieces into a separate process. I\'ll get into that a little later. </p>\n</blockquote>\n\n<p>Looks like the article is talking about using C++, so I found <a href="http://buildingsecurecode.blogspot.com/2007/06/how-to-display-uac-shield-icon-inside.html" rel="nofollow noreferrer">another article</a> that covers how to call this code using P/Invoke. So should be doable from .NET.</p>\n'}, {'answer_id': 78773, 'author': 'uzbones', 'author_id': 14551, 'author_profile': 'https://Stackoverflow.com/users/14551', 'pm_score': 3, 'selected': False, 'text': '<p>The best article I have seen is this one:</p>\n\n<p><a href="http://www.codeproject.com/KB/vista-security/UAC__The_Definitive_Guide.aspx" rel="noreferrer">http://www.codeproject.com/KB/vista-security/UAC__The_Definitive_Guide.aspx</a></p>\n\n<p>It explains down to the nitty gritty of whats going on behind the scenes when existing microsoft applications are bringing up the UAC prompt, and a bit of how to do it yourself, or at least you will know what your up against to make it work...</p>\n\n<p>(note the examples he shows are managed c++)</p>\n'}, {'answer_id': 93379, 'author': 'Andrei Belogortseff', 'author_id': 17037, 'author_profile': 'https://Stackoverflow.com/users/17037', 'pm_score': 4, 'selected': False, 'text': '<p>It is impossible to elevate just one function or any other part of a single process, because the elevation level is a per-process attribute. Just like with pregnancy, your process can either be elevated or not. If you need some part of your code to be running elevated, you must start a separate process.</p>\n\n<p>However, if you can implement your function as a COM object, you can run it elevated indirectly, by creating an elevated COM object, like this: </p>\n\n<pre><code>HRESULT \nCreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv)\n{\n WCHAR monikerName[1024];\n WCHAR clsid[1024];\n BIND_OPTS3 bo;\n\n StringFromGUID2 (guid, clsid, sizeof (clsid) / 2);\n\n swprintf_s (monikerName, sizeof (monikerName) / 2, L"Elevation:Administrator!new:%s", clsid);\n\n memset (&amp;bo, 0, sizeof (bo));\n bo.cbStruct = sizeof (bo);\n bo.hwnd = hwnd;\n bo.dwClassContext = CLSCTX_LOCAL_SERVER;\n\n // Prevent the GUI from being half-rendered when the UAC prompt "freezes" it\n MSG paintMsg;\n int MsgCounter = 5000; // Avoid endless processing of paint messages\n while (PeekMessage (&amp;paintMsg, hwnd, 0, 0, PM_REMOVE | PM_QS_PAINT) != 0 &amp;&amp; --MsgCounter &gt; 0)\n {\n DispatchMessage (&amp;paintMsg);\n }\n\n return CoGetObject (monikerName, &amp;bo, iid, ppv);\n}\n</code></pre>\n'}, {'answer_id': 114714, 'author': 'Adrian Clark', 'author_id': 148, 'author_profile': 'https://Stackoverflow.com/users/148', 'pm_score': 2, 'selected': False, 'text': '<p>The Windows SDK "Cross Technology Samples" have a "UACDemo" application which shows examples of a C# Windows Forms application which launches an administrator process to perform a task which requires elevation (i.e. writing to <code>%programfiles%</code>).</p>\n\n<p>This is a great starting point for writing your own functionality. I\'ve extended this sample to use .Net Remoting and IPC to call between my normal user process and my elevated process which allows me to keep the elevation executable generic and implement application-specific code within the application.</p>\n'}, {'answer_id': 425114, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I think Aydsman is on the right track here. With the addition of Named Pipes support to .NET 3.5, you have a decent IPC mechanism for communicating with an elevated child process.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78696', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14509/']
78,700
<p>I'm using KVM to run a Windows virtual machine on my Linux box. Networking is accomplished through a tap device, hooked into a bridged Ethernet device, which allows the Windows VM to basically appear like a separate physical computer on my network. This is pretty nice.</p> <p>However, my understanding is that most, if not all, wireless drivers can't support bridging. I'd really like to be able to roam a little more freely while I'm working -- does anyone know of an effective workaround?</p> <p>User-mode networking won't work, as I have to use some Windows VPN software that wants lower-level networking access.</p>
[{'answer_id': 78729, 'author': 'Jan Krüger', 'author_id': 12471, 'author_profile': 'https://Stackoverflow.com/users/12471', 'pm_score': 2, 'selected': False, 'text': '<p>I assume that you could configure your Windows guest to use the host as its default gateway, and set up NAT via the wireless interface on the host. So the signal flow would look like this:</p>\n\n<ol>\n<li>Windows software opens connections to a host on the internets.</li>\n<li>Windows routes the packet via the default gateway, i.e. the host Linux system.</li>\n<li>Linux does NAT magic and routes the packet via its normal routing table (which should use a default gateway via the wireless interface).</li>\n</ol>\n\n<p>I have never tried this in combination with bridging though.</p>\n'}, {'answer_id': 12164264, 'author': 'auspicacious', 'author_id': 14487, 'author_profile': 'https://Stackoverflow.com/users/14487', 'pm_score': 1, 'selected': True, 'text': '<p>Other, related questions <a href="https://stackoverflow.com/questions/10527780/how-to-set-up-bridged-networking-for-kvm-using-ubuntu-12-04">like this one</a> seem to indicate it is simply a limitation of many wireless drivers. There are a few for Linux that will do bridging, but one would have to plan to build that into their system from day one.</p>\n'}, {'answer_id': 18074071, 'author': 'aholbreich', 'author_id': 504913, 'author_profile': 'https://Stackoverflow.com/users/504913', 'pm_score': 0, 'selected': False, 'text': '<p>Why it should be a problem to setup host linux system to use WLAN and then us this connection as default gateway for local/internal bridge and all VMs are pluged into it? Ok, simple NAT has to be configured but what ist actually the point?</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78700', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14487/']
78,703
<p>Does any know of a good calendar (not datepicker, but a BIG browsable calendar) plugin for one of the major javascript frameworks. I'd prefer jQuery.</p>
[{'answer_id': 78738, 'author': 'patrickyoung', 'author_id': 3701, 'author_profile': 'https://Stackoverflow.com/users/3701', 'pm_score': 2, 'selected': False, 'text': '<p>You might want to send the guys at <a href="http://tedserbinski.com/jcalendar/index.html#about" rel="nofollow noreferrer">jCalendar</a> a note. They were working on a Google Calendar-like jQuery plugin. Project seems to have moved on, but they may be able to point you in the right direction.</p>\n\n<p>From their site:</p>\n\n<blockquote>\n <p>Coming soon will be v1.0, which will allow for not only visually selecting dates but also for displaying them in both mini and full page calendar views, similar to that of Google Calendar.</p>\n</blockquote>\n'}, {'answer_id': 344976, 'author': 'IEnumerator', 'author_id': 34819, 'author_profile': 'https://Stackoverflow.com/users/34819', 'pm_score': 2, 'selected': False, 'text': '<p>i think you will like the following:</p>\n\n<p><a href="http://www.filamentgroup.com/examples/daterangepicker/" rel="nofollow noreferrer">Date Range Picker</a></p>\n\n<p>vote it if you like it</p>\n'}, {'answer_id': 792025, 'author': 'arshaw', 'author_id': 96342, 'author_profile': 'https://Stackoverflow.com/users/96342', 'pm_score': 7, 'selected': True, 'text': '<p>just published a new open source project (jQuery plugin). sounds exactly like what you want:</p>\n\n<p><a href="http://arshaw.com/fullcalendar/" rel="noreferrer">FullCalendar</a></p>\n\n<p>Hope it works well for you!</p>\n'}, {'answer_id': 1102939, 'author': 'Elzo Valugi', 'author_id': 95353, 'author_profile': 'https://Stackoverflow.com/users/95353', 'pm_score': 3, 'selected': False, 'text': '<p>I prefer <a href="http://eyecon.ro/datepicker/" rel="noreferrer">Eyecon Calendar.</a> Maybe the best.</p>\n'}, {'answer_id': 1454852, 'author': 'JuanZe', 'author_id': 166611, 'author_profile': 'https://Stackoverflow.com/users/166611', 'pm_score': 2, 'selected': False, 'text': '<p>Useful Calendar &amp; Date Picker Scripts For Web Developers: </p>\n\n<p><a href="http://www.hongkiat.com/blog/useful-calendar-date-picker-scripts-for-web-developers/" rel="nofollow noreferrer">http://www.hongkiat.com/blog/useful-calendar-date-picker-scripts-for-web-developers/</a></p>\n'}, {'answer_id': 1753016, 'author': 'Philip Schlump', 'author_id': 213383, 'author_profile': 'https://Stackoverflow.com/users/213383', 'pm_score': 0, 'selected': False, 'text': '<p>I have successfully used <a href="http://www.stefanoverna.com/log/create-astonishing-ical-like-calendars-with-jquery" rel="nofollow noreferrer">http://www.stefanoverna.com/log/create-astonishing-ical-like-calendars-with-jquery</a></p>\n'}, {'answer_id': 3029190, 'author': 'Dilbert', 'author_id': 365295, 'author_profile': 'https://Stackoverflow.com/users/365295', 'pm_score': 1, 'selected': False, 'text': '<p>Here is one I put together. It looks and works like Google Calendar.</p>\n\n<p><a href="http://code.google.com/p/jquery-frontier-calendar/" rel="nofollow noreferrer">http://code.google.com/p/jquery-frontier-calendar/</a></p>\n'}, {'answer_id': 3598145, 'author': 'Ashu', 'author_id': 432594, 'author_profile': 'https://Stackoverflow.com/users/432594', 'pm_score': 2, 'selected': False, 'text': '<p>Checkout <a href="http://keith-wood.name/datepick.html" rel="nofollow noreferrer">http://keith-wood.name/datepick.html</a></p>\n\n<p>This is quite good resource for jQuery Calendar implemenation</p>\n'}, {'answer_id': 3797147, 'author': 'bobo', 'author_id': 458622, 'author_profile': 'https://Stackoverflow.com/users/458622', 'pm_score': 2, 'selected': False, 'text': '<p>why not try this jquery event calendar <a href="http://www.web-delicious.com/jquery-plugins/" rel="nofollow">http://www.web-delicious.com/jquery-plugins/</a>. This is amazing.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78703', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14521/']
78,716
<p>A while ago, I started on a project where I designed a html-esque XML schema so that authors could write their content (educational course material) in a simplified format which would then be transformed into HTML via XSLT. I played around (struggled) with it for a while and got it to a very basic level but then was too annoyed by the limitations I was encountering (which may well have been limitations of my knowledge) and when I read a blog suggesting to ditch XSLT and just write your own XML-to-whatever parser in your language of choice, I eagerly jumped onto that and it's worked out brilliantly.</p> <p>I'm still working on it to this day (<em>I'm actually supposed to be working on it right now, instead of playing on SO</em>), and I am seeing more and more things which make me think that the decision to ditch XSLT was a good one.</p> <p>I know that XSLT has its place, in that it is an accepted standard, and that if everyone is writing their own interpreters, 90% of them will end up on <a href="http://thedailywtf.com" rel="noreferrer">TheDailyWTF</a>. But given that it is a <a href="http://en.wikipedia.org/wiki/Functional_programming" rel="noreferrer">functional style language</a> instead of the procedural style which most programmers are familiar with, for someone embarking on a project such as my own, <strong>would you recommend they go down the path that I did, or stick it out with XSLT</strong>?</p>
[{'answer_id': 78736, 'author': 'Eric Schoonover', 'author_id': 3957, 'author_profile': 'https://Stackoverflow.com/users/3957', 'pm_score': 2, 'selected': False, 'text': '<p>The <a href="http://www.w3.org/TR/xslt" rel="nofollow noreferrer">XSLT specification</a> defines XSLT as "a language for transforming XML documents into other XML documents". If you are trying to do any thing but the most basic data processing within XSLT there are probably better solutions.</p>\n\n<p>Also worth noting that the data processing capabilities of XSLT can be extended in .NET using custom extension functions:</p>\n\n<ul>\n<li><a href="http://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltargumentlist.addextensionobject.aspx" rel="nofollow noreferrer">MSDN Documentation</a></li>\n<li><a href="http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=64" rel="nofollow noreferrer">CSharpFriends: Tutorial</a></li>\n</ul>\n'}, {'answer_id': 78747, 'author': 'Tom Martin', 'author_id': 5303, 'author_profile': 'https://Stackoverflow.com/users/5303', 'pm_score': 2, 'selected': False, 'text': '<p>I still believe that XSLT can be useful but it is an ugly language and can lead to an awful unreadable, unmaintainable mess. Partly because XML is not human readable enough to make up a "language" and partly because XSLT is stuck somewhere between being declarative and procedural. Having said that, and I think a comparison can be drawn with regular expressions, it has it\'s uses when it comes to simple well defined problems.</p>\n\n<p>Using the alternative approach and parsing XML in code can be equally nasty and you really want to employ some kind of XML marshalling/binding technology (such as JiBX in Java) that will convert your XML straight to an object.</p>\n'}, {'answer_id': 78748, 'author': 'Tom Leys', 'author_id': 11440, 'author_profile': 'https://Stackoverflow.com/users/11440', 'pm_score': 3, 'selected': False, 'text': "<p>Personally I used XSLT in a totally different context. The computer game that I was working on at the time used tons of UI pages defined using XML. During a major refactor shortly after a release we wanted to change the structure of these XML documents. We made the game's input format follow a much better and schema aware structure.</p>\n\n<p>XSLT seemed the perfect choice for this translation from old format -> New format. Within two weeks I had a working conversion from old to new for our hundreds of pages. I was also able to use it to extract lots of information on the layout of our UI pages. I created lists of which components were imbedded in which relatively easily which I then used XSLT to write into our schema definitions.</p>\n\n<p>Also, coming from a C++ background, it was a very fun and interesting language to master.</p>\n\n<p>I think that as a tool to translate XML from one format to another it is fantastic. However, it is not the only way to define an algorithm that takes XML as an input and outputs <em>Something</em>. If your algorithm is sufficiently complex, the fact that the input is XML becomes irrelevant to your choice of tool - i.e roll your own in C++ / Python / whatever.</p>\n\n<p>Specific to your example, I would imagine the best idea would be to create your own XML->XML convert that follows your business logic. Next, write a XSLT translator that just knows about formatting and does nothing clever. That might be a nice middle ground but it totally depends what you are doing. Having a XSLT translator on the output makes it easier to create alternative output formats - printable, for mobiles, etc.</p>\n"}, {'answer_id': 78761, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>XSLT is not the end-all be-all of xml transformation. However, it's very difficult to judge based on the information given if it would have been the best solution to your problem or if there are other more efficient and maintainable approaches. You say the authors could enter their content in a simplified format - what format? Text boxes? What kind of html were you converting it to?\nTo judge whether XSLT is the right tool for the job, it would help to know the features of this transformation in more detail.</p>\n"}, {'answer_id': 78763, 'author': 'Jason Jackson', 'author_id': 13103, 'author_profile': 'https://Stackoverflow.com/users/13103', 'pm_score': 1, 'selected': False, 'text': '<p>I have spent a lot of time in XSLT and found that while it is a useful tool in some situations, it is definitely not a fix all. It works very well for B2B purposes when it is used for data translation for machine-readable XML input/output. I don\'t think you are on the wrong track in your statement of its limitations. One of the things that frustrated me the most were the nuances in the implementations of XSLT. </p>\n\n<p>Perhaps you should look at some of the other markup languages available. I believe Jeff did an article about this very topic concerning Stack Overflow.</p>\n\n<p><a href="http://www.codinghorror.com/blog/archives/001116.html" rel="nofollow noreferrer">Is HTML a Humane Markup Language?</a></p>\n\n<p>I would take a look at what he wrote. You can probably find a software package that does what you want "out of the box", or at least very close instead of writing your own stuff from the ground up.</p>\n'}, {'answer_id': 78786, 'author': 'Mike Tunnicliffe', 'author_id': 13956, 'author_profile': 'https://Stackoverflow.com/users/13956', 'pm_score': 0, 'selected': False, 'text': '<p>I too have made forays into the world of XSLT and I found it to be a little awkward in places. I think my main issue was in the difficulty in converting "pure data" XML into a complete HTML page. In hindsight, perhaps using XSLT to generate a page fragment that could be composed together with other fragments using Server Side Scripting (eg SSI) would have solved many of my issues.</p>\n\n<p>One of the possible mistakes was to try and construct a common page layout to surround my data by importing XHTML or other XML data in using the document() function.</p>\n\n<p>The other mistake was trying to do programatic things like create a general template to generate tables on XML data with logic that did things like use different background row colours for rows with certain values and allow you to specify some columns to be filtered out. </p>\n\n<p>Not to mention trying to construct a string list of values from XML data that seemed only to be solvable using recursive template calls.</p>\n\n<p>What did I gain? Well, the page source is XML data right there and available to the viewer. Data and presentation are neatly separated.</p>\n\n<p>Would I do it again? Probably not, unless I really wanted data/presentation separation on a <strong>static</strong> page. Otherwise, I\'d probably write a Rails or Java EE app that could generate an XML view or an HTML view using templating - all the benefits, but with a much more natural (for me) programming language at my fingertips.</p>\n'}, {'answer_id': 78805, 'author': 'Crusty', 'author_id': 9810, 'author_profile': 'https://Stackoverflow.com/users/9810', 'pm_score': 4, 'selected': False, 'text': "<p>I remember all the hype around XSLT when the standard was newly released. All the excitement around being able built an entire HTML UI with a 'simple' transform. </p>\n\n<p>Let’s face it, it is hard to use, near impossible to debug, often unbearably slow. The end result is nearly always quirky and less than ideal.</p>\n\n<p>I will sooner gnaw off my own leg than use an XSLT while there are better ways to do things. Still it has its places, its good for simple transform tasks. </p>\n"}, {'answer_id': 78812, 'author': 'Ben', 'author_id': 13950, 'author_profile': 'https://Stackoverflow.com/users/13950', 'pm_score': 0, 'selected': False, 'text': "<p>I enjoy using XSLT only for changing the tree structure of XML documents. I find it cumbersome to do anything related to text processing and relegate that to a custom script that I may run before or after applying an XSLT to an XML document.</p>\n\n<p>XSLT 2.0 included a lot more string functions, but I think it's not a good fit for the language, and there's not many implementations of XSLT 2.0.</p>\n"}, {'answer_id': 78819, 'author': 'Mashed Potato', 'author_id': 14396, 'author_profile': 'https://Stackoverflow.com/users/14396', 'pm_score': 2, 'selected': False, 'text': "<p>I maintain an online documentation system for my company. The writers create the documentation in SGML ( an xml like language ). The SGML is then combined with XSLT and transformed into HTML.</p>\n\n<p>This allows us to easily make changes to the documentation layout without doing any coding. Its just a matter of changing the XSLT.</p>\n\n<p>This works well for us. In our case, its a read only document. The user isn't interacting with the documentation.</p>\n\n<p>Also, by using XSLT, you are working closer to your problem domain (HTML). I always consider that to be good idea.</p>\n\n<p>Lastly, if your current system WORKS, leave it alone. I would never suggest trashing your existing code. If I was starting from scratch, I would use XSLT, but in your case, I would use what you have.</p>\n"}, {'answer_id': 78841, 'author': 'mcherm', 'author_id': 14570, 'author_profile': 'https://Stackoverflow.com/users/14570', 'pm_score': 2, 'selected': False, 'text': '<p>I have found XSLT to be quite difficult to work with.</p>\n\n<p>I have had experience working on a system somewhat similar to the one you describe. My company noted that the data we were returning from "the middle tier" was in XML, and that the pages were to be rendered in HTML which might as well be XHTML, plus they\'d heard that XSL was a standard for transforming between XML formats. So the "architects" (by which I mean people who think deep design thoughts but apparently never code) decided that our front tier would be implemented by writing XSLT scripts that transformed the data into the XHTML for display.</p>\n\n<p>The choice turned out to be disastrous. XSLT, it turns out, is a pain to write. And so all of our pages were difficult to write and to maintain. We would have done much better to have used JSP (this was in Java) or some similar approach that used one kind of markup (angle brackets) for the output format (the HTML) and another kind of markup (like &lt;%...%>) for the meta-data. The most confusing thing about XSLT is that it is written in XML, and it translates from XML to XML... it is quite difficult to keep all 3 different XML documents straight in one\'s mind.</p>\n\n<p>Your situation is slightly different: instead of authoring each page in XSLT as I did, you only need to write ONE bit of code in XSLT (the code to convert from templates to display). But it sounds like you may have run into the same kind of difficulty that I did. I would say that trying to interpret a simple XML-based DSL (domain specific language) like you are doing is NOT one of the strong points of XSLT. (Although it CAN do the job... after all, it IS Turing complete!)</p>\n\n<p>However, if what you had was simpler: you have data in one XML format and wanted to make simple alterations to it -- not a full page-description DSL, but some simple straightforward modifications, then XSLT is an excellent tool for that purpose. It\'s declarative (not procedural) nature is actually an advantage for that purpose.</p>\n\n<p>-- Michael Chermside</p>\n'}, {'answer_id': 78862, 'author': 'Larry OBrien', 'author_id': 10116, 'author_profile': 'https://Stackoverflow.com/users/10116', 'pm_score': 0, 'selected': False, 'text': '<p>I think you did the right thing. In my experience, XSLT developers are among the very hardest to hire, because it\'s a language that never caught on either with Web developers nor with casual programmers.</p>\n\n<p>So you end up having to pay the "advanced programmer who knows a language outside the mainstream" premium, but for a language that is probably not that programmer\'s favorite. </p>\n'}, {'answer_id': 78920, 'author': 'Steve Jessop', 'author_id': 13005, 'author_profile': 'https://Stackoverflow.com/users/13005', 'pm_score': 7, 'selected': True, 'text': '<p>Advantages of XSLT:</p>\n\n<ul>\n<li>Domain-specific to XML, so for example no need to quote literal XML in the output.</li>\n<li>Supports XPath/XQuery, which can be a nice way to query DOMs, in the same way that regular expressions can be a nice way to query strings.</li>\n<li>Functional language.</li>\n</ul>\n\n<p>Disadvantages of XSLT:</p>\n\n<ul>\n<li>Can be obscenely verbose - you don\'t have to quote literal XML, which effectively means you do have to quote code. And not in a pretty way. But then again, it\'s not much worse than your typical SSI.</li>\n<li>Doesn\'t do certain things which most programmers take for granted. For instance string manipulation can be a chore. This can lead to "unfortunate moments" when novices design code, then frantically search the web for hints how to implement functions they assumed would just be there and didn\'t give themselves time to write.</li>\n<li>Functional language.</li>\n</ul>\n\n<p>One way to get procedural behaviour, by the way, is to chain multiple transforms together. After each step you have a brand new DOM to work on which reflects the changes in that step. Some XSL processors have extensions to effectively do this in one transform, but I forget the details.</p>\n\n<p>So, if your code is mostly output and not much logic, XSLT can be a very neat way to express it. If there is a lot of logic, but mostly of forms which are built in to XSLT (select all elements which look like blah, and for each one output blah), it\'s likely to be quite a friendly environment. If you fancy thinking XML-ishly at all times, then give XSLT 2 a go.</p>\n\n<p>Otherwise, I\'d say that if your favourite programming language has a good DOM implementation supporting XPath and allowing you to build documents in a useful way, then there are few benefits to using XSLT. Bindings to libxml2 and gdome2 should do nicely, and there\'s no shame in sticking to general-purpose languages you know well.</p>\n\n<p>Home-grown XML parsers are usually either incomplete (in which case you\'ll come unstuck some day) or else not much smaller than something you could have got off the shelf (in which case you\'re probably wasting your time), and give you any number of opportunities to introduce severe security issues around malicious input. Don\'t write one unless you know exactly what you gain by doing it. Which is not to say you can\'t write a parser for something simpler than XML as your input format, if you don\'t need everything that XML offers.</p>\n'}, {'answer_id': 78948, 'author': 'SpongeJim', 'author_id': 13361, 'author_profile': 'https://Stackoverflow.com/users/13361', 'pm_score': 2, 'selected': False, 'text': '<p>It comes down to what you need it for. Its main strength is the easy maintainability of the transform, and writing your own parser generally obliterates that. With that said, sometimes a system is small and simple and really doesn\'t need a "fancy" solution. As long as your code-based builder is replaceable without having to change other code, no big deal.</p>\n\n<p>As for the ugliness of XSL, yes it\'s ugly. Yes, it takes some getting used to. But once you get the hang of it (shouldn\'t take long IMO), it\'s actually smooth sailing. Compiled transforms run quite quickly in my experience, and you can certainly debug into them.</p>\n'}, {'answer_id': 79025, 'author': 'Nat', 'author_id': 13813, 'author_profile': 'https://Stackoverflow.com/users/13813', 'pm_score': 2, 'selected': False, 'text': '<p>I would definitely reccomend to stick it out. Particularly if you are using visual studio which has built in editing, viewing and debugging tools for XSLT. </p>\n\n<p>Yes, it is a pain while you are learning, but most of the pain is to do with familiarity. The pain does diminish as you learn the language.</p>\n\n<p>W3schools has two articles that are of particular worth:\n<a href="http://www.w3schools.com/xpath/xpath_functions.asp" rel="nofollow noreferrer">http://www.w3schools.com/xpath/xpath_functions.asp</a>\n<a href="http://www.w3schools.com/xsl/xsl_functions.asp" rel="nofollow noreferrer">http://www.w3schools.com/xsl/xsl_functions.asp</a></p>\n'}, {'answer_id': 190971, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I need to work with XSLT here because some one thought it is a good idea to solve a given problem: We need to extract some data from multiple XML-Files and join it together to different output formats for different tools that do further processing.</p>\n\n<p>Fisrt I thought XSLT is a very nice idea, because it is a standard you can rely on. This is true for simple formating tasks where you do not need to much programming logic or algorithms in your code.</p>\n\n<p>But: It is quite a step learning curve, as it is <em>not</em> procedural. If you got used to procedural programming (C,Java,Perl,PHP, etc) you are going to miss a lot of common structs or you will wonder about things that just luck cubersome and sometimes not really readable by an untrained eye.\nFor example writing "resuseable" code: If you need to do something over and over again in different places, in procedural programming, you would define a function to do so. You may achive such things in XSLT as well, but its for more code to write and is not as readable/understandable as a normal function would be.</p>\n\n<p>The main problem I have, is that many people comming from a procedural background worked on the XSLT-Files by now, and almost everyone just "emulated" what he needed.</p>\n\n<p>So as a conclusion: I don\'t see XSLT as "the ultimate" solution anymore. In fact it is pain to read or write some constructs in XSLT. For most cases you will have to think about the application: For simple transformation I will probably use XSLT again. But for more complex software I will not use it again.</p>\n'}, {'answer_id': 190981, 'author': 'David Robbins', 'author_id': 19799, 'author_profile': 'https://Stackoverflow.com/users/19799', 'pm_score': 2, 'selected': False, 'text': '<p>XSLT is difficult to work with, but once you conquer it you will have a very thorough understanding of the DOM and schema. If you also XPath, then you on your way to learning functional programming and this will expose to new techniques and ways about solving problems. In some cases, successive transformation is more powerful than procedural solutions.</p>\n'}, {'answer_id': 228838, 'author': 'Goran', 'author_id': 23164, 'author_profile': 'https://Stackoverflow.com/users/23164', 'pm_score': 1, 'selected': False, 'text': "<p>I'm currently tasked with scraping data from a public site (yeah, i know). Thankfully it conforms to xhtml so I'm able to use xslt to gather the data I need. The resulting solution is readable, clean and easy to change if need occurs. Perfect!</p>\n"}, {'answer_id': 228853, 'author': 'Midhat', 'author_id': 9425, 'author_profile': 'https://Stackoverflow.com/users/9425', 'pm_score': 0, 'selected': False, 'text': '<p>Talking about interoprability, XML is a standard for information storage. A whole lot of tools produce output in XML, and what better(or easier) way to present it than embed a browser in your app and format the XML and put it into the browser.</p>\n'}, {'answer_id': 264501, 'author': 'Vinh', 'author_id': 34561, 'author_profile': 'https://Stackoverflow.com/users/34561', 'pm_score': 0, 'selected': False, 'text': '<p>In my opinion Yes.</p>\n\n<p>For a great example of a really cool use of XSLT, check out blizzard\'s world of warcraft armory.</p>\n\n<p><a href="http://www.wowarmory.com" rel="nofollow noreferrer">http://www.wowarmory.com</a></p>\n'}, {'answer_id': 301475, 'author': 'annakata', 'author_id': 13018, 'author_profile': 'https://Stackoverflow.com/users/13018', 'pm_score': 7, 'selected': False, 'text': '<p>So much negativity!</p>\n\n<p>I\'ve been using XSLT for a good few years now, and genuinely love it. The key thing you have to realise is that <em>it\'s not a programming language it\'s a templating language</em> (and in this respect I find it indescribably superior to asp.net /spit).</p>\n\n<p>XML is the de facto data format of web development today, be it config files, raw data or in memory reprsentation. XSLT and XPath give you an <em>enormously</em> powerful and very efficient way to transform that data into any output format you might like, instantly giving you that MVC aspect of separating the presentation from the data. </p>\n\n<p>Then there\'s the utility abilities: washing out namespaces, recognising disparate schema definitions, merging documents.</p>\n\n<p>It <em>must</em> be better to deal with XSLT than developing your own in-house methods. At least XSLT is a standard and something you could hire for, and if it\'s ever really a problem for your team it\'s very nature would let you keep most of your team working with just XML.</p>\n\n<p>A real world use case: I just wrote an app which handles in-memory XML docs throughout the system, and transforms to JSON, HTML, or XML as requested by the end user. I had a fairly random request to provide as Excel data. A former colleague had done something similar programatically but it required a module of a few class files and that the server had MS Office installed! Turns out Excel has an XSD: new functionality with minimum basecode impact in 3 hours.</p>\n\n<p>Personally I think it\'s one of the cleanest things I\'ve encountered in my career, and I believe all of it\'s apparent issues (debugging, string manipulation, programming structures) are down to a flawed understanding of the tool.</p>\n\n<p>Obviously, I strongly believe it is "worth it".</p>\n'}, {'answer_id': 1270602, 'author': 'Sam Harwell', 'author_id': 138304, 'author_profile': 'https://Stackoverflow.com/users/138304', 'pm_score': 1, 'selected': False, 'text': "<p>I've used XSLT before. The group of 6 .xslt files (refactored out of one large one) was about 2750 lines long before I rewrote it in C#. The C# code is currently 4000 lines containing lots of logic; I don't even want to think about what that would have taken to write in XSLT.</p>\n\n<p>The point where I gave up is when I realized not having XPATH 2.0 was significantly hurting my progress.</p>\n"}, {'answer_id': 1270604, 'author': 'Bill Karwin', 'author_id': 20860, 'author_profile': 'https://Stackoverflow.com/users/20860', 'pm_score': 4, 'selected': False, 'text': '<p>XSLT is an example of a <a href="http://en.wikipedia.org/wiki/Declarative_programming" rel="noreferrer">declarative programming</a> language. </p>\n\n<p>Other examples of declarative programming languages include regular expressions, Prolog, and SQL. All of these are highly expressive and compact, and usually very well designed and powerful for the task for which they are designed.</p>\n\n<p>However, software developers generally hate such languages, because they are so different from more mainstream OO or procedural languages that they\'re hard to learn and debug. Their compact nature generally makes it very easy to do a lot of damage inadvertently.</p>\n\n<p>So while XSLT is an efficient mechanism to merge data into presentation, it fails in the ease-of-use department. I believe that\'s why it hasn\'t really caught on.</p>\n'}, {'answer_id': 1270612, 'author': 'Aaron Digulla', 'author_id': 34088, 'author_profile': 'https://Stackoverflow.com/users/34088', 'pm_score': 0, 'selected': False, 'text': "<p>I did use XSLT extensively ... for a couple of hours. It's cool for things like changing element names or filtering an input document (stripping stuff away that you don't need).</p>\n\n<p>Anything else gets complex very quickly. This inherit complexity plus the lack of most things you're used from any other programming languages (like variables) and the easy ways to make XPath expressions unreadable, really hurt.</p>\n\n<p>In the end, XSLT suffers from a schisma: Programmers don't like it because of the limitations and everyone else can't use it at all (say, web designers or any other non-programmer type). </p>\n\n<p>If XSLT had been promoted as some kind of SQL for XML, things would be a bit different. First, people wouldn't have even bothered to look at it. And those who did wouldn't have been surprised by the pain.</p>\n"}, {'answer_id': 1270614, 'author': 'Darknight', 'author_id': 150363, 'author_profile': 'https://Stackoverflow.com/users/150363', 'pm_score': 0, 'selected': False, 'text': "<p>I think the concept is sound, perhaps the execution is not as 'clean' as it could be.</p>\n\n<p>However I think it should be treated as a tool, it may not be wise to use it in every instance, however one should never ignore a tool when solving solutions.</p>\n\n<p>I have seen very good XSLT, and also very bad use of XSLT, and I conclude some of it may be down to the skill of the developer. I think its one that requires for the developer to think in multiple domains at the same time.</p>\n\n<p>Is it the future? maybe not, maybe there are better solutions..</p>\n\n<p>I don't know what new technology is going to come along, but at least its best to learn it, increasing ones own tool set can't be a bad thing surely?</p>\n"}, {'answer_id': 1270628, 'author': 'Alohci', 'author_id': 42585, 'author_profile': 'https://Stackoverflow.com/users/42585', 'pm_score': 3, 'selected': False, 'text': "<p>Yes, I use it a lot. By using different xslt files, I can use the same XML source to create multiple polyglot (X)HTML files (presenting the same data in different ways), a RSS feed, an Atom feed, a RDF descriptor file and fragment of a site map.</p>\n\n<p>It's not a panacea. There are things it does well, and things it doesn't do well, and like all other aspects of programming, it's all about using the right tool for the right job. It's a tool that's well worth having in your toolbox but it should used only when it's appropriate to do so.</p>\n"}, {'answer_id': 1270634, 'author': 'Dawie Strauss', 'author_id': 4211, 'author_profile': 'https://Stackoverflow.com/users/4211', 'pm_score': 1, 'selected': False, 'text': "<p>To answer your three questions:</p>\n\n<ol>\n<li>I've used XSLT once some years ago.</li>\n<li>I do believe XSLT could be the right solution in certain circumstances. (Never say never)</li>\n<li>I tend to agree with your assesment that it is mostly useful for 'simple' transformations. But I think as long as you understand XSLT well, there is a case to be made for using it for bigger tasks like publishing a website as XML transformed into HTML.</li>\n</ol>\n\n<p>I believe the reason many developers dislike XSLT is because they do not understand the fundamentally different paradigm it is based on. But with the recent interest in functional programming we might see XSLT making a comeback...</p>\n"}, {'answer_id': 1270665, 'author': 'bendin', 'author_id': 33412, 'author_profile': 'https://Stackoverflow.com/users/33412', 'pm_score': 3, 'selected': False, 'text': '<p>I use XSLT (for lack of better alternative), but not for presentation, just for transformation:</p>\n\n<ol>\n<li><p>I write short XSLT transformations to do mass edits on our maven pom.xml files.</p></li>\n<li><p>I\'ve written a pipeline of transformations to generate XML Schemas from XMI (UML Diagram). It worked for a while, but it finally got too complex and we had to take it out behind the barn.</p></li>\n<li><p>I\'ve used transformations to refactor XML Schemas.</p></li>\n<li><p>I\'ve worked around some limitations in XSLT by using it to generate an XSLT to do the real work. (Ever tried to write an XSLT that produces an output using namespaces that aren\'t known until runtime?)</p></li>\n</ol>\n\n<p>I keep coming back to it because it does a better job round-tripping the XML it\'s processing than other approaches I\'ve tried, which have seemed needlessly lossy or simply misunderstand XML. XSLT is unpleasant, but I find using <a href="http://www.oxygenxml.com/" rel="noreferrer">Oxygen</a> makes it bearable.</p>\n\n<p>That said, I\'m investigating using <a href="http://clojure.org/" rel="noreferrer">Clojure</a> (a lisp) to perform transformations of XML, but I haven\'t gotten far enough yet to know if that approach will bring me benefits.</p>\n'}, {'answer_id': 1270668, 'author': 'Adam Batkin', 'author_id': 120808, 'author_profile': 'https://Stackoverflow.com/users/120808', 'pm_score': 5, 'selected': False, 'text': '<p>We use XSLT extensively for things like documentation, and making some complex configuration settings user-serviceable.</p>\n\n<p>For documentation, we use a lot of DocBook, which is an XML-based format. This lets us store and manage our documentation with all of our source code, since the files are plain text. With XSLT, we can easily build our own documentation formats, allowing us to both autogenerate the content in a generic way, and make the content more readable. For example, when we publish release notes, we can create XML that looks something like:</p>\n\n<pre><code>&lt;ReleaseNotes&gt;\n &lt;FixedBugs&gt;\n &lt;Bug id="123" component="Admin"&gt;Error when clicking the Foo button&lt;/Bug&gt;\n &lt;Bug id="125" component="Core"&gt;Crash at startup when configuration is missing&lt;/Bug&gt;\n &lt;Bug id="127" component="Admin"&gt;Error when clicking the Bar button&lt;/Bug&gt;\n &lt;/FixedBugs&gt;\n&lt;/ReleaseNotes&gt;\n</code></pre>\n\n<p>And then using XSLT (which transforms the above to DocBook) we end up with nice release notes (PDF or HTML usually) where bug IDs are automatically linked to our bug tracker, bugs are grouped by component, and the format of everything is perfectly consistent. And the above XML can be generated automatically by querying our bug tracker for what has changed between versions.</p>\n\n<p>The other place where we have found XSLT to be useful is actually in our core product. Sometimes when interfacing with third-party systems we need to somehow process data in a complex HTML page. Parsing HTML is ugly, so we feed the data through something like <a href="http://home.ccil.org/~cowan/XML/tagsoup/" rel="noreferrer">TagSoup</a> (which generates proper SAX XML events, essentially letting us deal with the HTML as if it were properly written XML) and then we can run some XSLT against it, to turn the data into a "known stable" format that we can actually work with. By separating out that transformation into an XSLT file, that means that if and when the HTML format changes, the application itself does not need to be upgraded, instead the end-user can just edit the XSLT file themselves, or we can e-mail them an updated XSLT file without the entire system needing to be upgraded.</p>\n\n<p>I would say that for web projects, there are better ways to handle the view side than XSLT today, but as a technology there are definitely uses for XSLT. It\'s not the easiest language in the world to use, but it is definitely not dead, and from my perspective still has lots of good uses.</p>\n'}, {'answer_id': 1270673, 'author': 'Totonga', 'author_id': 101635, 'author_profile': 'https://Stackoverflow.com/users/101635', 'pm_score': 0, 'selected': False, 'text': '<p>I use XSLT to correct errors in very complexe xml files. So instead of handling the errors in the xml I use xslt to correct them.</p>\n\n<p>This is great. Because the language is so powerful and it fits the xml use case.\nTo do the same things in an ususal programming language it would took me real long time to adapt my code every time a new flavour arises.</p>\n\n<p>Its also usefult to migrate visual studio solutions without letting microsoft decide which things to change. So convert one solution. Check what changed. Revert the things you do not want to change and run the xslt script doing the job on all files.</p>\n\n<p>So I never used it to do web presentations or something like this but it helps me in my xml based problems. And to solve these issues its really really powerful and really worth having a look on it.</p>\n'}, {'answer_id': 1270707, 'author': 'Pavel Minaev', 'author_id': 111335, 'author_profile': 'https://Stackoverflow.com/users/111335', 'pm_score': 3, 'selected': False, 'text': "<p>I've used XSLT (and also XQuery) extensively for various things - to generate C++ code as part of build process, to produce documentation from doc comments, and within an application that had to work with XML in general and XHTML in particular a lot. The code generator in particular was in excess of 10,000 lines of XSLT 2.0 code spread around about a dozen separate files (it did a lot of things - headers for clients, remoting proxies/stubs, COM wrappers, .NET wrappers, ORM - to name a few). I inherited it over another guy who didn't really understand the language well, and the older bits were consequently quite a mess. Newer stuff that we wrote was mostly kept sane and readable, however, and I do not recall any particular problems with achieving that. It was certainly not any harder than doing it for C++.</p>\n\n<p>Speaking of versions, dealing with XSLT 2.0 definitely helps keep you sane, but 1.0 is still alright for simpler transforms. In its niche, it is an extremely handy tool, and the productivity you get from certain domain-specific features (most importantly, dynamic dispatch via template matching) is hard to match. Despite the perceived wordiness of XSLT's XML-based syntax, the same thing in LINQ to XML (even in VB with XML literals) was usually several times longer. Quite often, however, it gets undeserved flack because of unnecessary use of XML in some case in the first place.</p>\n\n<p>To sum it up: it is an incredibly useful tool to have in one's toolbox, but it is a very specialized one, so it is good so long as you use it properly and for its intended purpose. I really wish there was a proper, native .NET implementation of XSLT 2.0. </p>\n"}, {'answer_id': 1270733, 'author': 'Jack Ryan', 'author_id': 28882, 'author_profile': 'https://Stackoverflow.com/users/28882', 'pm_score': 1, 'selected': False, 'text': "<p>One place where xslt really shines is in generating reports. I've found that a 2 step process, with the first step exporting the report data as an xml file, and the second step generating the visual report from the xml using xslt. This allows for nice visual reports while still keeping the raw data around as a validation mechanism if needs be.</p>\n"}, {'answer_id': 1270746, 'author': 'Eamon Nerbonne', 'author_id': 42921, 'author_profile': 'https://Stackoverflow.com/users/42921', 'pm_score': 2, 'selected': False, 'text': '<p>I use XSLT extensively, for a custom MVC style front-end. The model is "serialized" to xml (not via xml serializaiton), and then converted to html via xslt. The advantage over ASP.NET lie in the natural integration with XPath, and the more rigorous well-formedness requirements (it\'s much easier to reason about document structure in xslt than in most other languages).</p>\n\n<p>Unfortunately, the language contains several limitations (for example, the ability to transform the output of another transform) which mean that it\'s occasionally frustrating to work with.</p>\n\n<p>Nevertheless, the easily achievable, strongly enforced separation of concerns which it grants aren\'t something I see another technology providing right now - so for document transforms it\'s still something I\'d recommend.</p>\n'}, {'answer_id': 1270757, 'author': 'philsquared', 'author_id': 32136, 'author_profile': 'https://Stackoverflow.com/users/32136', 'pm_score': 2, 'selected': False, 'text': '<p>If you can use XSLT in a declarative style (although I don\'t entirely agree that it is declarative language) then I think it is useful and expressive.</p>\n\n<p>I\'ve written web apps that use an OO language (C# in my case) to handle the data/ processing layer, but output XML rather than HTML. This can then be consumed directly by clients as a data API, or rendered as HTML by XSLTs. Because the C# was outputting XML that was structurally compatible with this use it was all very smooth, and the presentation logic was kept declarative. It was easier to follow and change than sending the tags from C#.</p>\n\n<p>However, as you require more processing logic at the XSLT level it gets convoluted and verbose - even if you "get" the functional style.</p>\n\n<p>Of course, these days I\'d probably have written those web apps using a RESTful interface - and I think data "languages" such as JSON are gaining traction in areas that XML has traditionally been transformed by XSLT. But for now XSLT is still an important, and useful, technology.</p>\n'}, {'answer_id': 1270863, 'author': 'Sam', 'author_id': 155655, 'author_profile': 'https://Stackoverflow.com/users/155655', 'pm_score': 2, 'selected': False, 'text': "<p>I used XML, XSD and XSLT on an integration project between very dis-similar DB systems sometime in 2004. I had to learn XSD and XSLT from scratch but it wasn't hard. The great thing about these tools was that it enabled me to write data independent C++ code, relying on XSD and XSLT to validate/verify and then transform the XML documents. Change the data format, change the XSD and XSLT documents not the C++ code which employed the Xerces libraries.</p>\n\n<p>For interest: the main XSD was 150KB and the average size of the XSLT was &lt; 5KB IIRC.</p>\n\n<p>The other great benefit is that the XSD is a specification document that the XSLT is based on. The two work in harmony. And specs are rare in software development these days.</p>\n\n<p>Although I did not have too much trouble learning the declarative nature XSD and XSLT I did find that other C/C++ programmers had great trouble in adjusting to the declarative way. When they saw that was it, ah procedural they muttered, now that I understand! And they proceeded (pun?) to write procedural XSLT! The thing is you have to learn XPath and understand the axes of XML. Reminds me of old-time C programmers adjusting to employing OO when writing C++.</p>\n\n<p>I used these tools as they enabled me to write a small C++ code base that was isolated from all but the most fundamental of data structure modifications and these latter were DB structure changes. Even though I prefer C++ to any other language I'll use what I consider to be useful to benefit the long term viability of a software project.</p>\n"}, {'answer_id': 1271075, 'author': 'Jack Ukleja', 'author_id': 61714, 'author_profile': 'https://Stackoverflow.com/users/61714', 'pm_score': 2, 'selected': False, 'text': "<p>I used to think XSLT was a great idea. I mean it <em>is</em> a great idea.</p>\n\n<p>Where it fails is the execution.</p>\n\n<p>The problem I discovered over time was that programming languages in XML are just a bad idea. It makes the whole thing impenetrable. Specifically I think XSLT is very hard learn, code and understand. The XML on top of the functional aspects just makes the whole thing too confusing. I have tried to learn it about 5 times in my career, and it just doesn't stick.</p>\n\n<p>OK, you could 'tool' it -- I think that was partly the point of it's design -- but that's the second failing: all the XSLT tools on the market are, quite simply ... crap!</p>\n"}, {'answer_id': 1271269, 'author': 'Jimmy', 'author_id': 427861, 'author_profile': 'https://Stackoverflow.com/users/427861', 'pm_score': 0, 'selected': False, 'text': '<p>In terms of sheer productivity you would be better off using one of the jQuery-style libraries - pyQuery, phpQuery etc. Most XML libraries suck and XSLT is essentially just another XML library packaged as a full-fledged language but without a decent set of tools. jQuery makes it insanely easy to traverse and manipulate XML style data in your language of choice.</p>\n'}, {'answer_id': 1272337, 'author': 'Toon Krijthe', 'author_id': 18061, 'author_profile': 'https://Stackoverflow.com/users/18061', 'pm_score': 1, 'selected': False, 'text': '<p>At a previous company we did a lot with XML and XSLT. Both XML and XSLT big.</p>\n\n<p>Yes there is a learning curve, but then you have a powerful tool to handle XML. And you can even use XSLT on XSLT (which can sometimes be useful).</p>\n\n<p>Performance is also an issue (with very large XML) but you can tackle that by using smart XSLT and do some preprocessing with the (generated) XML.</p>\n\n<p>Anybody with knowledge of XSLT can change the apearance of the finished product because it is not compiled.</p>\n'}, {'answer_id': 1273366, 'author': 'Nic Gibson', 'author_id': 88002, 'author_profile': 'https://Stackoverflow.com/users/88002', 'pm_score': 5, 'selected': False, 'text': '<p>I have to admit a bias here because I teach XSLT for a living. But, it might be worth covering off the areas that I see my students working in. They split into three groups generally: publishing, banking and web.</p>\n\n<p>Many of the answers so far could be summarised as "it\'s no good for creating websites" or "it\'s nothing like language X". Many tech folks go through their careers with no exposure to functional/declarative languages. When I\'m teaching, the experienced Java/VB/C/etc folk are the ones who have issues with the language (variables are variables in the sense of algebra not procedural programming for example). That\'s many of the people answering here - I\'ve never gotten on with Java but I\'m not going to bother to critique the language because of that.</p>\n\n<p>In many circumstances it is an inappropriate tool for creating websites - a general purpose programming language may be better. I often need to take very large XML documents and present them on the web; XSLT makes that trivial. The students I see in this space tend to be processing data sets and presenting them on the web. XSLT is certainly not the only applicable tool in this space. However, many of them are using the DOM to do this and XSLT is certainly less painful.</p>\n\n<p>The banking students I see use a DataPower box in general. This is an XML appliance and it\'s used to sit between services \'speaking\' different XML dialects. Transformation from one XML language to another is almost trivial in XSLT and the number of students attending my courses on this are increasing.</p>\n\n<p>The final set of students I see come from a publishing background (like me). These people tend to have immense documents in XML (believe me, publishing as an industry is getting very into XML - technical publishing has been there for years and trade publishing is getting there now). These documents need to be processing (DocBook to ePub comes to mind here).</p>\n\n<p>Someone above commented that scripts tend to be below 60 lines or they become unwieldy. If it does become unwieldy, the odds are the coder hasn\'t really got the idea - XSLT is a very different mindset from many other languages. If you don\'t get the mindset it won\'t work. </p>\n\n<p>It\'s certainly not a dying language (the amount of work I get tells me that). Right now, it\'s a bit \'stuck\' until Microsoft finish their (very late) implementation of XSLT 2. But it\'s still there and seems to be going strong from my viewpoint.</p>\n'}, {'answer_id': 1535693, 'author': 'brianary', 'author_id': 54323, 'author_profile': 'https://Stackoverflow.com/users/54323', 'pm_score': 1, 'selected': False, 'text': '<p>I personally like XSLT, and you may want to give the <a href="http://www.w3.org/TR/xslt#result-element-stylesheet" rel="nofollow noreferrer">simplified syntax</a> a look (no explicit templates, just a regular old HTML file with a few XSLT tags to spit values into it), but it just isn\'t for everyone.</p>\n\n<p>Maybe you just want to offer your authors a simple Wiki or Markdown interface. There are libraries for that, too, and if XSLT isn\'t working for you, maybe XML isn\'t working for them either.</p>\n'}, {'answer_id': 8332324, 'author': 'Rolf', 'author_id': 370786, 'author_profile': 'https://Stackoverflow.com/users/370786', 'pm_score': 0, 'selected': False, 'text': "<p>I've had a rather good experience with XSLT, but I wasn't transforming into HTML. It may be that the XSLT-HTML combo is a very difficult one for getting things done.</p>\n"}, {'answer_id': 8913739, 'author': 'dolmen', 'author_id': 328115, 'author_profile': 'https://Stackoverflow.com/users/328115', 'pm_score': 0, 'selected': False, 'text': '<p>XSLT 1.0 is one of the most portable code, at least on desktop and server computers.\nBecause it has one (and often many) runtime on most of those systems:</p>\n\n<ul>\n<li>Microsoft Windows has MSXML which is installed in the base system since at least Windows 2000. It can be used both from MSIE, <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms757858%28v=vs.85%29.aspx" rel="nofollow">from the command line</a> (using WSH) or from Office applications</li>\n<li>The Java Runtime Environment (JRE) has an XSLT runtime, and a JRE is installed on most desktops</li>\n<li>Almost all major web browser have one. Opera is the exception.</li>\n<li>There are free implementations that installed by default on major GNU based operating systems (libxslt, xsltproc)</li>\n<li>I\'ve not checked MacOS X, but it has at least an implementation in Safari</li>\n</ul>\n\n<p>This makes it a good fit to build some applications that require both portability and lightweight/no installation.</p>\n\n<p>Also, XSLT only requires a runtime (no compiler needed) and you can create the code just with any text editor. So you can create programs easily (well, once you master the language) from any desktop.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78716', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9021/']
78,717
<p>I have a 'foreach' macro I use frequently in C++ that works for most STL containers:</p> <pre><code>#define foreach(var, container) \ for(typeof((container).begin()) var = (container).begin(); \ var != (container).end(); \ ++var) </code></pre> <p>(Note that 'typeof' is a gcc extension.) It is used like this:</p> <pre><code>std::vector&lt; Blorgus &gt; blorgi = ...; foreach(blorgus, blorgi) { blorgus-&gt;draw(); } </code></pre> <p>I would like to make something similar that iterates over a map's values. Call it "foreach_value", perhaps. So instead of writing</p> <pre><code>foreach(pair, mymap) { pair-&gt;second-&gt;foo(); } </code></pre> <p>I would write</p> <pre><code>foreach_value(v, mymap) { v.foo(); } </code></pre> <p>I can't come up with a macro that will do this, because it requires declaring two variables: the iterator and the value variable ('v', above). I don't know how to do that in the initializer of a for loop, even using gcc extensions. I could declare it just before the foreach_value call, but then it will conflict with other instances of the foreach_value macro in the same scope. If I could suffix the current line number to the iterator variable name, it would work, but I don't know how to do that.</p>
[{'answer_id': 78754, 'author': 'Tyler', 'author_id': 3561, 'author_profile': 'https://Stackoverflow.com/users/3561', 'pm_score': 0, 'selected': False, 'text': '<p>You could define a template class that takes the type of mymap as a template parameter, and acts like an iterator over the values by overloading * and ->.</p>\n'}, {'answer_id': 78780, 'author': 'Tom Leys', 'author_id': 11440, 'author_profile': 'https://Stackoverflow.com/users/11440', 'pm_score': 3, 'selected': False, 'text': '<p>You would be looking for <a href="http://www.boost.org/doc/libs/1_36_0/doc/html/foreach.html" rel="nofollow noreferrer">BOOST_FOREACH</a> - they have done all the work for you already!</p>\n\n<p>If you do want to roll your own, you can declare a block anywhere in C++, which resolves your scope issue with your intermediate storage of itr->second\n...</p>\n\n<pre><code>// Valid C++ code (which does nothing useful)\n{\n int a = 21; // Which could be storage of your value type\n}\n// a out of scope here\n{ \n int a = 32; // Does not conflict with a above\n}\n</code></pre>\n'}, {'answer_id': 78793, 'author': 'porges', 'author_id': 10311, 'author_profile': 'https://Stackoverflow.com/users/10311', 'pm_score': 1, 'selected': False, 'text': '<p>Have you thought of using the <a href="http://www.boost.org/" rel="nofollow noreferrer">Boost libraries</a>? They have a <a href="http://www.boost.org/doc/libs/1_36_0/doc/html/foreach.html" rel="nofollow noreferrer"><code>foreach</code> macro implemented</a> which is probably more robust than anything you\'ll write... and there is also <a href="http://www.boost.org/doc/libs/1_36_0/libs/iterator/doc/transform_iterator.html" rel="nofollow noreferrer"><code>transform_iterator</code></a> which would seem to be able to be used to do the second-extraction part of what you want.</p>\n\n<p>Unfortunately I can\'t tell you exactly <em>how</em> to use it because I don\'t know enough C++ :) <a href="http://www.google.com/search?q=boost+foreach+transform_iterator" rel="nofollow noreferrer">This Google search</a> turns up some promising answers: <a href="http://groups.google.com/group/comp.lang.c++.moderated/msg/26b344960588d3ac" rel="nofollow noreferrer">comp.lang.c++.moderated</a>, <a href="https://network-geographics.com/weblog/2008/06/boost_transform_iterator_use_cas.html" rel="nofollow noreferrer">Boost transform_iterator use case</a>.</p>\n'}, {'answer_id': 79071, 'author': 'archbishop', 'author_id': 14529, 'author_profile': 'https://Stackoverflow.com/users/14529', 'pm_score': 4, 'selected': True, 'text': "<p>You can do this using two loops. The first declares the iterator, with a name which is a function of the container variable (and you can make this uglier if you're worried about conflicts with your own code). The second declares the value variable.</p>\n\n<pre><code>#define ci(container) container ## iter\n#define foreach_value(var, container) \\\n for (typeof((container).begin()) ci(container) = container.begin(); \\\n ci(container) != container.end(); ) \\\n for (typeof(ci(container)-&gt;second)* var = &amp;ci(container)-&gt;second; \\\n ci(container) != container.end(); \\\n (++ci(container) != container.end()) ? \\\n (var = &amp;ci(container)-&gt;second) : var)\n</code></pre>\n\n<p>By using the same loop termination condition, the outer loop only happens once (and if you're lucky, gets optimized away). Also, you avoid calling ->second on the iterator if the map is empty. That's the same reason for the ternary operator in the increment of the inner loop; at the end, we just leave var at the last value, since it won't be referenced again.</p>\n\n<p>You could inline ci(container), but I think it makes the macro more readable.</p>\n"}, {'answer_id': 79250, 'author': 'Zachary Garrett', 'author_id': 14692, 'author_profile': 'https://Stackoverflow.com/users/14692', 'pm_score': 2, 'selected': False, 'text': '<p>The STL <em><a href="http://www.sgi.com/tech/stl/transform.html" rel="nofollow noreferrer">transform</a></em> function also does something similar. </p>\n\n<p>The arguments are (in order):</p>\n\n<ol>\n<li>An input iterator designating the beginning of a container </li>\n<li>An input iterator designating the end of the container</li>\n<li>An output iterator defining where to put the output (for an in-place transform, similar to for-each, just pass the the input iterator in #1)</li>\n<li>A unary function (function object) to perform on each element</li>\n</ol>\n\n<p>For a very simple example, you could capitalize each character in a string by:</p>\n\n<pre><code>#include &lt;iostream&gt;\n#include &lt;string&gt;\n#include &lt;algorithm&gt;\n#include &lt;cctype&gt;\n\nint main(int argc, char* argv[]) {\n std::string s("my lowercase string");\n std::transform(s.begin(), s.end(), s.begin(), toupper);\n std::cout &lt;&lt; s &lt;&lt; std::endl; // "MY LOWERCASE STRING"\n}\n</code></pre>\n\n<p>Alternatively there is also the <em><a href="http://www.sgi.com/tech/stl/accumulate.html" rel="nofollow noreferrer">accumulate</a></em> function, which allows some values to be retained between calls to the function object. <em>accumulate</em> does not modify the data in the input container as is the case with <em>transform</em>.</p>\n'}, {'answer_id': 79463, 'author': 'Mark Kegel', 'author_id': 14788, 'author_profile': 'https://Stackoverflow.com/users/14788', 'pm_score': 1, 'selected': False, 'text': '<p>Boost::For_each is by far your best bet. The nifty thing is that what they actually give you is the macro BOOST_FOREACH() which you can then wrap and #define to whatever you would really like to call it in your code. Most everyone will opt for the good old "foreach", but other shops may have different coding standards, so this fits with that mindset. Boost also has lots of other goodies for C++ developers! Well worth using.</p>\n'}, {'answer_id': 80671, 'author': 'Assaf Lavie', 'author_id': 11208, 'author_profile': 'https://Stackoverflow.com/users/11208', 'pm_score': 0, 'selected': False, 'text': "<pre><code>#define foreach(var, container) for (typeof((container).begin()) var = (container).begin(); var != (container).end(); ++var)\n</code></pre>\n\n<p>There's no typeof in C++... how is this compiling for you? (it's certainly not portable)</p>\n"}, {'answer_id': 4214768, 'author': 'Artur Sowiński', 'author_id': 512072, 'author_profile': 'https://Stackoverflow.com/users/512072', 'pm_score': 1, 'selected': False, 'text': '<p>I created a little Foreach.h helper with a few variants of foreach() including both ones operating on the local variables and on pointers, with also an extra version secured against deleting elements from within loop. So the code that uses my macros looks nice and cozy like this:</p>\n\n<pre><code>#include &lt;cstdio&gt;\n#include &lt;vector&gt;\n#include "foreach.h"\n\nint main()\n{\n // make int vector and fill it\n vector&lt;int&gt; k;\n for (int i=0; i&lt;10; ++i) k.push_back(i);\n\n // show what the upper loop filled\n foreach_ (it, k) printf("%i ",(*it));\n printf("\\n");\n\n // show all of the data, but get rid of 4\n // http://en.wikipedia.org/wiki/Tetraphobia :)\n foreachdel_ (it, k)\n {\n if (*it == 4) it=k.erase(it);\n printf("%i ",(*it));\n }\n printf("\\n");\n\n return 0;\n}\n</code></pre>\n\n<p>output:</p>\n\n<pre><code>0 1 2 3 4 5 6 7 8 9\n0 1 2 3 5 6 7 8 9\n</code></pre>\n\n<p>My <a href="http://pleasanthacking.com/2010/06/17/foreach-in-cpp/" rel="nofollow" title="Foreach in c++">Foreach.h</a> provides following macros:</p>\n\n<ul>\n<li>foreach() - regular foreach for pointers </li>\n<li>foreach_() - regular foreach for local variables </li>\n<li>foreachdel() - foreach version with checks for deletion within loop, pointer version</li>\n<li>foreachdel_() - foreach version with checks for deletion within loop, local variable version</li>\n</ul>\n\n<p>They sure do work for me, I hope they will also make your life a bit easier :)</p>\n'}, {'answer_id': 7253042, 'author': 'Stuart Berg', 'author_id': 162094, 'author_profile': 'https://Stackoverflow.com/users/162094', 'pm_score': 1, 'selected': False, 'text': '<p>There are two parts to this question. You need to somehow (1) generate an iterator (or rather, an iterable sequence) over you map\'s <em>values</em> (not keys), and (2) use a macro to do the iteration without a lot of boilerplate.</p>\n\n<p>The cleanest solution is to use a <a href="http://www.boost.org/doc/libs/1_47_0/libs/range/doc/html/index.html" rel="nofollow">Boost Range</a> <a href="http://www.boost.org/doc/libs/1_47_0/libs/range/doc/html/range/reference/adaptors/introduction.html" rel="nofollow">Adaptor</a> for part (1) and <a href="http://www.boost.org/doc/libs/1_47_0/doc/html/foreach.html" rel="nofollow">Boost Foreach</a> for part (2). You don\'t need to write the macro or implement the iterator yourself.</p>\n\n<pre><code>#include &lt;map&gt;\n#include &lt;string&gt;\n#include &lt;boost/range/adaptor/map.hpp&gt;\n#include &lt;boost/foreach.hpp&gt;\n\nint main()\n{\n // Sample data\n std::map&lt;int, std::string&gt; myMap ;\n myMap[0] = "Zero" ;\n myMap[10] = "Ten" ;\n myMap[20] = "Twenty" ;\n\n // Loop over map values\n BOOST_FOREACH( std::string text, myMap | boost::adaptors::map_values )\n {\n std::cout &lt;&lt; text &lt;&lt; " " ;\n }\n}\n// Output:\n// Zero Ten Twenty\n</code></pre>\n'}, {'answer_id': 11972376, 'author': 'marko.ristin', 'author_id': 1600678, 'author_profile': 'https://Stackoverflow.com/users/1600678', 'pm_score': 0, 'selected': False, 'text': '<p>I implemented my own <code>foreach_value</code> based on the <code>Boost</code> <code>foreach</code> code:</p>\n\n<pre><code>#include &lt;boost/preprocessor/cat.hpp&gt;\n#define MUNZEKONZA_FOREACH_IN_MAP_ID(x) BOOST_PP_CAT(x, __LINE__)\n\nnamespace munzekonza {\nnamespace foreach_in_map_private {\ninline bool set_false(bool&amp; b) {\n b = false;\n return false;\n}\n\n}\n}\n\n#define MUNZEKONZA_FOREACH_VALUE(value, map) \\\nfor(auto MUNZEKONZA_FOREACH_IN_MAP_ID(_foreach_in_map_it) = map.begin(); \\\n MUNZEKONZA_FOREACH_IN_MAP_ID(_foreach_in_map_it) != map.end();) \\\nfor(bool MUNZEKONZA_FOREACH_IN_MAP_ID(_foreach_in_map_continue) = true; \\\n MUNZEKONZA_FOREACH_IN_MAP_ID(_foreach_in_map_continue) &amp;&amp; \\\n MUNZEKONZA_FOREACH_IN_MAP_ID(_foreach_in_map_it) != map.end(); \\\n (MUNZEKONZA_FOREACH_IN_MAP_ID(_foreach_in_map_continue)) ? \\\n ((void)++MUNZEKONZA_FOREACH_IN_MAP_ID(_foreach_in_map_it)) : \\\n (void)0) \\\n if( munzekonza::foreach_in_map_private::set_false( \\\n MUNZEKONZA_FOREACH_IN_MAP_ID(_foreach_in_map_continue))) {} else \\\n for( value = MUNZEKONZA_FOREACH_IN_MAP_ID(_foreach_in_map_it)-&gt;second; \\\n !MUNZEKONZA_FOREACH_IN_MAP_ID(_foreach_in_map_continue); \\\n MUNZEKONZA_FOREACH_IN_MAP_ID(_foreach_in_map_continue) = true) \n</code></pre>\n\n<p>For example, you can use it in your code like this:</p>\n\n<pre><code>#define MUNZEKONZA_FOREACH_VALUE foreach_value\n\nstd::map&lt;int, std::string&gt; mymap;\n// populate the map ...\n\nforeach_value( const std::string&amp; value, mymap ) {\n // do something with value\n}\n\n// change value\nforeach_value( std::string&amp; value, mymap ) {\n value = "hey";\n}\n</code></pre>\n'}, {'answer_id': 41991034, 'author': 'Zoltán Horváth', 'author_id': 7503044, 'author_profile': 'https://Stackoverflow.com/users/7503044', 'pm_score': 0, 'selected': False, 'text': '<pre><code>#define zforeach(var, container) for(auto var = (container).begin(); var != (container).end(); ++var)\n</code></pre>\n\n<p>there is no typeof() so you can use this:</p>\n\n<pre><code>decltype((container).begin()) var \ndecltype(container)::iterator var\n</code></pre>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78717', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14528/']
78,723
<p>Considering such code:</p> <pre><code>class ToBeTested { public: void doForEach() { for (vector&lt;Contained&gt;::iterator it = m_contained.begin(); it != m_contained.end(); it++) { doOnce(*it); doTwice(*it); doTwice(*it); } } void doOnce(Contained &amp; c) { // do something } void doTwice(Contained &amp; c) { // do something } // other methods private: vector&lt;Contained&gt; m_contained; } </code></pre> <p>I want to test that if I fill vector with 3 values my functions will be called in proper order and quantity. For example my test can look something like this:</p> <pre><code>tobeTested.AddContained(one); tobeTested.AddContained(two); tobeTested.AddContained(three); BEGIN_PROC_TEST() SHOULD_BE_CALLED(doOnce, 1) SHOULD_BE_CALLED(doTwice, 2) SHOULD_BE_CALLED(doOnce, 1) SHOULD_BE_CALLED(doTwice, 2) SHOULD_BE_CALLED(doOnce, 1) SHOULD_BE_CALLED(doTwice, 2) tobeTested.doForEach() END_PROC_TEST() </code></pre> <p>How do you recommend to test this? Are there any means to do this with CppUnit or GoogleTest frameworks? Maybe some other unit test framework allow to perform such tests?</p> <p>I understand that probably this is impossible without calling any debug functions from these functions, but at least can it be done automatically in some test framework. I don't like to scan trace logs and check their correctness.</p> <p><em>UPD</em>: I'm trying to check not only the <strong>state</strong> of an objects, but also the <strong>execution order</strong> to avoid performance issues on the earliest possible stage (and in general I want to know that my code is executed exactly as I expected).</p>
[{'answer_id': 78764, 'author': 'Doug R', 'author_id': 3271, 'author_profile': 'https://Stackoverflow.com/users/3271', 'pm_score': 0, 'selected': False, 'text': '<p>Some mocking frameworks allow you to set up ordered expectations, which lets you say exactly which function calls you expect in a certain order. For example, <a href="http://www.ayende.com/projects/rhino-mocks.aspx" rel="nofollow noreferrer">RhinoMocks</a> for C# allows this.</p>\n\n<p>I am not a C++ coder so I\'m not aware of what\'s available for C++, but that\'s one type of tool that might allow what you\'re trying to do.</p>\n'}, {'answer_id': 78775, 'author': 'Tyler', 'author_id': 3561, 'author_profile': 'https://Stackoverflow.com/users/3561', 'pm_score': 1, 'selected': False, 'text': '<p>You could check out <a href="http://mockpp.sourceforge.net/" rel="nofollow noreferrer">mockpp</a>.</p>\n'}, {'answer_id': 78810, 'author': 'kbaribeau', 'author_id': 8085, 'author_profile': 'https://Stackoverflow.com/users/8085', 'pm_score': 2, 'selected': False, 'text': "<p>You should be able to use any good mocking framework to verify that calls to a collaborating object are done in a specific order.</p>\n\n<p>However, you don't generally test that one method makes some calls to other methods on the same class... why would you?</p>\n\n<p>Generally, when you're testing a class, you only care about testing its publicly visible state. If you test\nanything else, your tests will prevent you from refactoring later.</p>\n\n<p>I could provide more help, but I don't think your example is consistent (Where is the implementation for the AddContained method?).</p>\n"}, {'answer_id': 78861, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-au/magazine/cc301356.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-au/magazine/cc301356.aspx</a></p>\n\n<p>This is a good article about Context Bound Objects. It contains some so advanced stuff, but if you are not lazy and really want to understand this kind of things it will be really helpful.</p>\n\n<p>At the end you will be able to write something like:\n[CallTracingAttribute()]\npublic class TraceMe : ContextBoundObject\n{...}</p>\n'}, {'answer_id': 78901, 'author': 'metao', 'author_id': 11484, 'author_profile': 'https://Stackoverflow.com/users/11484', 'pm_score': 1, 'selected': False, 'text': '<p>Instead of trying to figure out how many functions were called, and in what order, find a set of inputs that can only produce an expected output if you call things in the right order.</p>\n'}, {'answer_id': 78902, 'author': 'metao', 'author_id': 11484, 'author_profile': 'https://Stackoverflow.com/users/11484', 'pm_score': 0, 'selected': False, 'text': '<p>You could use ACE (or similar) debug frameworks, and in your test, configure the debug object to stream to a file. Then you just need to check the file.</p>\n'}, {'answer_id': 79169, 'author': 'kbaribeau', 'author_id': 8085, 'author_profile': 'https://Stackoverflow.com/users/8085', 'pm_score': 2, 'selected': True, 'text': "<p>If you're interested in performance, I recommend that you write a test that measures performance.</p>\n\n<p>Check the current time, run the method you're concerned about, then check the time again. Assert that the total time taken is less than some value.</p>\n\n<p>The problem with check that methods are called in a certain order is that your code is going to have to change, and you don't want to have to update your tests when that happens. You should focus on testing the <em>actual requirement</em> instead of testing the implementation detail that meets that requirement.</p>\n\n<p>That said, if you really want to test that your methods are called in a certain order, you'll need to do the following:</p>\n\n<ol>\n<li>Move them to another class, call it Collaborator</li>\n<li>Add an instance of this other class to the ToBeTested class</li>\n<li>Use a mocking framework to set the instance variable on ToBeTested to be a mock of the Collborator class</li>\n<li>Call the method under test</li>\n<li>Use your mocking framework to assert that the methods were called on your mock in the correct order.</li>\n</ol>\n\n<p>I'm not a native cpp speaker so I can't comment on which mocking framework you should use, but I see some other commenters have added their suggestions on this front.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/78723', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14535/']
78,752
<p>I have read that using database keys in a URL is a bad thing to do.</p> <p>For instance,</p> <p>My table has 3 fields: <code>ID:int</code>, <code>Title:nvarchar(5)</code>, <code>Description:Text</code></p> <p>I want to create a page that displays a record. Something like ...</p> <pre><code>http://server/viewitem.aspx?id=1234 </code></pre> <ol> <li><p>First off, could someone elaborate on why this is a bad thing to do?</p></li> <li><p>and secondly, what are some ways to work around using primary keys in a url?</p></li> </ol>
[{'answer_id': 78760, 'author': 'Aaron Jensen', 'author_id': 11229, 'author_profile': 'https://Stackoverflow.com/users/11229', 'pm_score': 0, 'selected': False, 'text': "<p>It's a bit pedantic at times, but you want to use a unique business identifier for things rather than the surrogate key. </p>\n\n<p>It can be as simple as ItemNumber instead of Id. </p>\n\n<p>The Id is a db concern, not a business/user concern.</p>\n"}, {'answer_id': 78768, 'author': 'mopoke', 'author_id': 14054, 'author_profile': 'https://Stackoverflow.com/users/14054', 'pm_score': 3, 'selected': True, 'text': '<p>I think it\'s perfectly reasonable to use primary keys in the URL.</p>\n\n<p>Some considerations, however:</p>\n\n<p>1) Avoid SQL injection attacks. If you just blindly accept the value of the id URL parameter and pass it into the DB, you are at risk. Make sure you sanitise the input so that it matches whatever format of key you have (e.g. strip any non-numeric characters).</p>\n\n<p>2) SEO. It helps if your URL contains some context about the item (e.g. "big fluffy rabbit" rather than 1234). This helps search engines see that your page is relevant. It can also be useful for your users (I can tell from my browser history which record is which without having to remember a number).</p>\n'}, {'answer_id': 78770, 'author': 'Don Neufeld', 'author_id': 13097, 'author_profile': 'https://Stackoverflow.com/users/13097', 'pm_score': 2, 'selected': False, 'text': "<p>It's not inherently a bad thing to do, but it has some caveats.</p>\n\n<p>Caveat one is that someone can type in different keys and maybe pull up data you didn't want / expect them to get at. You can reduce the chance that this is successful by increasing your key space (for example making ids random 64 bit numbers).</p>\n\n<p>Caveat two is that if you're running a public service and you have competitors they may be able to extract business information from your keys if they are monotonic. Example: create a post today, create a post in a week, compare Ids and you have extracted the rate at which posts are being made.</p>\n\n<p>Caveat three is that it's prone to SQL injection attacks. But you'd never make those mistakes, right?</p>\n"}, {'answer_id': 78779, 'author': 'David Medinets', 'author_id': 219658, 'author_profile': 'https://Stackoverflow.com/users/219658', 'pm_score': 0, 'selected': False, 'text': "<ol>\n<li>Using integer primary keys in a URL is a security risk. It is quite easy for someone to post using any number. For example, through normal web application use, the user creates a user record with an ID of 45 (viewitem/id/45). This means the user automatically knows there are 44 other users. And unless you have a correct authorization system in place they can see the other user's information by created their own url (viewitem/id/32).</li>\n</ol>\n\n<p>2a. Use proper authorization.\n2b. Use GUIDs for primary keys.</p>\n"}, {'answer_id': 78796, 'author': 'Arthur Thomas', 'author_id': 14009, 'author_profile': 'https://Stackoverflow.com/users/14009', 'pm_score': 0, 'selected': False, 'text': '<p>showing the key itself isn\'t inherently bad because it holds no real meaning, but showing the means to obtain access to an item is bad.</p>\n\n<p>for instance say you had an online store that sold stuff from 2 merchants. Merchant A had items (1, 3, 5, 7) and Merchant B has items (2, 4, 5, 8). </p>\n\n<p>If I am shopping on Merchant A\'s site and see:\n<a href="http://server/viewitem.aspx?id=1" rel="nofollow noreferrer">http://server/viewitem.aspx?id=1</a></p>\n\n<p>I could then try to fiddle with it and type:\n<a href="http://server/viewitem.aspx?id=2" rel="nofollow noreferrer">http://server/viewitem.aspx?id=2</a></p>\n\n<p>That might let me access an item that I shouldn\'t be accessing since I am shopping with Merchant A and not B. In general allowing users to fiddle with stuff like that can lead to security problems. Another brief example is employees that can look at their personal information (id=382) but they type in someone else id to go directly to someone else profile.</p>\n\n<p>Now, having said that.. this is not bad as long as security checks are built into the system that check to make sure people are doing what they are supposed to (ex: not shopping with another merchant or not viewing another employee).</p>\n\n<p>One mechanism is to store information in sessions, but some do not like that. I am not a web programmer so I will not go into that :) </p>\n\n<p>The main thing is to make sure the system is secure. Never trust data that came back from the user.</p>\n'}, {'answer_id': 78814, 'author': 'mislav', 'author_id': 11687, 'author_profile': 'https://Stackoverflow.com/users/11687', 'pm_score': 1, 'selected': False, 'text': '<p>Using IDs in the URL is not necessarily bad. This site uses it, despite being done by professionals.</p>\n\n<p>How can they be dangerous? When users are allowed to update or delete entries belonging to them, developers implement some sort of authentication, but <em>they often forget</em> to check if the entry really <strong>belongs</strong> to you. A malicious user could form a URL like <code>"/questions/12345/delete"</code> when he notices that "12345" belongs to you, and it would be deleted.</p>\n\n<p>Programmers should ensure that a database entry with an arbitrary ID really belongs to the current logged-in user before performing such operation.</p>\n\n<p><strong>Sometimes there are strong reasons to avoid exposing IDs in the URL.</strong> In such cases, developers often generate random <em>hashes</em> that they store for each entry and use those in the URL. A malicious person tampering in the URL bar would have a hard time guessing a hash that would belong to some other user.</p>\n'}, {'answer_id': 78836, 'author': 'John Virgolino', 'author_id': 4246, 'author_profile': 'https://Stackoverflow.com/users/4246', 'pm_score': 1, 'selected': False, 'text': "<p>Security and privacy are the main reasons to avoid doing this. Any information that gives away your data structure is more information that a hacker can use to access your database. As mopoke says, you also expose yourself to SQL injection attacks which are fairly common and can be extremely harmful to your database and application. From a privacy standpoint, if you are displaying any information that is sensitive or personal, anybody can just substitute a number to retrieve information and if you have no mechanism for authentication, you could be putting your information at risk. Also, if it's that easy to query your database, you open yourself up to Denial of Service attacks with someone just looping through URL's against your server since they know each one will get a response.</p>\n\n<p>Regardless of the nature of the data, I tend to recommend against sharing anything in the URL that could give away anything about your application's architecture, it seems to me you are just inviting trouble (I feel the same way about hidden fields which aren't really hidden).</p>\n\n<p>To get around it, we usaully encrypt the parameters before passing them. In some cases, the encyrpted URL also includes some form of verification/authentication mechanism so the server can decide if it's ok to process.</p>\n\n<p>Of course every application is different and the level of security you want to implement has to be balanced with functionality, budget, performance, etc. But I don't see anything wrong with being paranoid when it comes to data security.</p>\n"}, {'answer_id': 78922, 'author': 'Kibbee', 'author_id': 1862, 'author_profile': 'https://Stackoverflow.com/users/1862', 'pm_score': 0, 'selected': False, 'text': '<p>Everybody seems to be posting the "problems" with using this technique, but I haven\'t seen any solutions. What are the alternatives. There has to be something in the URL that uniquely defines what you want to display to the user. The only other solution I can think of would be to run your entire site off forms, and have the browser post the value to the server. This is a little trickier to code, as all links need to be form submits. Also, it\'s only minimally harder for users of the site to put in whatever value they wish. Also this wouldn\'t allow the user to bookmark anything, which is a major disadvantage.</p>\n\n<p>@John Virgolino mentioned encrypting the entire query string, which could help with this process. However it seems like going a little too far for most applications. </p>\n'}, {'answer_id': 953950, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve been reading about this, looking for a solution, but as @Kibbee says there is no real consensus.</p>\n\n<p>I can think of a few possible solutions:</p>\n\n<p>1) If your table uses integer keys (likely), add a check-sum digit to the identifier. That way, (simple) injection attacks will usually fail. On receiving the request, simply remove the check-sum digit and check that it still matches - if they don\'t then you know the URL has been tampered with. This method also hides your "rate of growth" (somewhat).</p>\n\n<p>2) When storing the DB record initially, save a "secondary key" or value that you are happy to be a public id. This has to be unique and usually not sequential - examples are a UUID/Guid or a hash (MD5) of the integer ID e.g. <a href="http://server/item.aspx?id=AbD3sTGgxkjero" rel="nofollow noreferrer">http://server/item.aspx?id=AbD3sTGgxkjero</a> (but be careful of characters that are not compatible with http). Nb. the secondary field will need to be indexed, and you will lose benefits of clustering that you get in 1).</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78752', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14396/']
78,757
<p>How can I programmatically make a query in MS Access default to landscape when printed, specifically when viewing it as a PivotChart? I'm currently attempting this in MS Access 2003, but would like to see a solution for any version.</p>
[{'answer_id': 79635, 'author': 'ahockley', 'author_id': 8209, 'author_profile': 'https://Stackoverflow.com/users/8209', 'pm_score': 3, 'selected': True, 'text': '<p>The following function should do the trick:</p>\n\n<pre><code>Function SetLandscape()\n Application.Printer.Orientation = acPRORLandscape\nEnd Function\n</code></pre>\n\n<p>Should be able to call this from the autoexec function to ensure it always runs.</p>\n'}, {'answer_id': 79740, 'author': 'Brettski', 'author_id': 5836, 'author_profile': 'https://Stackoverflow.com/users/5836', 'pm_score': 0, 'selected': False, 'text': '<p>Yes ahockley\'s call sets the application\'s printer orientation to landscape. I tried an experiment and it worked well. I know this doesn\'t produce a pivot table, but I didn\'t setup one to use, so it opens and prints a regular query. </p>\n\n<pre><code>Private sub\n Application.Printer.Orientation = acPRORLandscape\n DoCmd.OpenQuery "qry1", acViewNormal, acReadOnly\n DoCmd.PrintOut acPrintAll\nEnd Sub\n</code></pre>\n\n<p>If you want to close the query after printing it, add:</p>\n\n<pre><code>docmd.Close acQuery, "qry1", acSaveNo\n</code></pre>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78757', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3155/']
78,799
<p>What I'm talking about here are nested classes. Essentially, I have two classes that I'm modeling. A DownloadManager class and a DownloadThread class. The obvious OOP concept here is composition. However, composition doesn't necessarily mean nesting, right?</p> <p>I have code that looks something like this:</p> <pre><code>class DownloadThread: def foo(self): pass class DownloadManager(): def __init__(self): dwld_threads = [] def create_new_thread(): dwld_threads.append(DownloadThread()) </code></pre> <p>But now I'm wondering if there's a situation where nesting would be better. Something like:</p> <pre><code>class DownloadManager(): class DownloadThread: def foo(self): pass def __init__(self): dwld_threads = [] def create_new_thread(): dwld_threads.append(DownloadManager.DownloadThread()) </code></pre>
[{'answer_id': 78858, 'author': 'dF.', 'author_id': 3002, 'author_profile': 'https://Stackoverflow.com/users/3002', 'pm_score': 8, 'selected': True, 'text': '<p>You might want to do this when the "inner" class is a one-off, which will never be used outside the <em>definition</em> of the outer class. For example to use a metaclass, it\'s sometimes handy to do</p>\n\n<pre><code>class Foo(object):\n class __metaclass__(type):\n .... \n</code></pre>\n\n<p>instead of defining a metaclass separately, if you\'re only using it once.</p>\n\n<p>The only other time I\'ve used nested classes like that, I used the outer class only as a namespace to group a bunch of closely related classes together:</p>\n\n<pre><code>class Group(object):\n class cls1(object):\n ...\n\n class cls2(object):\n ...\n</code></pre>\n\n<p>Then from another module, you can import Group and refer to these as Group.cls1, Group.cls2 etc. However one might argue that you can accomplish exactly the same (perhaps in a less confusing way) by using a module.</p>\n'}, {'answer_id': 78868, 'author': 'André Chalella', 'author_id': 4850, 'author_profile': 'https://Stackoverflow.com/users/4850', 'pm_score': 5, 'selected': False, 'text': "<p>I don't know Python, but your question seems very general. Ignore me if it's specific to Python.</p>\n\n<p>Class nesting is all about scope. If you think that one class will only make sense in the context of another one, then the former is probably a good candidate to become a nested class.</p>\n\n<p>It is a common pattern make helper classes as private, nested classes.</p>\n"}, {'answer_id': 78968, 'author': 'tim.tadh', 'author_id': 14107, 'author_profile': 'https://Stackoverflow.com/users/14107', 'pm_score': 3, 'selected': False, 'text': "<p>You could be using a class as class generator. Like (in some off the cuff code :)</p>\n\n<pre><code>class gen(object):\n class base_1(object): pass\n ...\n class base_n(object): pass\n\n def __init__(self, ...):\n ...\n def mk_cls(self, ..., type):\n '''makes a class based on the type passed in, the current state of\n the class, and the other inputs to the method'''\n</code></pre>\n\n<p>I feel like when you need this functionality it will be very clear to you. If you don't need to be doing something similar than it probably isn't a good use case.</p>\n"}, {'answer_id': 79094, 'author': 'Jerub', 'author_id': 14648, 'author_profile': 'https://Stackoverflow.com/users/14648', 'pm_score': 3, 'selected': False, 'text': "<p>There is really no benefit to doing this, except if you are dealing with metaclasses.</p>\n\n<p>the class: suite really isn't what you think it is. It is a weird scope, and it does strange things. It really doesn't even make a class! It is just a way of collecting some variables - the name of the class, the bases, a little dictionary of attributes, and a metaclass.</p>\n\n<p>The name, the dictionary and the bases are all passed to the function that is the metaclass, and then it is assigned to the variable 'name' in the scope where the class: suite was.</p>\n\n<p>What you can gain by messing with metaclasses, and indeed by nesting classes within your stock standard classes, is harder to read code, harder to understand code, and odd errors that are terribly difficult to understand without being intimately familiar with why the 'class' scope is entirely different to any other python scope.</p>\n"}, {'answer_id': 49812827, 'author': 'Thomas', 'author_id': 4540266, 'author_profile': 'https://Stackoverflow.com/users/4540266', 'pm_score': 4, 'selected': False, 'text': '<p>There is another usage for nested class, when one wants to construct inherited classes whose enhanced functionalities are encapsulated in a specific nested class.</p>\n\n<p>See this example:</p>\n\n<pre><code>class foo:\n\n class bar:\n ... # functionalities of a specific sub-feature of foo\n\n def __init__(self):\n self.a = self.bar()\n ...\n\n ... # other features of foo\n\n\nclass foo2(foo):\n\n class bar(foo.bar):\n ... # enhanced functionalities for this specific feature\n\n def __init__(self):\n foo.__init__(self)\n</code></pre>\n\n<p>Note that in the constructor of <code>foo</code>, the line <code>self.a = self.bar()</code> will construct a <code>foo.bar</code> when the object being constructed is actually a <code>foo</code> object, and a <code>foo2.bar</code> object when the object being constructed is actually a <code>foo2</code> object. </p>\n\n<p>If the class <code>bar</code> was defined outside of class <code>foo</code> instead, as well as its inherited version (which would be called <code>bar2</code> for example), then defining the new class <code>foo2</code> would be much more painful, because the constuctor of <code>foo2</code> would need to have its first line replaced by <code>self.a = bar2()</code>, which implies re-writing the whole constructor. </p>\n'}, {'answer_id': 66900415, 'author': 'Leon Chang', 'author_id': 9749972, 'author_profile': 'https://Stackoverflow.com/users/9749972', 'pm_score': 0, 'selected': False, 'text': "<p>Either way, defined inside or outside of a class, would work. Here is an employee pay schedule program where the helper class EmpInit is embedded inside the class Employee:</p>\n<pre><code>class Employee:\n\n def level(self, j):\n return j * 5E3\n\n def __init__(self, name, deg, yrs):\n self.name = name\n self.deg = deg\n self.yrs = yrs\n self.empInit = Employee.EmpInit(self.deg, self.level)\n self.base = Employee.EmpInit(self.deg, self.level).pay\n\n def pay(self):\n if self.deg in self.base:\n return self.base[self.deg]() + self.level(self.yrs)\n print(f&quot;Degree {self.deg} is not in the database {self.base.keys()}&quot;)\n return 0\n\n class EmpInit:\n\n def __init__(self, deg, level):\n self.level = level\n self.j = deg\n self.pay = {1: self.t1, 2: self.t2, 3: self.t3}\n\n def t1(self): return self.level(1*self.j)\n def t2(self): return self.level(2*self.j)\n def t3(self): return self.level(3*self.j)\n\nif __name__ == '__main__':\n for loop in range(10):\n lst = [item for item in input(f&quot;Enter name, degree and years : &quot;).split(' ')]\n e1 = Employee(lst[0], int(lst[1]), int(lst[2]))\n print(f'Employee {e1.name} with degree {e1.deg} and years {e1.yrs} is making {e1.pay()} dollars')\n print(&quot;EmpInit deg {0}\\nlevel {1}\\npay[deg]: {2}&quot;.format(e1.empInit.j, e1.empInit.level, e1.base[e1.empInit.j]))\n</code></pre>\n<p>To define it outside, just un-indent EmpInit and change Employee.EmpInit() to simply EmpInit() as a regular &quot;has-a&quot; composition. However, since Employee is the controller of EmpInit and users don't instantiate or interface with it directly, it makes sense to define it inside as it is not a standalone class. Also note that the instance method level() is designed to be called in both classes here. Hence it can also be conveniently defined as a static method in Employee so that we don't need to pass it into EmpInit, instead just invoke it with Employee.level().</p>\n"}, {'answer_id': 68819173, 'author': 'kharandziuk', 'author_id': 1907902, 'author_profile': 'https://Stackoverflow.com/users/1907902', 'pm_score': 1, 'selected': False, 'text': '<p>A good use case for this feature is Error/Exception handling, e.g.:</p>\n<pre><code>class DownloadManager(object):\n class DowndloadException(Exception):\n pass\n\n def download(self):\n ...\n</code></pre>\n<p>Now the one who is reading the code knows all the possible exceptions related to this class.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78799', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10708/']
78,801
<p>Running a rails site right now using SQLite3.</p> <p>About once every 500 requests or so, I get a</p> <p>ActiveRecord::StatementInvalid (SQLite3::BusyException: database is locked:...</p> <p>What's the way to fix this that would be minimally invasive to my code?</p> <p>I'm using SQLLite at the moment because you can store the DB in source control which makes backing up natural and you can push changes out very quickly. However, it's obviously not really set up for concurrent access. I'll migrate over to MySQL tomorrow morning.</p>
[{'answer_id': 78817, 'author': 'Sargun Dhillon', 'author_id': 10432, 'author_profile': 'https://Stackoverflow.com/users/10432', 'pm_score': -1, 'selected': False, 'text': '<p>I believe this happens when a transaction times out. You really should be using a "real" database. Something like Drizzle, or MySQL. Any reason why you prefer SQLite over the two prior options? </p>\n'}, {'answer_id': 78870, 'author': 'Brian R. Bondy', 'author_id': 3153, 'author_profile': 'https://Stackoverflow.com/users/3153', 'pm_score': 0, 'selected': False, 'text': '<p>Source: <a href="http://nessie.de/mroth/lua-sqlite3/documentation.html" rel="nofollow noreferrer">this link</a></p>\n\n<pre><code>- Open the database\ndb = sqlite3.open("filename")\n\n-- Ten attempts are made to proceed, if the database is locked\nfunction my_busy_handler(attempts_made)\n if attempts_made &lt; 10 then\n return true\n else\n return false\n end\nend\n\n-- Set the new busy handler\ndb:set_busy_handler(my_busy_handler)\n\n-- Use the database\ndb:exec(...)\n</code></pre>\n'}, {'answer_id': 78881, 'author': 'David Medinets', 'author_id': 219658, 'author_profile': 'https://Stackoverflow.com/users/219658', 'pm_score': 0, 'selected': False, 'text': '<p>What table is being accessed when the lock is encountered?</p>\n\n<p>Do you have long-running transactions?</p>\n\n<p>Can you figure out which requests were still being processed when the lock was encountered?</p>\n'}, {'answer_id': 78958, 'author': 'Voltaire', 'author_id': 14621, 'author_profile': 'https://Stackoverflow.com/users/14621', 'pm_score': 0, 'selected': False, 'text': "<p>Argh - the bane of my existence over the last week. Sqlite3 locks the db file when any process <em>writes</em> to the database. IE any UPDATE/INSERT type query (also select count(*) for some reason). However, it handles multiple reads just fine.</p>\n\n<p>So, I finally got frustrated enough to write my own thread locking code around the database calls. By ensuring that the application can only have one thread writing to the database at any point, I was able to scale to 1000's of threads.</p>\n\n<p>And yea, its slow as hell. But its also fast enough and <em>correct</em>, which is a nice property to have.</p>\n"}, {'answer_id': 95255, 'author': 'ravenspoint', 'author_id': 16582, 'author_profile': 'https://Stackoverflow.com/users/16582', 'pm_score': 4, 'selected': True, 'text': '<p>By default, sqlite returns immediatly with a blocked, busy error if the database is busy and locked. You can ask for it to wait and keep trying for a while before giving up. This usually fixes the problem, unless you do have 1000s of threads accessing your db, when I agree sqlite would be inappropriate.</p>\n\n<pre>\n // set SQLite to wait and retry for up to 100ms if database locked\n sqlite3_busy_timeout( db, 100 );\n</pre>\n'}, {'answer_id': 739037, 'author': 'Rifkin Habsburg', 'author_id': 89619, 'author_profile': 'https://Stackoverflow.com/users/89619', 'pm_score': 6, 'selected': False, 'text': '<p>You mentioned that this is a Rails site. Rails allows you to set the SQLite retry timeout in your database.yml config file:</p>\n\n<pre><code>production:\n adapter: sqlite3\n database: db/mysite_prod.sqlite3\n timeout: 10000\n</code></pre>\n\n<p>The timeout value is specified in miliseconds. Increasing it to 10 or 15 seconds should decrease the number of BusyExceptions you see in your log.</p>\n\n<p>This is just a temporary solution, though. If your site needs true concurrency then you will have to migrate to another db engine.</p>\n'}, {'answer_id': 739472, 'author': 'alfredodeza', 'author_id': 89528, 'author_profile': 'https://Stackoverflow.com/users/89528', 'pm_score': 1, 'selected': False, 'text': "<p>Sqlite can allow other processes to wait until the current one finished.</p>\n\n<p>I use this line to connect when I know I may have multiple processes trying to access the Sqlite DB:</p>\n\n<p>conn = sqlite3.connect('filename', <strong>isolation_level = 'exclusive'</strong>)</p>\n\n<p>According to the Python Sqlite Documentation:</p>\n\n<blockquote>\n <p>You can control which kind of BEGIN\n statements pysqlite implicitly\n executes (or none at all) via the\n isolation_level parameter to the\n connect() call, or via the\n isolation_level property of\n connections.</p>\n</blockquote>\n"}, {'answer_id': 4226570, 'author': 'ybakos', 'author_id': 129622, 'author_profile': 'https://Stackoverflow.com/users/129622', 'pm_score': 2, 'selected': False, 'text': "<p>All of these things are true, but it doesn't answer the question, which is likely: why does my Rails app occasionally raise a SQLite3::BusyException in production?</p>\n\n<p>@Shalmanese: what is the production hosting environment like? Is it on a shared host? Is the directory that contains the sqlite database on an NFS share? (Likely, on a shared host).</p>\n\n<p>This problem likely has to do with the phenomena of file locking w/ NFS shares and SQLite's lack of concurrency.</p>\n"}, {'answer_id': 5112460, 'author': 'meredrica', 'author_id': 633375, 'author_profile': 'https://Stackoverflow.com/users/633375', 'pm_score': 1, 'selected': False, 'text': '<p>I had a similar problem with rake db:migrate. Issue was that the working directory was on a SMB share.\nI fixed it by copying the folder over to my local machine.</p>\n'}, {'answer_id': 6099601, 'author': 'Ignacio Huerta', 'author_id': 766296, 'author_profile': 'https://Stackoverflow.com/users/766296', 'pm_score': 2, 'selected': False, 'text': '<p>Just for the record. In one application with Rails 2.3.8 we found out that Rails was ignoring the "timeout" option Rifkin Habsburg suggested.</p>\n\n<p>After some more investigation we found a possibly related bug in Rails dev: <a href="http://dev.rubyonrails.org/ticket/8811" rel="nofollow">http://dev.rubyonrails.org/ticket/8811</a>. And after some more investigation we found <a href="http://webcache.googleusercontent.com/search?q=cache:6_UlZMo3eH4J:https://rails.lighthouseapp.com/projects/8994/tickets/5941+ActiveRecord+SQLite3+BusyException&amp;cd=10&amp;hl=en&amp;ct=clnk&amp;client=ubuntu&amp;source=www.google.com" rel="nofollow">the solution</a> (tested with Rails 2.3.8):</p>\n\n<p>Edit this ActiveRecord file: activerecord-2.3.8/lib/active_record/connection_adapters/sqlite_adapter.rb</p>\n\n<p>Replace this:</p>\n\n\n\n<pre class="lang-rb prettyprint-override"><code> def begin_db_transaction #:nodoc:\n catch_schema_changes { @connection.transaction }\n end\n</code></pre>\n\n<p>with</p>\n\n\n\n<pre class="lang-rb prettyprint-override"><code> def begin_db_transaction #:nodoc:\n catch_schema_changes { @connection.transaction(:immediate) }\n end\n</code></pre>\n\n<p>And that\'s all! We haven\'t noticed a performance drop and now the app supports many more petitions without breaking (it waits for the timeout). Sqlite is nice!</p>\n'}, {'answer_id': 13189516, 'author': 'xijing dai', 'author_id': 628568, 'author_profile': 'https://Stackoverflow.com/users/628568', 'pm_score': 0, 'selected': False, 'text': '<p>I found a deadlock on sqlite3 ruby extension and fix it here: have a go with it and see if this fixes ur problem. </p>\n\n<pre>\n\n https://github.com/dxj19831029/sqlite3-ruby\n\n</pre>\n\n<p>I opened a pull request, no response from them anymore.</p>\n\n<p>Anyway, some busy exception is expected as described in sqlite3 itself. </p>\n\n<p><strong>Be aware</strong> with this condition: <a href="http://www.sqlite.org/c3ref/busy_handler.html" rel="nofollow">sqlite busy</a></p>\n\n<pre>\n\n The presence of a busy handler does not guarantee that it will be invoked when there is \n lock contention. If SQLite determines that invoking the busy handler could result in a \n deadlock, it will go ahead and return SQLITE_BUSY or SQLITE_IOERR_BLOCKED instead of \n invoking the busy handler. Consider a scenario where one process is holding a read lock \n that it is trying to promote to a reserved lock and a second process is holding a reserved \n lock that it is trying to promote to an exclusive lock. The first process cannot proceed \n because it is blocked by the second and the second process cannot proceed because it is \n blocked by the first. If both processes invoke the busy handlers, neither will make any \n progress. Therefore, SQLite returns SQLITE_BUSY for the first process, hoping that this \n will induce the first process to release its read lock and allow the second process to \n proceed.\n\n</pre>\n\n<p>If you meet this condition, timeout isn\'t valid anymore. To avoid it, don\'t put select inside begin/commit. or use exclusive lock for begin/commit.</p>\n\n<p>Hope this helps. :)</p>\n'}, {'answer_id': 14625992, 'author': 'Anno2001', 'author_id': 1201015, 'author_profile': 'https://Stackoverflow.com/users/1201015', 'pm_score': 0, 'selected': False, 'text': '<p>this is often a consecutive fault of multiple processes accessing the same database, i.e. if the "allow only one instance" flag was not set in RubyMine</p>\n'}, {'answer_id': 26150137, 'author': 'Adrien Jarthon', 'author_id': 304434, 'author_profile': 'https://Stackoverflow.com/users/304434', 'pm_score': 2, 'selected': False, 'text': '<p>If you have this issue but <strong>increasing the timeout does not change anything</strong>, you might have another concurrency issue with transactions, here is it in summary:</p>\n\n<ol>\n<li>Begin a transaction (aquires a <em>SHARED</em> lock)</li>\n<li>Read some data from DB (we are still using the <em>SHARED</em> lock)</li>\n<li>Meanwhile, another process starts a transaction and write data (acquiring the <em>RESERVED</em> lock).</li>\n<li>Then you try to write, you are now trying to request the <em>RESERVED</em> lock</li>\n<li>SQLite raises the SQLITE_BUSY exception <strong>immediately</strong> (indenpendently of your timeout) because your previous reads may no longer be accurate by the time it can get the <em>RESERVED</em> lock.</li>\n</ol>\n\n<p>One way to fix this is to patch the <code>active_record</code> sqlite adapter to aquire a <em>RESERVED</em> lock directly at the begining of the transaction by padding the <code>:immediate</code> option to the driver. This will decrease performance a bit, but at least all your transactions will honor your timeout and occurs one after the other. Here is how to do this using <code>prepend</code> (Ruby 2.0+) put this in a initializer:</p>\n\n<pre><code>module SqliteTransactionFix\n def begin_db_transaction\n log(\'begin immediate transaction\', nil) { @connection.transaction(:immediate) }\n end\nend\n\nmodule ActiveRecord\n module ConnectionAdapters\n class SQLiteAdapter &lt; AbstractAdapter\n prepend SqliteTransactionFix\n end\n end\nend\n</code></pre>\n\n<p>Read more here: <a href="https://rails.lighthouseapp.com/projects/8994/tickets/5941-sqlite3busyexceptions-are-raised-immediately-in-some-cases-despite-setting-sqlite3_busy_timeout" rel="nofollow">https://rails.lighthouseapp.com/projects/8994/tickets/5941-sqlite3busyexceptions-are-raised-immediately-in-some-cases-despite-setting-sqlite3_busy_timeout</a></p>\n'}, {'answer_id': 28494279, 'author': 'Balaji Radhakrishnan', 'author_id': 3930758, 'author_profile': 'https://Stackoverflow.com/users/3930758', 'pm_score': 2, 'selected': False, 'text': '<pre><code>bundle exec rake db:reset\n</code></pre>\n\n<p>It worked for me it will reset and show the pending migration.</p>\n'}, {'answer_id': 28494445, 'author': 'John', 'author_id': 3525295, 'author_profile': 'https://Stackoverflow.com/users/3525295', 'pm_score': 0, 'selected': False, 'text': '<p>Try running the following, it may help: </p>\n\n<pre><code>ActiveRecord::Base.connection.execute("BEGIN TRANSACTION; END;") \n</code></pre>\n\n<p>From: <a href="https://stackoverflow.com/questions/7154664/ruby-sqlite3busyexception-database-is-locked">Ruby: SQLite3::BusyException: database is locked:</a></p>\n\n<p>This may clear up the any transaction holding up the system</p>\n'}, {'answer_id': 47793885, 'author': 'Elindor', 'author_id': 3443954, 'author_profile': 'https://Stackoverflow.com/users/3443954', 'pm_score': 1, 'selected': False, 'text': '<p>Most answers are for Rails rather than raw ruby, and OPs question IS for rails, which is fine. :)</p>\n\n<p>So I just want to leave this solution over here should any raw ruby user have this problem, and is not using a yml configuration.</p>\n\n<p>After instancing the connection, you can set it like this:</p>\n\n<pre><code>db = SQLite3::Database.new "#{path_to_your_db}/your_file.db"\ndb.busy_timeout=(15000) # in ms, meaning it will retry for 15 seconds before it raises an exception.\n#This can be any number you want. Default value is 0.\n</code></pre>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78801', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14559/']
78,806
<blockquote> <p>Where a new system concept or new technology is used, one has to build a system to throw away, for even the best planning is not so omniscient as to get it right the first time. Hence <strong>plan to throw one away; you will, anyhow.</strong></p> <p>-- Fred Brooks, <a href="http://en.wikipedia.org/wiki/The_Mythical_Man-Month" rel="noreferrer"><em>The Mythical Man-Month</em></a> [Emphasis mine]</p> </blockquote> <p>Build one to throw away. That's what they told me. Then they told me that we're all <a href="http://agilemanifesto.org/" rel="noreferrer">agile</a> now, so we should <a href="http://c2.com/cgi/wiki?RefactorMercilessly" rel="noreferrer">Refactor Mercilessly</a>. What gives?</p> <p>Is it <strong>always</strong> better to refactor my way out of trouble? If not, can anyone suggest a rule-of-thumb to help me decide when to stick with it, and when to give up and start over?</p>
[{'answer_id': 78827, 'author': 'Chris Upchurch', 'author_id': 2600, 'author_profile': 'https://Stackoverflow.com/users/2600', 'pm_score': 3, 'selected': False, 'text': "<p>If you're merciless enough, the end result of refactoring will be pretty close to what you'd have gotten if you rebuilt from scratch, but you won't have been stuck with a non-working system during the process.</p>\n"}, {'answer_id': 78843, 'author': 'scubabbl', 'author_id': 9450, 'author_profile': 'https://Stackoverflow.com/users/9450', 'pm_score': 1, 'selected': False, 'text': "<p>I'll prototype when I'm trying to work out a new problem or functionality. After than, I'll rebuild it based on what I learned. Actually, that sounds a lot like refactoring... what? Maybe it's the same thing? Hmmm... </p>\n"}, {'answer_id': 78844, 'author': 'emk', 'author_id': 12089, 'author_profile': 'https://Stackoverflow.com/users/12089', 'pm_score': 5, 'selected': True, 'text': "<p>If you're doing test-driven development, you can refactor your way out of almost any trouble. I've changed major design decisions without much trouble, and rescued decade-old codebases.</p>\n\n<p>The only exception is when you've discovered that your architecture is completely wrong from beginning to end. For example, if you wrote your app using threads, but you discovered that you wanted a bunch of asynchronous state machines. At that point, go ahead and throw away the first draft.</p>\n"}, {'answer_id': 78883, 'author': 'metao', 'author_id': 11484, 'author_profile': 'https://Stackoverflow.com/users/11484', 'pm_score': 2, 'selected': False, 'text': "<p>There comes a point where refactoring is a waste of time. You just have to start again from scratch. If you keep your design fairly flexible, and you recognise that you don't know everything just yet, you won't have to throw anything away. A class might become redundant, of course, but you wont throw away a whole system. </p>\n\n<p>Having a flexible design is necessary to be able to refactor properly. Having no design or a rigid design means you WILL end up throwing something away - either because you cannot refactor, or because the constant refactoring degrades the maintainability of your code base. Few humans are meticulous and disciplined enough to be able to complete a long sequence of minor refactorings to maintain integrity. Unless you have an all-star team, this degradation will happen!</p>\n\n<p>TL;DR: You can refactor your way out of most trouble. Occasionally, though, you won't be able to refactor past some design elements. When that happens, it is time to start again - although hopefully you can re-use some of the components you have in place.</p>\n"}, {'answer_id': 79154, 'author': 'Dan Harper', 'author_id': 14530, 'author_profile': 'https://Stackoverflow.com/users/14530', 'pm_score': 1, 'selected': False, 'text': '<p>I think that throwing one away is sometimes the best way to go, but it can hurt. One thing that I\'ve found that works well is to throw one away, but choose your technology well.</p>\n\n<p>For example, I\'ve written a large codebase in Ruby on Rails, and over the past 2-3 years, RoR has advanced a lot. I also made some decisions in architecture that needed to be fixed. So, I\'m throwing one away, and building a new one from scratch. However, I\'m still able to use 70-80% or so of my old code as I\'m still writing in Ruby and Rails. </p>\n\n<p>The major factor that has helped with that is that Rails forces you to write well structured code with separation of business logic and presentation layers. I didn\'t get it perfect the first time around, but since everything is fairly well separated and DRY, porting the code to Rails v2.1, re-architecting the problem areas, and re-writing some "problem" features has been a fairly pain free experience.</p>\n\n<p>So, by choosing a great technology from the start, I\'ve been able to throw one away, but still take with me 70-80% of the old stuff that still works.</p>\n'}, {'answer_id': 79167, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>In a later essay in The Mythical Man Month, Brooks warns that he\'s found that if you do indeed plan to throw 1 away, you\'ll end up throwing 2 away!</p>\n\n<p>I personally saw this happen in real life; we assigned a version 1 of the project as a quick throw-away to a mediocre programmer, because "we plan to throw it away later -- we will anyhow." We ended up having to rewrite it for version 2, but that one got thrown away too. I never saw version 3 - the company went out of business.</p>\n\n<p>I think when Brooks says "plan to throw one away, you will anyway" it\'s more like the statement "the number of bugs remaining to be found is \'n+1\'." That is, it\'s a ha-ha-only-serious statement about Murphy\'s law, rather than practical advice. The lessons to take away from it is that prototypes are valuable, good writing is rewriting, and don\'t be afraid to abandon something that isn\'t working.</p>\n\n<p>However, it has to come down to a judgement call because as Joel Spolsky has talked about in several essays, the option to throw away and start over is tempting because code is easier to write than to read, and more fun to write than to maintain, so your natural inclination will always be to start over even when that isn\'t really the best thing to do.</p>\n'}, {'answer_id': 79374, 'author': 'Paulus', 'author_id': 14209, 'author_profile': 'https://Stackoverflow.com/users/14209', 'pm_score': 4, 'selected': False, 'text': '<h2>Throw away early, refactor later</h2>\n\n<p>Throwing away is OK for small systems, but if the size of the system is huge, you simply do not have the resources to do so. </p>\n\n<p>You could, however, create a small pilot project that implements only the very essential features of the actual project. After some trial and error and learning and throwing away stuff, you end up with a solid core and a better understanding for the actual project. Then you let the size of the project grow, by adding all the features needed. But once you get there, no way you can throw away the core. Only refactoring.</p>\n'}, {'answer_id': 79396, 'author': 'Jeff Heigl', 'author_id': 14649, 'author_profile': 'https://Stackoverflow.com/users/14649', 'pm_score': 2, 'selected': False, 'text': "<p>Different situations require different approaches. Personally I perfer refactoring to a better design whenever possible. Refactoring leads to less bugs than a rewrite.</p>\n\n<p>But, even if you plan to throw one away, its still a good idea to write a bunch of acceptance tests to make sure your 2nd version is on the right track. Then you can migrate towards the next version piece by piece while ensuring your functionality isnt changing from the user's perspective. Sounds a bit like refactoring, just a little sloppier I guess.</p>\n"}, {'answer_id': 79441, 'author': 'kbaribeau', 'author_id': 8085, 'author_profile': 'https://Stackoverflow.com/users/8085', 'pm_score': 2, 'selected': False, 'text': "<p>One of the central points of The Mythical Man Month was that the hard part of software development is figuring out what to say, not how to say it.</p>\n\n<p>The way I've interpreted this recently is that the most value you get out of the first draft is the requirements you've gathered and preserved in the form of tests. If you're careful not to test things that aren't actually requirements of the system, you <em>can</em> refactor your way out of any mess.</p>\n\n<p>So long as you don't code yourself into a trap where you have to start throwing out tests, you are OK to throw out as much code as you want without losing a significant amount of real work.</p>\n"}, {'answer_id': 79494, 'author': 'marcospereira', 'author_id': 4600, 'author_profile': 'https://Stackoverflow.com/users/4600', 'pm_score': 2, 'selected': False, 'text': '<p>When talking about Agile, you could do both, but in a general way, you will do <a href="http://www.extremeprogramming.org/rules/spike.html" rel="nofollow noreferrer">spikes</a> (prototypes) only to try specific issues, learn about them and be able to do better estimates. Throw away when you are doing a simple spike and refactoring when you are really coding the application.</p>\n\n<p>Kind Regards</p>\n'}, {'answer_id': 100977, 'author': 'quamrana', 'author_id': 4834, 'author_profile': 'https://Stackoverflow.com/users/4834', 'pm_score': 2, 'selected': False, 'text': '<p>My general advice here is to refactor an existing system away from its bad designs to a system with better designs. This maintains the system and allows it to be deployed at all times. If you start from scratch it may be a while before you can deploy, or never.</p>\n\n<p>If you are talking about just writing some brand new code where there is no existing system, then quite often its a good idea to write a little bit of code, however you want, then throw that away since it was never deployed and start again (using TDD).</p>\n'}, {'answer_id': 1915867, 'author': 'Kzqai', 'author_id': 69993, 'author_profile': 'https://Stackoverflow.com/users/69993', 'pm_score': 1, 'selected': False, 'text': "<p>I think that your version control system plays a large role here. If you run a distributed version control system with easy branching (git, mercurial, these days), then you'll be able to prototype easier, and refactor easier, all while still having a valid working copy. Anything else requires so much more discipline.</p>\n"}, {'answer_id': 1939503, 'author': 'Xav', 'author_id': 214431, 'author_profile': 'https://Stackoverflow.com/users/214431', 'pm_score': 0, 'selected': False, 'text': '<p>As a development manager in this organisation, I\'m "not allowed" to write production code. </p>\n\n<p>I (ab)use that rule to knock out quick, dirty proof-of-concept code that addresses one or other sticking point, then I check it in to source control and point a "proper" dev at it and say "Here\'s how it\'s done, now do it properly."</p>\n\n<p>That\'s as close as we get to "one to throw away" here, and it\'s probably taken me a couple of hours max to knock together. Spending time putting in things like error handling, boundary-checking and all the other bits that make good code would be a waste of time for this sort of work, yet it means that the guys who are getting paid to write production code can spend their time writing production code and don\'t have excuses like "it\'s only a prototype" when it comes to code-review time. </p>\n\n<p>Building one to throw away is too often used as an excuse for not doing the job properly. That means that you don\'t actually encounter enough of the issues in the process to learn enough to make it a good use of anyone\'s time. And doing it properly, only to throw it away, is even more wasteful.</p>\n\n<p>As several people have previously said, the most important feature in any software is that it ships. With that in mind, I\'d build "one to get people to pay me for" any day, and my mercilessness in terms of refactoring is to allow only enough of it to get a product that works and can be reasonably maintained.</p>\n'}, {'answer_id': 39946418, 'author': 'Stan J.', 'author_id': 6945699, 'author_profile': 'https://Stackoverflow.com/users/6945699', 'pm_score': 0, 'selected': False, 'text': "<p>It is easy to build one to throw away on any configuration management system that supports the concept of a branch. If you are introducing a radical design change into an existing system that is in the field and is the source of your paycheck; you darn well better branch; prototype; and throw it away if it doesn't work.</p>\n\n<p>Refactoring a large legacy cash cow system often leads to plain old fashioned hacking. Refactoring just sounds a lot better than hacking I guess. </p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/78806', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1260685/']
78,811
<p>Is there an effective tool to convert C# code to Java code?</p>
[{'answer_id': 78860, 'author': 'scubabbl', 'author_id': 9450, 'author_profile': 'https://Stackoverflow.com/users/9450', 'pm_score': 2, 'selected': False, 'text': '<p>They don\'t convert directly, but it allows for interoperability between .NET and J2EE.</p>\n\n<p><a href="http://www.mainsoft.com/products/index.aspx" rel="nofollow noreferrer">http://www.mainsoft.com/products/index.aspx</a></p>\n'}, {'answer_id': 78928, 'author': 'Roger Ween', 'author_id': 6143, 'author_profile': 'https://Stackoverflow.com/users/6143', 'pm_score': 3, 'selected': False, 'text': '<p>There is a tool from Microsoft to convert java to C#. For the opposite direction take a look <a href="http://www.cs2j.com/" rel="nofollow noreferrer">here</a> and <a href="http://www.theserverside.com/news/thread.tss?thread_id=40344" rel="nofollow noreferrer">here</a>. If this doesn\'t work out, it should not take too long to convert the source manually because C# and java are very similar, </p>\n'}, {'answer_id': 78943, 'author': 'Michael Meadows', 'author_id': 7643, 'author_profile': 'https://Stackoverflow.com/users/7643', 'pm_score': 6, 'selected': False, 'text': '<p>I have never encountered a C#->Java conversion tool. The syntax would be easy enough, but the frameworks are dramatically different. Even if there were a tool, I would strongly advise against it. I have worked on several "migration" projects, and can\'t say emphatically enough that while conversion seems like a good choice, conversion projects <em>always always always</em> turn in to money pits. It\'s not a shortcut, what you end up with is code that is not readable, and doesn\'t take advantage of the target language. speaking from personal experience, assume that a rewrite is the cheaper option.</p>\n'}, {'answer_id': 79138, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>C# has a few more features than Java. Take delegates for example: Many very simple C# applications use delegates, while the Java folks figures that the observer pattern was sufficient. So, in order for a tool to convert a C# application which uses delegates it would have to translate the structure from using delegates to an implementation of the observer pattern.\nAnother problem is the fact that C# methods are not virtual by default while Java methods are. Additionally, Java doesn\'t have a way to make methods non virtual. This creates another problem: an application in C# could leverage non virtual method behavior through polymorphism in a way the does not translate directly to Java.\nIf you look around you will probably find that there are lots of tools to convert Java to C# since it is a simpler language (please don\'t flame me I didn\'t say worse I said simpler); however, you will find very few if any decent tools that convert C# to Java.</p>\n\n<p>I would recommend changing your approach to converting from Java to C# as it will create fewer headaches in the long run. Db4Objects recently released their internal tool which they use to convert Db4o into C# to the public. It is called Sharpen. If you register with their site you can view this link with instructions on how to use Sharpen:\n<a href="http://developer.db4o.com/Resources/view.aspx/Reference/Sharpen/How_To_Setup_Sharpen" rel="nofollow noreferrer">http://developer.db4o.com/Resources/view.aspx/Reference/Sharpen/How_To_Setup_Sharpen</a></p>\n\n<p>(I\'ve been registered with them for a while and they\'re good about not spamming)</p>\n'}, {'answer_id': 287113, 'author': 'Gad', 'author_id': 25152, 'author_profile': 'https://Stackoverflow.com/users/25152', 'pm_score': 1, 'selected': False, 'text': '<p>I\'m not sure what you are trying to do by wishing to convert C# to java, but if it is .net interoperability that you need, you might want to check out <a href="http://www.mono-project.com/Main_Page" rel="nofollow noreferrer">Mono</a></p>\n'}, {'answer_id': 287125, 'author': 'Ian Patrick Hughes', 'author_id': 2213, 'author_profile': 'https://Stackoverflow.com/users/2213', 'pm_score': 1, 'selected': False, 'text': '<p>This is off the cuff, but isn\'t that what <a href="http://dev.mainsoft.com/Default.aspx?tabid=130#What%20is%20Grasshopper?" rel="nofollow noreferrer">Grasshopper</a> was for?</p>\n'}, {'answer_id': 436025, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Try to look at <a href="https://net2java.dev.java.net/index.html" rel="nofollow noreferrer">Net2Java</a> It seems to me the best option for automatic (or semi-automatic at least) conversion from C# to Java</p>\n'}, {'answer_id': 1222523, 'author': 'Mike Rustici', 'author_id': 115553, 'author_profile': 'https://Stackoverflow.com/users/115553', 'pm_score': 5, 'selected': False, 'text': '<p>We have an application that we need to maintain in both C# and Java. Since we actively maintain this product, a one-time port wasn\'t an option. We investigated Net2Java and the Mainsoft tools, but neither met our requirements (Net2Java for lack of robustness and Mainsoft for cost and lack of source code conversion). We created our own tool called <a href="http://www.cs2j.com" rel="noreferrer">CS2J</a> that runs as part of our nightly build script and does a very effective port of our C# code to Java. Right now it is precisely good enough to translate our application, but would have a long way to go before being considered a comprehensive tool. We\'ve licensed the technology to a few parties with similar needs and we\'re toying with the idea of releasing it publicly, but our core business just keeps us too busy these days.</p>\n'}, {'answer_id': 1222542, 'author': 'Hannoun Yassir', 'author_id': 72443, 'author_profile': 'https://Stackoverflow.com/users/72443', 'pm_score': 1, 'selected': False, 'text': '<p>Well the syntax is almost the same but they rely on different frameworks so the only way to convert is by getting someone who knows both languages and convert the code :) the answer to your question is no there is no "effective" tool to convert c# to java</p>\n'}, {'answer_id': 2613269, 'author': 'Nick Westgate', 'author_id': 313445, 'author_profile': 'https://Stackoverflow.com/users/313445', 'pm_score': 3, 'selected': False, 'text': '<p>This blog <a href="http://lpeer.blogspot.com/2010/04/switching-from-c-to-java.html" rel="noreferrer">post</a> suggests useful results from <a href="http://www.tangiblesoftwaresolutions.com/" rel="noreferrer">Tangible</a>.</p>\n'}, {'answer_id': 3138658, 'author': 'Guven Demir', 'author_id': 378740, 'author_profile': 'https://Stackoverflow.com/users/378740', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://www.tangiblesoftwaresolutions.com/" rel="noreferrer">These</a> guys seem to have a solution for this, but I haven\'t tried yet. They also have a demo version of the converter.</p>\n'}, {'answer_id': 4434677, 'author': 'Pavel Savara', 'author_id': 129124, 'author_profile': 'https://Stackoverflow.com/users/129124', 'pm_score': 1, 'selected': False, 'text': '<p>Possibly you could use <a href="http://jni4net.sf.net/" rel="nofollow">jni4net - opensource bridge</a> instead ?\nOr list of <a href="http://jni4net.sourceforge.net/links.shtml" rel="nofollow">other options</a> I know.</p>\n'}, {'answer_id': 4682675, 'author': 'Big Rich', 'author_id': 304330, 'author_profile': 'https://Stackoverflow.com/users/304330', 'pm_score': 3, 'selected': False, 'text': '<p>Although this is an old-ish question, take a look at xmlVM <a href="http://www.xmlvm.org/clr2jvm" rel="nofollow">http://www.xmlvm.org/clr2jvm</a>, I\'m not sure if it\'s mature enough yet, although it has been around for several years now. XMLvm was made, I believe, primarily for translating Android Java apps to the iPhone, however, its XML-code-translation-based framework is flexible enough to do other combinations (see the diagrams on the site).</p>\n\n<p>As for a reason to do this conversion, maybe there is a need to \'hijack\' some of the <a href="http://code.google.com/codesearch?hl=en&amp;lr=&amp;q=license%3absd|apache|mit|zlib+lang%3ac%23+game&amp;sbtn=Search" rel="nofollow">highly abundant oss code</a> out there and use it within his/their own [Java] project.</p>\n\n<p>Cheers</p>\n\n<p>Rich </p>\n'}, {'answer_id': 32242667, 'author': 'Rohitdev', 'author_id': 569691, 'author_profile': 'https://Stackoverflow.com/users/569691', 'pm_score': -1, 'selected': False, 'text': '<p>Why not write it in Haxe (<a href="http://haxe.org/" rel="nofollow noreferrer">http://haxe.org/</a>) and convert it to whatever you want it to be?</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78811', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
78,816
<p>I have recently written an application(vb.net) that stores and allows searching for old council plans. Now while the application works well, the other day I was having a look at the routine that I use to generate the SQL string to pass the database and frankly, it was bad.<br> I was just posting a question here to see if anyone else has a better way of doing this.</p> <p>What I have is a form with a bunch of controls ranging from text boxes to radio buttons, each of these controls are like database filters and when the user hits search button, a SQL string(I would really like it to be a LINQ query because I have changed to LINQ to SQL) gets generated from the completed controls and run. </p> <p>The problem that I am having is matching each one of these controls to a field in the database and generating a LINQ query efficiently without doing a bunch of "if ...then...else." statements. In the past I have just used the tag property on the control to link to control to a field name in the database.</p> <p>I'm sorry if this is a bit confusing, its a bit hard to describe. Just throwing it out there to see if anyone has any ideas.</p> <p>Thanks Nathan</p>
[{'answer_id': 78860, 'author': 'scubabbl', 'author_id': 9450, 'author_profile': 'https://Stackoverflow.com/users/9450', 'pm_score': 2, 'selected': False, 'text': '<p>They don\'t convert directly, but it allows for interoperability between .NET and J2EE.</p>\n\n<p><a href="http://www.mainsoft.com/products/index.aspx" rel="nofollow noreferrer">http://www.mainsoft.com/products/index.aspx</a></p>\n'}, {'answer_id': 78928, 'author': 'Roger Ween', 'author_id': 6143, 'author_profile': 'https://Stackoverflow.com/users/6143', 'pm_score': 3, 'selected': False, 'text': '<p>There is a tool from Microsoft to convert java to C#. For the opposite direction take a look <a href="http://www.cs2j.com/" rel="nofollow noreferrer">here</a> and <a href="http://www.theserverside.com/news/thread.tss?thread_id=40344" rel="nofollow noreferrer">here</a>. If this doesn\'t work out, it should not take too long to convert the source manually because C# and java are very similar, </p>\n'}, {'answer_id': 78943, 'author': 'Michael Meadows', 'author_id': 7643, 'author_profile': 'https://Stackoverflow.com/users/7643', 'pm_score': 6, 'selected': False, 'text': '<p>I have never encountered a C#->Java conversion tool. The syntax would be easy enough, but the frameworks are dramatically different. Even if there were a tool, I would strongly advise against it. I have worked on several "migration" projects, and can\'t say emphatically enough that while conversion seems like a good choice, conversion projects <em>always always always</em> turn in to money pits. It\'s not a shortcut, what you end up with is code that is not readable, and doesn\'t take advantage of the target language. speaking from personal experience, assume that a rewrite is the cheaper option.</p>\n'}, {'answer_id': 79138, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>C# has a few more features than Java. Take delegates for example: Many very simple C# applications use delegates, while the Java folks figures that the observer pattern was sufficient. So, in order for a tool to convert a C# application which uses delegates it would have to translate the structure from using delegates to an implementation of the observer pattern.\nAnother problem is the fact that C# methods are not virtual by default while Java methods are. Additionally, Java doesn\'t have a way to make methods non virtual. This creates another problem: an application in C# could leverage non virtual method behavior through polymorphism in a way the does not translate directly to Java.\nIf you look around you will probably find that there are lots of tools to convert Java to C# since it is a simpler language (please don\'t flame me I didn\'t say worse I said simpler); however, you will find very few if any decent tools that convert C# to Java.</p>\n\n<p>I would recommend changing your approach to converting from Java to C# as it will create fewer headaches in the long run. Db4Objects recently released their internal tool which they use to convert Db4o into C# to the public. It is called Sharpen. If you register with their site you can view this link with instructions on how to use Sharpen:\n<a href="http://developer.db4o.com/Resources/view.aspx/Reference/Sharpen/How_To_Setup_Sharpen" rel="nofollow noreferrer">http://developer.db4o.com/Resources/view.aspx/Reference/Sharpen/How_To_Setup_Sharpen</a></p>\n\n<p>(I\'ve been registered with them for a while and they\'re good about not spamming)</p>\n'}, {'answer_id': 287113, 'author': 'Gad', 'author_id': 25152, 'author_profile': 'https://Stackoverflow.com/users/25152', 'pm_score': 1, 'selected': False, 'text': '<p>I\'m not sure what you are trying to do by wishing to convert C# to java, but if it is .net interoperability that you need, you might want to check out <a href="http://www.mono-project.com/Main_Page" rel="nofollow noreferrer">Mono</a></p>\n'}, {'answer_id': 287125, 'author': 'Ian Patrick Hughes', 'author_id': 2213, 'author_profile': 'https://Stackoverflow.com/users/2213', 'pm_score': 1, 'selected': False, 'text': '<p>This is off the cuff, but isn\'t that what <a href="http://dev.mainsoft.com/Default.aspx?tabid=130#What%20is%20Grasshopper?" rel="nofollow noreferrer">Grasshopper</a> was for?</p>\n'}, {'answer_id': 436025, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Try to look at <a href="https://net2java.dev.java.net/index.html" rel="nofollow noreferrer">Net2Java</a> It seems to me the best option for automatic (or semi-automatic at least) conversion from C# to Java</p>\n'}, {'answer_id': 1222523, 'author': 'Mike Rustici', 'author_id': 115553, 'author_profile': 'https://Stackoverflow.com/users/115553', 'pm_score': 5, 'selected': False, 'text': '<p>We have an application that we need to maintain in both C# and Java. Since we actively maintain this product, a one-time port wasn\'t an option. We investigated Net2Java and the Mainsoft tools, but neither met our requirements (Net2Java for lack of robustness and Mainsoft for cost and lack of source code conversion). We created our own tool called <a href="http://www.cs2j.com" rel="noreferrer">CS2J</a> that runs as part of our nightly build script and does a very effective port of our C# code to Java. Right now it is precisely good enough to translate our application, but would have a long way to go before being considered a comprehensive tool. We\'ve licensed the technology to a few parties with similar needs and we\'re toying with the idea of releasing it publicly, but our core business just keeps us too busy these days.</p>\n'}, {'answer_id': 1222542, 'author': 'Hannoun Yassir', 'author_id': 72443, 'author_profile': 'https://Stackoverflow.com/users/72443', 'pm_score': 1, 'selected': False, 'text': '<p>Well the syntax is almost the same but they rely on different frameworks so the only way to convert is by getting someone who knows both languages and convert the code :) the answer to your question is no there is no "effective" tool to convert c# to java</p>\n'}, {'answer_id': 2613269, 'author': 'Nick Westgate', 'author_id': 313445, 'author_profile': 'https://Stackoverflow.com/users/313445', 'pm_score': 3, 'selected': False, 'text': '<p>This blog <a href="http://lpeer.blogspot.com/2010/04/switching-from-c-to-java.html" rel="noreferrer">post</a> suggests useful results from <a href="http://www.tangiblesoftwaresolutions.com/" rel="noreferrer">Tangible</a>.</p>\n'}, {'answer_id': 3138658, 'author': 'Guven Demir', 'author_id': 378740, 'author_profile': 'https://Stackoverflow.com/users/378740', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://www.tangiblesoftwaresolutions.com/" rel="noreferrer">These</a> guys seem to have a solution for this, but I haven\'t tried yet. They also have a demo version of the converter.</p>\n'}, {'answer_id': 4434677, 'author': 'Pavel Savara', 'author_id': 129124, 'author_profile': 'https://Stackoverflow.com/users/129124', 'pm_score': 1, 'selected': False, 'text': '<p>Possibly you could use <a href="http://jni4net.sf.net/" rel="nofollow">jni4net - opensource bridge</a> instead ?\nOr list of <a href="http://jni4net.sourceforge.net/links.shtml" rel="nofollow">other options</a> I know.</p>\n'}, {'answer_id': 4682675, 'author': 'Big Rich', 'author_id': 304330, 'author_profile': 'https://Stackoverflow.com/users/304330', 'pm_score': 3, 'selected': False, 'text': '<p>Although this is an old-ish question, take a look at xmlVM <a href="http://www.xmlvm.org/clr2jvm" rel="nofollow">http://www.xmlvm.org/clr2jvm</a>, I\'m not sure if it\'s mature enough yet, although it has been around for several years now. XMLvm was made, I believe, primarily for translating Android Java apps to the iPhone, however, its XML-code-translation-based framework is flexible enough to do other combinations (see the diagrams on the site).</p>\n\n<p>As for a reason to do this conversion, maybe there is a need to \'hijack\' some of the <a href="http://code.google.com/codesearch?hl=en&amp;lr=&amp;q=license%3absd|apache|mit|zlib+lang%3ac%23+game&amp;sbtn=Search" rel="nofollow">highly abundant oss code</a> out there and use it within his/their own [Java] project.</p>\n\n<p>Cheers</p>\n\n<p>Rich </p>\n'}, {'answer_id': 32242667, 'author': 'Rohitdev', 'author_id': 569691, 'author_profile': 'https://Stackoverflow.com/users/569691', 'pm_score': -1, 'selected': False, 'text': '<p>Why not write it in Haxe (<a href="http://haxe.org/" rel="nofollow noreferrer">http://haxe.org/</a>) and convert it to whatever you want it to be?</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78816', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6335/']
78,823
<h2>Problem</h2> <p>My current project requires me to do different things based on different HTTP request headers for nearly every action.</p> <p>Currently, I have one massive Controller (all for the same resource type), and every action method has an ActionName attribute (so that I can have multiple versions of the same action that takes the same parameters, but does different things) and a custom FilterAttribute (implemented almost exactly like the AcceptVerbsAttribute in Preview 5) that checks if certain headers have certain values.</p> <p>I would really like to push the code into separate Controllers, and have the RouteTable select between them based on the headers, but can't think of the cleanest way to do this.</p> <h2>Example</h2> <p>For example, say I have a list of files. The service must process the request in one of two ways:</p> <ol> <li><p>The client wants a zip file, and passes "accept: application/zip" as a header, I take the list of files, pack them into a zip file, and send it back to the client.</p></li> <li><p>The client wants an html page, so it passes "accept: text/html", the site sends back a table-formatted html page listing the files.</p></li> </ol>
[{'answer_id': 78864, 'author': 'Aeon', 'author_id': 13289, 'author_profile': 'https://Stackoverflow.com/users/13289', 'pm_score': 0, 'selected': False, 'text': "<p>I'm not sure you need separate controllers based on header; this structure sounds perfectly reasonable. If your controller is massive as you say, consider whether it's dealing with multiple resources, and if it is, perhaps it should be split into multiple controllers based on resource?</p>\n"}, {'answer_id': 78872, 'author': 'Bryant', 'author_id': 10893, 'author_profile': 'https://Stackoverflow.com/users/10893', 'pm_score': 0, 'selected': False, 'text': '<p>Not sure if it is possible, but it seems like this would be something like the AcceptVerbs attribute that was <a href="http://weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx" rel="nofollow noreferrer">added in Preview 5</a>. I\'d take a look at how that was implemented (get the MVC source) to see if you can add something similar based on content type. </p>\n'}, {'answer_id': 84718, 'author': 'Haacked', 'author_id': 598, 'author_profile': 'https://Stackoverflow.com/users/598', 'pm_score': 3, 'selected': True, 'text': '<p>It sounds like you have slightly different behavior from your actions based on which header comes in. I would try to isolate the differences as much as possible. </p>\n\n<p>For example, if the application logic is the same, but the only difference is how you render the response to the user, you might consider writing a custom ActionResult that takes different actions based on the Http headers.</p>\n\n<p>However, if the logic is completely different, you could implement a custom Routing constraint (IRoutConstraint) that you attach to each route. Take a look at the implementation of HttpMethodConstraint for ideas.</p>\n'}, {'answer_id': 645186, 'author': 'zihotki', 'author_id': 66591, 'author_profile': 'https://Stackoverflow.com/users/66591', 'pm_score': 0, 'selected': False, 'text': '<p>You should to look at <a href="http://omaralzabir.com/create_rest_api_using_asp_net_mvc_that_speaks_both_json_and_plain_xml/" rel="nofollow noreferrer">this post</a>. It describes implementation for json and xml responses based on http header.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78823', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5897/']
78,826
<p>How do you use <code>gen_udp</code> in Erlang to do <a href="https://en.wikipedia.org/wiki/Multicast" rel="nofollow noreferrer">multicasting</a>? I know its in the code, there is just no documentation behind it. Sending out data is obvious and simple. I was wondering on how to add memberships. Not only adding memberships at start-up, but adding memberships while running would be useful too.</p>
[{'answer_id': 78886, 'author': 'Mark Harrison', 'author_id': 116, 'author_profile': 'https://Stackoverflow.com/users/116', 'pm_score': 0, 'selected': False, 'text': '<p><strong>Multicast is specified by IP Address</strong></p>\n\n<p>It\'s the same in erlang as for all languages. The IP addresses 224.0.0.0 through 239.255.255.255 are multicast addresses.</p>\n\n<p>Pick an address in that range, check that you\'re not overlapping an already assigned address, and you are good to go.</p>\n\n<p><a href="http://www.iana.org/assignments/multicast-addresses" rel="nofollow noreferrer">http://www.iana.org/assignments/multicast-addresses</a></p>\n'}, {'answer_id': 81149, 'author': 'Bwooce', 'author_id': 15290, 'author_profile': 'https://Stackoverflow.com/users/15290', 'pm_score': 4, 'selected': False, 'text': '<p>Multicast sending has been answered, receipt requires subscription to the multicast group. </p>\n\n<p>It (still) seems undocumented, but has been covered on the erlang-questions mailing list before. <a href="http://www.erlang.org/pipermail/erlang-questions/2003-March/008071.html" rel="nofollow noreferrer">http://www.erlang.org/pipermail/erlang-questions/2003-March/008071.html</a></p>\n\n<pre><code> {ok, Socket} = gen_udp:open(Port, [binary, {active, false},\n {reuseaddr, true},{ip, Addr}, \n {add_membership, {Addr, LAddr}}]).\n</code></pre>\n\n<p>where the <code>Addr</code> is the multicast group, and <code>LAddr</code> is a local interface. (code courtesy of mog)</p>\n\n<p>The same options used above can be passed to <a href="http://www.erlang.org/doc/man/inet.html#setopts-2" rel="nofollow noreferrer"><code>inet:setopts</code></a> including <code>{drop_membership, {Addr, LAddr}}</code> to stop listening to the group. </p>\n'}, {'answer_id': 1740065, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': True, 'text': '<p>Here is example code on how to listen in on Bonjour / Zeroconf traffic.</p>\n\n<pre><code>-module(zcclient).\n\n-export([open/2,start/0]).\n-export([stop/1,receiver/0]).\n\nopen(Addr,Port) -&gt;\n {ok,S} = gen_udp:open(Port,[{reuseaddr,true}, {ip,Addr}, {multicast_ttl,4}, {multicast_loop,false}, binary]),\n inet:setopts(S,[{add_membership,{Addr,{0,0,0,0}}}]),\n S.\n\nclose(S) -&gt; gen_udp:close(S).\n\nstart() -&gt;\n S=open({224,0,0,251},5353),\n Pid=spawn(?MODULE,receiver,[]),\n gen_udp:controlling_process(S,Pid),\n {S,Pid}.\n\nstop({S,Pid}) -&gt;\n close(S),\n Pid ! stop.\n\nreceiver() -&gt;\n receive\n {udp, _Socket, IP, InPortNo, Packet} -&gt;\n io:format("~n~nFrom: ~p~nPort: ~p~nData: ~p~n",[IP,InPortNo,inet_dns:decode(Packet)]),\n receiver();\n stop -&gt; true;\n AnythingElse -&gt; io:format("RECEIVED: ~p~n",[AnythingElse]),\n receiver()\n end. \n</code></pre>\n'}, {'answer_id': 1880167, 'author': 'Matthias', 'author_id': 228713, 'author_profile': 'https://Stackoverflow.com/users/228713', 'pm_score': 2, 'selected': False, 'text': '<p>I try to get this example running on my PC. What could happen, if I get always the message {error,eaddrnotavail} by opening the receive socket?</p>\n\n<p>Example 1: This works:</p>\n\n<pre><code>{ok, Socket} = gen_udp:open(?PORT, [{reuseaddr,true}, {ip,?SERVER_IP},\n {multicast_ttl,4}, {multicast_loop,false}, binary]),\n</code></pre>\n\n<p>Example 2: Getting an runtime Error:</p>\n\n<pre><code>{ok, Socket} = gen_udp:open(?PORT, [{reuseaddr,true}, {ip,?MULTICAST_IP},\n {multicast_ttl,4}, {multicast_loop,false}, binary]),\n</code></pre>\n\n<p>% --> {error,eaddrnotavail}</p>\n\n<pre><code>-define(SERVER_IP, {10,31,123,123}). % The IP of the current computer\n-define(PORT, 5353).\n-define(MULTICAST_IP, {224,0,0,251}). \n</code></pre>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78826', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10432/']
78,828
<p>In SQL Server 2005, a snapshot of a database can be created that allows read-only access to a database, even when the database is in "recovery pending" mode. One use case for this capability is in creating a reporting database that references a copy of a production database, which is kept current through log-shipping. </p> <p>In this scenario, how can I implement security on the "snapshot" database that is different from the "production" source database? </p> <p>For example, in the production database, all access to data is through stored procedures, while in the snapshot database users are allowed to select from table in the database for reporting purposes. The problem the I see is that security for the snapshot database is inherited from the source database, and can not be changed because snapshots are strictly read-only.</p>
[{'answer_id': 79791, 'author': 'Nathan Feger', 'author_id': 8563, 'author_profile': 'https://Stackoverflow.com/users/8563', 'pm_score': 1, 'selected': False, 'text': '<p>Are you able to manage permissions on this database? Would adding a separate user who only has read access to a database be sufficient for this type of scenario? This could be a read-only user on the main database, but is only effectively used on the snapshot db.</p>\n\n<p>i.e. Add a new user, readerMan5000 who is only given select access, to the database in question. Then require users to authenticate through that new credential.</p>\n\n<p>Note to future commenters, you may want to read: \n<a href="http://www.simple-talk.com/sql/database-administration/sql-server-2005-snapshots/" rel="nofollow noreferrer">http://www.simple-talk.com/sql/database-administration/sql-server-2005-snapshots/</a>\nor \n<a href="http://msdn.microsoft.com/en-us/library/ms187054(SQL.90).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms187054(SQL.90).aspx</a>\nbefore you open your big mouth like me. :)</p>\n'}, {'answer_id': 215786, 'author': 'Brent Ozar', 'author_id': 26837, 'author_profile': 'https://Stackoverflow.com/users/26837', 'pm_score': 0, 'selected': False, 'text': "<p>You can't change permissions after you take the snapshot, but here's one workaround: instead of having them access the tables directly, require them to use views instead. If the views are used only for reporting, then you can set tight security on them in the original database, and then have the users hit those views in the snapshot. You'll need to restrict access on the underlying tables though if you want it to be effective.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/78828', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
78,847
<p>ASP.NET 1.1 - I have a DataGrid on an ASPX page that is databound and displays a value within a textbox. The user is able to change this value, then click on a button where the code behind basically iterates through each DataGridItem in the grid, does a FindControl for the ID of the textbox then assigns the .Text value to a variable which is then used to update the database. The DataGrid is rebound with the new values.</p> <p>The issue I'm having is that when assigning the .Text value to the variable, the value being retrieved is the original databound value and not the newly entered user value. Any ideas as to what may be causing this behaviour?</p> <p>Code sample:</p> <pre><code>foreach(DataGridItem dgi in exGrid.Items) { TextBox Text1 = (TextBox)dgi.FindControl("TextID"); string exValue = Text1.Text; //This is retrieving the original bound value not the newly entered value // do stuff with the new value } </code></pre>
[{'answer_id': 79791, 'author': 'Nathan Feger', 'author_id': 8563, 'author_profile': 'https://Stackoverflow.com/users/8563', 'pm_score': 1, 'selected': False, 'text': '<p>Are you able to manage permissions on this database? Would adding a separate user who only has read access to a database be sufficient for this type of scenario? This could be a read-only user on the main database, but is only effectively used on the snapshot db.</p>\n\n<p>i.e. Add a new user, readerMan5000 who is only given select access, to the database in question. Then require users to authenticate through that new credential.</p>\n\n<p>Note to future commenters, you may want to read: \n<a href="http://www.simple-talk.com/sql/database-administration/sql-server-2005-snapshots/" rel="nofollow noreferrer">http://www.simple-talk.com/sql/database-administration/sql-server-2005-snapshots/</a>\nor \n<a href="http://msdn.microsoft.com/en-us/library/ms187054(SQL.90).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms187054(SQL.90).aspx</a>\nbefore you open your big mouth like me. :)</p>\n'}, {'answer_id': 215786, 'author': 'Brent Ozar', 'author_id': 26837, 'author_profile': 'https://Stackoverflow.com/users/26837', 'pm_score': 0, 'selected': False, 'text': "<p>You can't change permissions after you take the snapshot, but here's one workaround: instead of having them access the tables directly, require them to use views instead. If the views are used only for reporting, then you can set tight security on them in the original database, and then have the users hit those views in the snapshot. You'll need to restrict access on the underlying tables though if you want it to be effective.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/78847', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/710/']
78,849
<p>I have an image (mx) and i want to get the uint of the pixel that was clicked.</p> <p>Any ideas?</p>
[{'answer_id': 79221, 'author': 'enobrev', 'author_id': 14651, 'author_profile': 'https://Stackoverflow.com/users/14651', 'pm_score': 3, 'selected': False, 'text': '<p>A few minutes on the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html" rel="nofollow noreferrer">BitmapData LiveDoc Page</a> will take you where you need to go. Once you have your image loaded into a Bitmap variable, you can access its BitmapData property. Add a <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/MouseEvent.html#CLICK" rel="nofollow noreferrer">Mouse Click Event</a> Listener to the image and then use <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html" rel="nofollow noreferrer">BitmapData::getPixel</a>. The example for getPixel shows how to convert the uint response to an rgb hex code.</p>\n\n<p>Here\'s a modification of the Example given on the BitmapData page that worked for me (using mxmlc - YMMV):</p>\n\n<pre><code>package {\n import flash.display.Bitmap;\n import flash.display.BitmapData;\n import flash.display.Loader;\n import flash.display.Sprite;\n import flash.events.Event;\n import flash.events.MouseEvent;\n import flash.net.URLRequest;\n\n public class BitmapDataExample extends Sprite {\n private var url:String = "santa-drunk1.jpg";\n private var size:uint = 200;\n private var image:Bitmap;\n\n public function BitmapDataExample() {\n configureAssets();\n }\n\n private function configureAssets():void {\n var loader:Loader = new Loader();\n loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);\n\n var request:URLRequest = new URLRequest(url);\n loader.load(request);\n addChild(loader);\n }\n\n private function completeHandler(event:Event):void {\n var loader:Loader = Loader(event.target.loader);\n this.image = Bitmap(loader.content);\n\n this.addEventListener(MouseEvent.CLICK, this.clickListener);\n }\n\n private function clickListener(event:MouseEvent):void {\n var pixelValue:uint = this.image.bitmapData.getPixel(event.localX, event.localY)\n trace(pixelValue.toString(16));\n }\n }\n}\n</code></pre>\n'}, {'answer_id': 85391, 'author': 'defmeta', 'author_id': 10875, 'author_profile': 'https://Stackoverflow.com/users/10875', 'pm_score': 4, 'selected': True, 'text': '<p>Here\'s an even simpler implementation. All you do is take a snapshot of the stage using the <strong>draw()</strong> method of bitmapData, then use <strong>getPixel()</strong> on the pixel under the mouse. The advantage of this is that you can sample anything that\'s been drawn to the stage, not just a given bitmap.</p>\n\n<pre><code>import flash.display.Bitmap;\nimport flash.display.BitmapData;\nimport flash.events.*;\n\nstage.addEventListener(MouseEvent.CLICK, getColorSample);\n\nfunction getColorSample(e:MouseEvent):void {\n var bd:BitmapData = new BitmapData(stage.width, stage.height);\n bd.draw(stage);\n var b:Bitmap = new Bitmap(bd);\n trace(b.bitmapData.getPixel(stage.mouseX,stage.mouseX));\n}\n</code></pre>\n\n<p>Hope this is helpful!</p>\n\n<hr>\n\n<p><strong>Edit</strong>:</p>\n\n<p>This edited version uses a single <code>BitmapData</code>, and removes the unnecessary step of creating a <code>Bitmap</code>. If you\'re sampling the color on <code>MOUSE_MOVE</code> then this is essential to avoid memory issues. </p>\n\n<p>Note: if you\'re using a custom cursor sprite you\'ll have to use an object other than \'state\' or else you\'ll be sampling the color of the custom sprite instead of what\'s under it.</p>\n\n<pre><code>import flash.display.Bitmap;\nimport flash.display.BitmapData;\nimport flash.events.*;\n\nprivate var _stageBitmap:BitmapData;\n\nstage.addEventListener(MouseEvent.CLICK, getColorSample);\n\nfunction getColorSample(e:MouseEvent):void \n{\n if (_stageBitmap == null) {\n _stageBitmap = new BitmapData(stage.width, stage.height);\n }\n _stageBitmap.draw(stage);\n\n var rgb:uint = _stageBitmap.getPixel(stage.mouseX,stage.mouseY);\n\n var red:int = (rgb &gt;&gt; 16 &amp; 0xff);\n var green:int = (rgb &gt;&gt; 8 &amp; 0xff);\n var blue:int = (rgb &amp; 0xff);\n\n trace(red + "," + green + "," + blue);\n}\n</code></pre>\n'}, {'answer_id': 8619705, 'author': 'darscan', 'author_id': 53303, 'author_profile': 'https://Stackoverflow.com/users/53303', 'pm_score': 3, 'selected': False, 'text': "<p>This is not specific to Flex or mx:Image, and allows you to grab a pixel color value from any bitmap drawable object (provided you have permission):</p>\n\n<pre><code>private const bitmapData:BitmapData = new BitmapData(1, 1);\nprivate const matrix:Matrix = new Matrix();\nprivate const clipRect:Rectangle = new Rectangle(0, 0, 1, 1);\n\npublic function getColor(drawable:IBitmapDrawable, x:Number, y:Number):uint\n{\n matrix.setTo(1, 0, 0, 1, -x, -y)\n bitmapData.draw(drawable, matrix, null, null, clipRect);\n return bitmapData.getPixel(0, 0);\n}\n</code></pre>\n\n<p>You could easily grab a pixel from the stage or your mx:Image instance. It's a lot more efficient than drawing the entire stage (or drawable object), and should be fast enough to hook up to MouseEvent.MOUSE_MOVE for instant visual feedback.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/78849', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1748529/']
78,850
<p>What is the difference between publishing a website with visual studio and just copying the files over to the server? Is the only difference that the publish files are pre-compiled?</p>
[{'answer_id': 78906, 'author': 'David Negron', 'author_id': 981, 'author_profile': 'https://Stackoverflow.com/users/981', 'pm_score': 1, 'selected': False, 'text': '<p>I believe you are correct in your assumption. It has been my experience that the only difference is that published files are compiled. <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=0AA30AE8-C73B-4BDD-BB1B-FE697256C459&amp;displaylang=en" rel="nofollow noreferrer">Visual Studio® 2008 Web Deployment Projects</a> is a nice enhancement for customizing your build scripts for both your Websites and Web Applications.</p>\n'}, {'answer_id': 79017, 'author': 'mattlant', 'author_id': 14642, 'author_profile': 'https://Stackoverflow.com/users/14642', 'pm_score': 3, 'selected': True, 'text': '<p>There is not much difference between "publish", and copying the files. Publish appears in a webapplication. The only difference really is publishing gives you the option to only include html and dll\'s, where as copying you would need to parse out source code manually. There is no full precompiling in the publish option, as Fully precompiled means no HTML at all; The aspx files are just placeholders; All html is in the compiled binaries.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78850', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2066/']
78,852
<p>Mapping a collection of enums with NHibernate</p> <p>Specifically, using Attributes for the mappings.</p> <p>Currently I have this working mapping the collection as type Int32 and NH seems to take care of it, but it's not exactly ideal.</p> <p>The error I receive is "Unable to determine type" when trying to map the collection as of the type of the enum I am trying to map.</p> <p>I found a post that said to define a class as</p> <pre><code>public class CEnumType : EnumStringType { public CEnumType() : base(MyEnum) { } } </code></pre> <p>and then map the enum as CEnumType, but this gives "CEnumType is not mapped" or something similar.</p> <p>So has anyone got experience doing this?</p> <p>So anyway, just a simple reference code snippet to give an example with</p> <pre><code> [NHibernate.Mapping.Attributes.Class(Table = "OurClass")] public class CClass : CBaseObject { public enum EAction { do_action, do_other_action }; private IList&lt;EAction&gt; m_class_actions = new List&lt;EAction&gt;(); [NHibernate.Mapping.Attributes.Bag(0, Table = "ClassActions", Cascade="all", Fetch = CollectionFetchMode.Select, Lazy = false)] [NHibernate.Mapping.Attributes.Key(1, Column = "Class_ID")] [NHibernate.Mapping.Attributes.Element(2, Column = "EAction", Type = "Int32")] public virtual IList&lt;EAction&gt; Actions { get { return m_class_actions; } set { m_class_actions = value;} } } </code></pre> <p>So, anyone got the correct attributes for me to map this collection of enums as actual enums? It would be really nice if they were stored in the db as strings instead of ints too but it's not completely necessary.</p>
[{'answer_id': 80485, 'author': 'alvin', 'author_id': 15121, 'author_profile': 'https://Stackoverflow.com/users/15121', 'pm_score': 1, 'selected': False, 'text': '<p>This is the way i do it. There\'s probably an easier way but this works for me.</p>\n\n<p>Edit: sorry, i overlooked that you want it as a list. I don\'t know how to do that...</p>\n\n<p>Edit2: maybe you can map it as a protected IList[string], and convert to public IList[EAction] just as i do with a simple property.</p>\n\n<pre><code> public virtual ContractGroups Group\n {\n get\n {\n if (GroupString.IsNullOrEmpty())\n return ContractGroups.Default;\n\n return GroupString.ToEnum&lt;ContractGroups&gt;(); // extension method\n }\n set { GroupString = value.ToString(); }\n }\n\n // this is castle activerecord, you can map this property in NH mapping file as an ordinary string\n [Property("`Group`", NotNull = true)] \n protected virtual string GroupString\n {\n get;\n set;\n }\n\n\n\n /// &lt;summary&gt;\n /// Converts to an enum of type &lt;typeparamref name="TEnum"/&gt;.\n /// &lt;/summary&gt;\n /// &lt;typeparam name="TEnum"&gt;The type of the enum.&lt;/typeparam&gt;\n /// &lt;param name="self"&gt;The self.&lt;/param&gt;\n /// &lt;returns&gt;&lt;/returns&gt;\n /// &lt;remarks&gt;From &lt;see href="http://www.mono-project.com/Rocks"&gt;Mono Rocks&lt;/see&gt;.&lt;/remarks&gt;\n public static TEnum ToEnum&lt;TEnum&gt;(this string self)\n where TEnum : struct, IComparable, IFormattable, IConvertible\n {\n Argument.SelfNotNull(self);\n\n return (TEnum)Enum.Parse(typeof(TEnum), self);\n }\n</code></pre>\n'}, {'answer_id': 214268, 'author': 'kͩeͣmͮpͥ ͩ', 'author_id': 26479, 'author_profile': 'https://Stackoverflow.com/users/26479', 'pm_score': 1, 'selected': False, 'text': '<p>instead of</p>\n\n<pre><code>[NHibernate.Mapping.Attributes.Element(2, Column = "EAction", Type = "Int32")]\n</code></pre>\n\n<p>try</p>\n\n<pre><code>[NHibernate.Mapping.Attributes.Element(2, Column = "EAction", Type = "String")]\n</code></pre>\n\n<p>ie: change the <code>Int32</code> to <code>String</code></p>\n'}, {'answer_id': 271296, 'author': 'Geoff Bennett', 'author_id': 35377, 'author_profile': 'https://Stackoverflow.com/users/35377', 'pm_score': 1, 'selected': False, 'text': '<p>While I haven\'t tried using it myself, I stumbled across this code a little while ago and it looks pretty interesting:</p>\n\n<p><a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/08/12/enumeration-classes.aspx" rel="nofollow noreferrer" title="Jimmy Bogard - Enumeration Classes">http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/08/12/enumeration-classes.aspx</a></p>\n\n<p>Like I said, I haven\'t used it myself, but I\'m going to give it a go in a project RSN.</p>\n'}, {'answer_id': 2807763, 'author': 'Lisa', 'author_id': 314283, 'author_profile': 'https://Stackoverflow.com/users/314283', 'pm_score': 2, 'selected': False, 'text': '<p>You will need to map your CEnum type directly. In XML mappings this would mean creating a new class mapping element in your NHibernate XML mappings file.</p>\n\n<p><code><pre></p>\n\n<pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="YourAssembly"\n auto-import="true" default-lazy="false"&gt;\n\n ...\n\n &lt;class name="YourAssemblyNamespace.CEnum" table="CEnumTable" mutable="false" &gt;\n &lt;id name="Id" unsaved-value="0" column="id"&gt;\n &lt;generator class="native"/&gt;\n &lt;/id&gt;\n\n ...\n\n &lt;/class&gt;\n\n&lt;/hibernate-mapping&gt;\n</code></pre>\n\n<p></pre></code></p>\n\n<p>To do it with attribute mappings, something like this on top of your CEnum class:</p>\n\n<p><code>[NHibernate.Mapping.Attributes.Class(Table = "CEnumTable")] //etc as you require</code></p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78852', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/924607/']
78,859
<p>I am new to developing for Office Forms Server / MOSS 2007. I have to choose between designing my web-based forms and writing code for them in Visual Studio Tools for Applications (aka VSTA) or Visual Studio Tools for Office (aka VSTO). VSTA is included free as part of the license for InfoPath 2007; VSTO, also free, requires Visual Studio 2005 / 2008. I have licenses for both of the products and cannot easily decide what the pros and cons of each IDE might be.</p>
[{'answer_id': 78887, 'author': 'Bennor McCarthy', 'author_id': 14451, 'author_profile': 'https://Stackoverflow.com/users/14451', 'pm_score': 3, 'selected': True, 'text': '<p>This explains it better than I can: <a href="http://blogs.msdn.com/andreww/archive/2006/02/21/536179.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/andreww/archive/2006/02/21/536179.aspx</a></p>\n\n<p>Given the fact that the license for VSTA comes with InfoPath, I\'d probably run with that.</p>\n'}, {'answer_id': 165324, 'author': 'rasx', 'author_id': 22944, 'author_profile': 'https://Stackoverflow.com/users/22944', 'pm_score': 0, 'selected': False, 'text': '<p>To add to Bennor\'s answer I would avoid writing code "behind" InfoPath forms entirely. This is a desperate attempt to make \'dumb XML\' as much as possible instead of "smart" XML that is entangled with code. Failing this, my next choice is VSTA because historically these solutions (at least the ones I have written) have a lower security risk and can run on more diverse Office environments.</p>\n\n<p>The last resort is to use VSTO. This is my bias... most of my VSTO investments are in Microsoft Word.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78859', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8305/']
78,869
<p>I'm looking around for a Java <a href="http://en.wikipedia.org/wiki/Code_signing" rel="noreferrer">code signing</a> certificate so my Java applets don't throw up such scary security warnings. However, all the places I've found offering them charge (in my opinion) way too much, like over USD200 per year. While doing research, a code signing certificate seems almost exactly the same as an <a href="http://en.wikipedia.org/wiki/SSL" rel="noreferrer">SSL</a> certificate.</p> <p>The main question I have: is it possible to buy an SSL certificate, but use it to sign Java applets?</p>
[{'answer_id': 78889, 'author': 'John Meagher', 'author_id': 3535, 'author_profile': 'https://Stackoverflow.com/users/3535', 'pm_score': 6, 'selected': True, 'text': "<p>Short answer: No, they're different.</p>\n\n<p>Long answer: It's the same sort of certificate and it uses the same crypto software, but the certificate has flags indicating what it is allowed to be used for. Code signing and web server are different uses. </p>\n"}, {'answer_id': 78925, 'author': 'Purfideas', 'author_id': 4615, 'author_profile': 'https://Stackoverflow.com/users/4615', 'pm_score': 2, 'selected': False, 'text': '<p>When I import a new CA certificate in Firefox (etc.) I have the option of choosing which certificate uses I trust:</p>\n\n<ul>\n<li>Sign servers</li>\n<li>Sign code (like your applet)</li>\n<li>Sign email certificates</li>\n</ul>\n\n<p>So to me the answer is: Yes, they\'re the same. Furthermore, why not generate your own with <a href="http://en.wikipedia.org/wiki/OpenSSL" rel="nofollow noreferrer">OpenSSL</a> (man openssl, man x509, man req, etc. on Unix)? Do you want to just quiet down the warnings <em>or</em> do you want <em>other</em> people whom you\'ve never met to trust your code? If you don\'t need other users to chain trust to the anchor CA\'s bundled with their browser, OS, etc., then use OpenSSL to generate your own.</p>\n\n<p>And ask "How do I use OpenSSL to generate my own certificates?" if the latter is your choice.</p>\n'}, {'answer_id': 78931, 'author': 'jtimberman', 'author_id': 7672, 'author_profile': 'https://Stackoverflow.com/users/7672', 'pm_score': 1, 'selected': False, 'text': '<p>Thawte offers code signing certificates <a href="http://www.thawte.com/code-signing/" rel="nofollow noreferrer">here</a>. I imagine other Certificate Authorities offer this service as well. You can also create self-signed certificates, with <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/keytool.html" rel="nofollow noreferrer">Java keytool</a>.</p>\n'}, {'answer_id': 27676751, 'author': 'flup', 'author_id': 1973271, 'author_profile': 'https://Stackoverflow.com/users/1973271', 'pm_score': 1, 'selected': False, 'text': '<p>X.509 certificates may include <a href="https://www.rfc-editor.org/rfc/rfc5280#section-4.2.1.3" rel="nofollow noreferrer">key usage fields</a> (KU\'s) and <a href="https://www.rfc-editor.org/rfc/rfc5280#section-4.2.1.12" rel="nofollow noreferrer">extended key usage fields</a> (EKU\'s). The <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/certificates.html#A1148308" rel="nofollow noreferrer">Oracle tech note describing how to create sign your RIA\'s</a> creates a certificate without any key usage flags, which works just fine (if you can get a trusted CA to sign it)</p>\n<p>But more and more, CA\'s issue certificates with these key usage fields. When present, these fields <strong>restrict</strong> the usage of the certificate. The java plugin checks for the presence of these fields in the <a href="http://www.docjar.com/html/api/sun/security/validator/EndEntityChecker.java.html" rel="nofollow noreferrer">EndEntityChecker</a>:</p>\n<pre><code>/**\n * Check whether this certificate can be used for code signing.\n * @throws CertificateException if not.\n */\nprivate void checkCodeSigning(X509Certificate cert)\n throws CertificateException {\n Set&lt;String&gt; exts = getCriticalExtensions(cert);\n\n if (checkKeyUsage(cert, KU_SIGNATURE) == false) {\n throw new ValidatorException\n (&quot;KeyUsage does not allow digital signatures&quot;,\n ValidatorException.T_EE_EXTENSIONS, cert);\n }\n\n if (checkEKU(cert, exts, OID_EKU_CODE_SIGNING) == false) {\n throw new ValidatorException\n (&quot;Extended key usage does not permit use for code signing&quot;,\n ValidatorException.T_EE_EXTENSIONS, cert);\n }\n\n if (!SimpleValidator.getNetscapeCertTypeBit(cert, NSCT_SSL_CLIENT)) {\n throw new ValidatorException\n (&quot;Netscape cert type does not permit use for SSL client&quot;,\n ValidatorException.T_EE_EXTENSIONS, cert);\n }\n\n // do not check Netscape cert type for JCE code signing checks\n // (some certs were issued with incorrect extensions)\n if (variant.equals(Validator.VAR_JCE_SIGNING) == false) {\n if (!SimpleValidator.getNetscapeCertTypeBit(cert, NSCT_CODE_SIGNING)) {\n throw new ValidatorException\n (&quot;Netscape cert type does not permit use for code signing&quot;,\n ValidatorException.T_EE_EXTENSIONS, cert);\n }\n exts.remove(SimpleValidator.OID_NETSCAPE_CERT_TYPE);\n }\n\n // remove extensions we checked\n exts.remove(SimpleValidator.OID_KEY_USAGE);\n exts.remove(SimpleValidator.OID_EXTENDED_KEY_USAGE);\n\n checkRemainingExtensions(exts);\n}\n</code></pre>\n<p>The check methods look as follows:</p>\n<pre><code>/**\n * Utility method checking if the extended key usage extension in\n * certificate cert allows use for expectedEKU.\n */\nprivate boolean checkEKU(X509Certificate cert, Set&lt;String&gt; exts,\n String expectedEKU) throws CertificateException {\n List&lt;String&gt; eku = cert.getExtendedKeyUsage();\n if (eku == null) {\n return true;\n }\n return eku.contains(expectedEKU) || eku.contains(OID_EKU_ANY_USAGE);\n}\n</code></pre>\n<p>So if no KU or EKU is specified, the KU or EKU checker happily returns true.</p>\n<p>But</p>\n<ul>\n<li>if KU\'s are specified, the <em>digital signature</em> KU should be one of them.</li>\n<li>if any EKU\'s are specified, either the EKU <em>code signing</em> (identified by oid 1.3.6.1.5.5.7.3.3) or the EKU <em>any usage</em> (identified by oid 2.5.29.37.0) should be specified as well.</li>\n</ul>\n<p>Finally, the <code>checkRemainingExtensions</code> method checks the remaining critical EKU\'s. The only other critical EKU\'s allowed to be present are</p>\n<ul>\n<li><em>basic constraints</em> (oid &quot;2.5.29.19&quot;) and</li>\n<li><em>subject alt name</em> (oid 2.5.29.17)</li>\n</ul>\n<p>If it finds any other critical EKU, it returns false.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78869', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14569/']
78,874
<p>I have a cross platform app and for my Linux and Mac versions it generates a postscript file for printing reports and then prints them with CUPS. It works for simple characters and images but I would like to have the ability to embed a true type font directly into the postscript file. Does anyone know how to do this?? Also I can encode simple ascii characters but I'm not sure how to encode any characters beyond the usual a-z 0-9, things like foreign characters with accents.</p>
[{'answer_id': 80260, 'author': 'ccxvii', 'author_id': 14849, 'author_profile': 'https://Stackoverflow.com/users/14849', 'pm_score': 3, 'selected': False, 'text': '<p>In order to embed a TrueType font in a Postscript document, you will first need to convert it to a Type 42 font. This conversion turns the font into postscript code.\nThere are several small utilities for doing this conversion, or you can read\nthe <a href="http://www.adobe.com/devnet/font/pdfs/5012.Type42_Spec.pdf" rel="noreferrer">Type 42 specification</a> and write\nyour own code for it.</p>\n\n<p>Embedding Type 1 fonts is a lot easier. Linux ships with a large set of Type 1 fonts, and so does OS X if you have X11 installed. Generating PDF instead is also an option you may want to look into, since PDF can embed TrueType fonts directly.</p>\n'}, {'answer_id': 80265, 'author': 'ccxvii', 'author_id': 14849, 'author_profile': 'https://Stackoverflow.com/users/14849', 'pm_score': 3, 'selected': False, 'text': '<p>Postscript fonts come with widely varying encodings, so if you want to reliably\nprint iso-8859-1 characters you need to reencode the font in your postscript\nprogram.</p>\n\n<p><a href="http://en.wikibooks.org/wiki/PostScript_FAQ#How_to_print_accented_characters.3F" rel="noreferrer">PostScript FAQ - How to print accented characters</a></p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78874', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13676/']
78,884
<p>I have an xslt sheet with some text similar to below:</p> <pre><code>&lt;xsl:text&gt;I am some text, and I want to be bold&lt;/xsl:text&gt; </code></pre> <p>I would like some text to be bold, but this doesn't work.</p> <pre><code>&lt;xsl:text&gt;I am some text, and I want to be &lt;strong&gt;bold&lt;strong&gt;&lt;/xsl:text&gt; </code></pre> <p>The deprecated b tag doesn't work either. How do I format text within an xsl:text tag?</p>
[{'answer_id': 78904, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 3, 'selected': False, 'text': '<p>Try this: </p>\n\n<pre><code>&lt;fo:inline font-weight="bold"&gt;&lt;xsl:text&gt;Bold text&lt;/xsl:text&gt;&lt;/fo:inline&gt;\n</code></pre>\n\n<ul>\n<li><a href="http://www.ecrion.com/Support/Resources/XSL-FOTutorial/Inline.xml.html" rel="noreferrer">XSL-FO Tutoria: Inline Text\nFormatting</a></li>\n<li><a href="http://www.w3schools.com/xslfo/obj_inline.asp" rel="noreferrer">XSL-FO inline Object</a></li>\n</ul>\n'}, {'answer_id': 78917, 'author': 'David Medinets', 'author_id': 219658, 'author_profile': 'https://Stackoverflow.com/users/219658', 'pm_score': 2, 'selected': False, 'text': '<blockquote>\n <p>&lt;xsl:text <strong>disable-output-escaping="yes"</strong>&gt;I want to be &lt;strong&gt;bold&lt;strong&gt; &lt;/xsl:text&gt;</p>\n</blockquote>\n'}, {'answer_id': 78927, 'author': 'Joe Skora', 'author_id': 14057, 'author_profile': 'https://Stackoverflow.com/users/14057', 'pm_score': -1, 'selected': False, 'text': '<p>XSL-FO formatting should be able to do that, see the W3Schools <a href="http://w3schools.com/xslfo/default.asp" rel="nofollow noreferrer">tutorial</a>.</p>\n'}, {'answer_id': 80522, 'author': 'jelovirt', 'author_id': 2679, 'author_profile': 'https://Stackoverflow.com/users/2679', 'pm_score': 4, 'selected': True, 'text': "<p>You don't. <code>xsl:text</code> can only contain text nodes and <code>&lt;strong&gt;</code> is an element node, not a string that starts with less-than character; XSLT is about creating node trees, not markup. So, you have to do </p>\n\n<pre><code>&lt;xsl:text&gt;I am some text, and I want to be &lt;/xsl:text&gt;\n&lt;strong&gt;bold&lt;strong&gt;\n&lt;xsl:text&gt; &lt;/xsl:text&gt;\n</code></pre>\n"}, {'answer_id': 6410661, 'author': 'Pavan', 'author_id': 732642, 'author_profile': 'https://Stackoverflow.com/users/732642', 'pm_score': 0, 'selected': False, 'text': '<p>The answer for this depends on how much formatting is needed in the content and also where you get content from.\nIf you have less content and less formatting then you can use what jelovirt suggested</p>\n\n<pre><code>&lt;xsl:text&gt;I am some text, and I want to be &lt;/xsl:text&gt;\n&lt;strong&gt;bold&lt;strong&gt;\n&lt;xsl:text&gt; &lt;/xsl:text&gt;\n</code></pre>\n\n<p>However if your content has large formatting then what David Medinets suggests is better way to do it</p>\n\n<pre><code>&lt;xsl:text disable-output-escaping="yes"&gt;\n</code></pre>\n\n<p>We have some instructions to print on UI. The set of instructions is huge and of course we read those from XML file.</p>\n\n<p>In such cases the above method is easy to use and maintain too. That is because the content is provided by technical writers. They have no knowledge of XSL. They know using HTML tags and they can easily edit the XML file.</p>\n'}, {'answer_id': 59292527, 'author': 'Ricardo PSilva', 'author_id': 3179207, 'author_profile': 'https://Stackoverflow.com/users/3179207', 'pm_score': 0, 'selected': False, 'text': '<p>the correct way to use the strong tag is </p>\n\n<pre><code>&lt;strong&gt;This text is strong&lt;/strong&gt;\n</code></pre>\n\n<p>not <code>&lt;strong&gt;</code> at the end</p>\n\n<p>Here is the information reference: <a href="https://www.w3schools.com/html/html_formatting.asp" rel="nofollow noreferrer">https://www.w3schools.com/html/html_formatting.asp</a></p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78884', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5989/']
78,905
<p>More specifically I am trying to make the mailto component show within my template; the same way as an article does. </p> <p>By default the mailto component opens in a new window. So far I changed the code so it opens on the same window, but that way the whole template is gone.</p> <p>Any suggestions?</p>
[{'answer_id': 86132, 'author': 'julz', 'author_id': 16536, 'author_profile': 'https://Stackoverflow.com/users/16536', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m afraid I can\'t entirely follow your question - do you want to have a sign up form for membership or email notifications shown as an article? If so, then the easiest way is to install \'m2c\' - the \'module to component\' component. Then you can put any module (ie the sign up box) in the centre content area.</p>\n\n<p>The m2c component can be found here: <a href="http://joomla.focalizaisso.com.br/en/componentes/index.php" rel="nofollow noreferrer">http://joomla.focalizaisso.com.br/en/componentes/index.php</a></p>\n'}, {'answer_id': 279605, 'author': 'Bingy', 'author_id': 69518, 'author_profile': 'https://Stackoverflow.com/users/69518', 'pm_score': 2, 'selected': False, 'text': '<p>In the template there is a tag which takes the contents of a component. An article is a com_content component. you are trying to put in a caom_mail_to component? The beauty is that they both plug into the same slot.</p>\n\n<p>Now you can only ever have one component on a page. you can have lots of modules, but only one component.</p>\n\n<p>you set which component is on a page by choosing it from the menu comands. (each menu item refers to a component.) generaly the componetsn are of the com_content type, and are articles, but in your case you are wanting to add a component called com_mailto? Asuming the component is installed, all you have to do is select the new butto0n when in menu item manager, and then select the mailto component type.</p>\n\n<p>the tag that is being used in a joomla 1.5 template is: </p>\n\n<pre><code>&lt;jdoc:include type="component" /&gt;\n</code></pre>\n\n<p>If on the other hand you are trying to add a module to the template, that is a different kettle of fish. Youy need to create an instance of teh module, assign it to a tag (which exiusts in teh template) then select which menu items the module will be published on. The tag in a template for a module is like:</p>\n\n<pre><code>&lt;jdoc:include type="modules" name="module_name_place_holder" /&gt;\n</code></pre>\n\n<p>you can put more than one module into a single place holder.</p>\n\n<p>If you already have this basic knowlge, pass on the details of this component, and we will see if we cant find you a better solution. </p>\n'}, {'answer_id': 677241, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': True, 'text': '<p>use "component as content" plugin</p>\n\n<p><a href="http://extensions.joomla.org/extensions/core-enhancements/embed-&amp;-include/5947/details" rel="nofollow noreferrer">http://extensions.joomla.org/extensions/core-enhancements/embed-&amp;-include/5947/details</a></p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78905', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/131/']
78,909
<p>I have a few scripts on a site I recently started maintaining. I get those Object Not Found errors in IE6 (which Firefox fails to report in its Error Console?). What's the best way to debug these- any good cross-browser-compatible IDEs, or javascript debugging libraries of some sort?</p>
[{'answer_id': 78919, 'author': 'William', 'author_id': 9193, 'author_profile': 'https://Stackoverflow.com/users/9193', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.getfirebug.com" rel="nofollow noreferrer">Firebug</a></p>\n\n<p>It\'s only for firefox but it should let you figure out what\'s happening on IE especially once you have the script line numbers.</p>\n'}, {'answer_id': 78929, 'author': 'mopoke', 'author_id': 14054, 'author_profile': 'https://Stackoverflow.com/users/14054', 'pm_score': 3, 'selected': True, 'text': '<p>There\'s no cross-browser JS debugger that I know of (because most browsers use different JS engines).</p>\n\n<p>For firefox, I\'d definitely recommend firebug (<a href="http://www.getfirebug.com" rel="nofollow noreferrer">http://www.getfirebug.com</a>)</p>\n\n<p>For IE, the best I\'ve found is Microsoft Script Debugger (<a href="http://www.microsoft.com/downloads/details.aspx?familyid=2f465be0-94fd-4569-b3c4-dffdf19ccd99&amp;displaylang=en" rel="nofollow noreferrer">http://www.microsoft.com/downloads/details.aspx?familyid=2f465be0-94fd-4569-b3c4-dffdf19ccd99&amp;displaylang=en</a>). If you have Office installed, you may also have Microsoft Script Editor installed. To use either of these, you need to turn on script debugging in IE. (uncheck Tools -> Internet Options -> Advanced -> Disable Script debugging).</p>\n'}, {'answer_id': 78930, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 1, 'selected': False, 'text': "<ol>\n<li>You can use Visual Studio and enable debugging in browser</li>\n<li>You can install FireBug plugin for Firefox, it's really good!</li>\n<li>You can try to install IE8 beta 2 and use it in compatibility mode with built-in debugger.</li>\n</ol>\n\n<p>Also in any line of your JS code you can write </p>\n\n<pre><code>debugger;\n</code></pre>\n\n<p>and this will be threated as breakpoint for any of the debug tools you use.</p>\n\n<p>Cheers!</p>\n"}, {'answer_id': 78946, 'author': 'Svet', 'author_id': 8934, 'author_profile': 'https://Stackoverflow.com/users/8934', 'pm_score': 0, 'selected': False, 'text': '<p>You could use this tool apparently - <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2f465be0-94fd-4569-b3c4-dffdf19ccd99&amp;displaylang=en" rel="nofollow noreferrer">Microsoft Script Debugger</a></p>\n\n<p>Personally I try to go through the code and figure out what\'s going on - it gives you the line number where it goes wrong right? </p>\n'}, {'answer_id': 78975, 'author': 'David Negron', 'author_id': 981, 'author_profile': 'https://Stackoverflow.com/users/981', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.aptana.com/studio" rel="nofollow noreferrer">Aptana Studio</a> provides JavaScript debugging for Firefox and IE</p>\n'}, {'answer_id': 79096, 'author': 'madcolor', 'author_id': 13954, 'author_profile': 'https://Stackoverflow.com/users/13954', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.getfirebug.com" rel="nofollow noreferrer">Firebug</a> is the best all around client-side debugger. I frequently use it to debug CSS code as well as javascript. It allows you to easily find offending areas of code. I especially like the ability to modify tag attributes in the firebug pane and see the effects immediately before committing. Very useful for anyone designing websites.</p>\n'}, {'answer_id': 79364, 'author': 'Darren Newton', 'author_id': 12799, 'author_profile': 'https://Stackoverflow.com/users/12799', 'pm_score': 2, 'selected': False, 'text': '<p>You could also use <a href="http://getfirebug.com/lite.html" rel="nofollow noreferrer">Firebug Lite</a> - which will work in IE &amp; Opera. It\'s an external lib that will help you track down problems. It\'s sometimes more convenient than dealing with the MS Script Debugger.</p>\n'}, {'answer_id': 81388, 'author': 'Kristian J.', 'author_id': 4588, 'author_profile': 'https://Stackoverflow.com/users/4588', 'pm_score': 0, 'selected': False, 'text': '<p>To make the Microsoft Script Debugger more user friendly (and to add javascript error messages that actually are helpful to IE), I highly recommend <a href="http://www.my-debugbar.com/wiki/CompanionJS/HomePage" rel="nofollow noreferrer">Companion.JS</a>.</p>\n'}, {'answer_id': 81442, 'author': 'Tyler', 'author_id': 3561, 'author_profile': 'https://Stackoverflow.com/users/3561', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://getfirebug.com/" rel="nofollow noreferrer">Firebug</a> seems to be the most useful so far. When a page is running on firebug, it can be very handy to log messages into firebug via javascript calls to <strong>console.log(\'your log message\');</strong> but don\'t execute that code in IE since the console object is only in scope when firebug is running.</p>\n\n<p>For IE, other folks have mentioned the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2f465be0-94fd-4569-b3c4-dffdf19ccd99&amp;displaylang=en" rel="nofollow noreferrer">Script Debugger</a>. Although it is not primarily for javascript debugging, it can be useful to also add the <a href="http://en.wikipedia.org/wiki/IE_Developer_Toolbar" rel="nofollow noreferrer">IE developer toolbar</a>, which allows you to easily and dynamically inspect the style and other properties of your page\'s DOM.</p>\n'}, {'answer_id': 81454, 'author': 'Glenn', 'author_id': 11814, 'author_profile': 'https://Stackoverflow.com/users/11814', 'pm_score': 0, 'selected': False, 'text': "<p>In response to mopoke, for IE6 you definitely want to use Visual Studio for debugging if you can get it. For all intents and purposes, the MS script debugger is useless. You're better off using some form of tracing (not alerts) than using the MS script debugger. Dojo Toolkit, for instance, provides a debug console for tracing, but you can write your own by dumping messages to a secondary window or div. </p>\n\n<p>The script debugger needlessly prompts you on each error in IE6 and even then doesn't give you enough state context to make it useful in a sufficiently complex JS app. Visual Studio is more tightly integrated and much friendlier. Just my experience. </p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/78909', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14563/']
78,913
<p>What is the single most effective practice to prevent <a href="http://en.wikipedia.org/wiki/Arithmetic_overflow" rel="nofollow noreferrer">arithmetic overflow</a> and <a href="http://en.wikipedia.org/wiki/Arithmetic_underflow" rel="nofollow noreferrer">underflow</a>?</p> <p>Some examples that come to mind are:</p> <ul> <li>testing based on valid input ranges</li> <li>validation using formal methods</li> <li>use of invariants</li> <li>detection at runtime using language features or libraries (this does not prevent it)</li> </ul>
[{'answer_id': 78936, 'author': 'Eclipse', 'author_id': 8701, 'author_profile': 'https://Stackoverflow.com/users/8701', 'pm_score': 3, 'selected': True, 'text': '<p>One possibility is to use a language that has arbitrarily sized integers that never overflow / underflow.</p>\n\n<p>Otherwise, if this is something you\'re really concerned about, and if your language allows it, write a wrapper class that acts like an integer, but checks every operation for overflow. You could even have it do the check on debug builds, and leave things optimized for release builds. In a language like C++, you could do this, and it would behave almost exactly like an integer for release builds, but for debug builds you\'d get full run-time checking.</p>\n\n<pre><code>class CheckedInt\n{\nprivate: \n int Value;\n\npublic:\n // Constructor\n CheckedInt(int src) : Value(src) {}\n\n // Conversions back to int\n operator int&amp;() { return Value; }\n operator const int &amp;() const { return Value; }\n\n // Operators\n CheckedInt operator+(CheckedInt rhs) const\n {\n if (rhs.Value &lt; 0 &amp;&amp; rhs.Value + Value &gt; Value)\n throw OverflowException();\n if (rhs.Value &gt; 0 &amp;&amp; rhs.Value + Value &lt; Value)\n throw OverflowException();\n return CheckedInt(rhs.Value + Value);\n }\n\n // Lots more operators...\n};\n</code></pre>\n\n<p>Edit:</p>\n\n<p>Turns out someone is <a href="http://www.codeplex.com/SafeInt" rel="nofollow noreferrer">doing this already for C++</a> - the current implementation is focused for Visual Studio, but it looks like they\'re getting support for gcc as well.</p>\n'}, {'answer_id': 78941, 'author': 'itsmatt', 'author_id': 7862, 'author_profile': 'https://Stackoverflow.com/users/7862', 'pm_score': 1, 'selected': False, 'text': '<p>I write a lot of test code to do range/validity checking on my code. This tends to catch most of these types of situations - and definitely helps me write more bulletproof code.</p>\n'}, {'answer_id': 78949, 'author': 'postfuturist', 'author_id': 1892, 'author_profile': 'https://Stackoverflow.com/users/1892', 'pm_score': 1, 'selected': False, 'text': '<p>Use high precision floating point numbers like a <a href="http://en.wikipedia.org/wiki/Long_double" rel="nofollow noreferrer">long double</a>.</p>\n'}, {'answer_id': 79074, 'author': 'Jörg W Mittag', 'author_id': 2988, 'author_profile': 'https://Stackoverflow.com/users/2988', 'pm_score': 1, 'selected': False, 'text': "<p>I think you are missing one very important option in your list: choose the right programming language for the job. There are many programming languages which do not have these problems, because they don't have fixed size integers.</p>\n"}, {'answer_id': 79470, 'author': 'pro3carp3', 'author_id': 7899, 'author_profile': 'https://Stackoverflow.com/users/7899', 'pm_score': 0, 'selected': False, 'text': "<p>There are more important considerations when choosing which language you use than the size of the integer. Simply check your input if you don't know if the value is in bounds, or use exception handling if the case is extremely rare.</p>\n"}, {'answer_id': 1028197, 'author': 'mturquette', 'author_id': 123330, 'author_profile': 'https://Stackoverflow.com/users/123330', 'pm_score': 0, 'selected': False, 'text': "<p>A wrapper that checks for inconsistencies will make sense in many cases. If an additive operation (ie, addition or multiplication) on two or more integers results in a smaller value than the operands then you know something went wrong. Every additive operation should be followed by,</p>\n\n<pre><code>if (sum &lt; operand1 || sum &lt; operand2)\n omg_error();\n</code></pre>\n\n<p>Likewise any operation that should logically result in a smaller value should be check to see if it was accidentally embiggin'd.</p>\n"}, {'answer_id': 9234479, 'author': 'Jay Abraham', 'author_id': 893216, 'author_profile': 'https://Stackoverflow.com/users/893216', 'pm_score': 0, 'selected': False, 'text': '<p>Have you investigated the use of formal methods to check your code to prove that it is free of overflows? A formal methods technique known as abstract interpretation can check the robustness of your software to prove that your software will not suffer from an overflow, underflow, divide by zero, overflow, or other similar run-time error. It is a mathematical technique that exhaustively analyzes your software. The technique was pioneered by Patrick Cousot in the 1970s. It was successfully used to diagnose an overflow condition in the Arian 5 rocket where an overflow caused the destruction of the launch vehicle. The overflow was caused while converting a floating point number to an integer. You can find more information about this technique <a href="http://www.mathworks.com/discovery/formal-methods.html" rel="nofollow">here</a> and also on <a href="http://en.wikipedia.org/wiki/Abstract_interpretation" rel="nofollow">Wikipedia</a>.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78913', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3836/']
78,924
<p>I have written a message handler function in Outlook's Visual Basic (we're using Outlook 2003 and Exchange Server) to help me sort out incoming email. </p> <p>It is working for me, except sometimes the rule fails and Outlook deactivates it. </p> <p>Then I turn the rule back on and manually run it on my Inbox to catch up. The rule spontaneously fails and deactivates several times a day. </p> <p>I would love to fix this once and for all.</p>
[{'answer_id': 79000, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>have written a message handler function in Outlook\'s Visual Basic (we\'re using Outlook 2003 and Exchange Server) to help me sort out incoming email. It is working for me, except sometimes the rule fails and Outlook deactivates it. Then I turn the rule back on and manually run it on my Inbox to catch up. The rule spontaneously fails and deactivates several times a day. I would love to fix this once and for all.</p>\n\n<p>Here is the code stripped of the functionality, but giving you an idea of how it looks:</p>\n\n<pre><code> Public WithEvents myOlItems As Outlook.Items\n\n Public Sub Application_Startup()\n \' Reference the items in the Inbox. Because myOlItems is declared\n \' "WithEvents" the ItemAdd event will fire below.\n \' Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items\n Set myOlItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items\n End Sub\n\n Private Sub myOlItems_ItemAdd(ByVal Item As Object)\n On Error Resume Next\n If TypeName(Item) = "MailItem" Then\n MyMessageHandler Item\n End If\n End Sub\n\n Public Sub MyMessageHandler(ByRef Item As MailItem)\n Dim strSender As String\n Dim strSubject As String\n\n If TypeName(Item) &lt;&gt; "MailItem" Then\n Exit Sub\n End If\n\n strSender = LCase(Item.SenderEmailAddress)\n strSubject = Item.Subject\n\n rem do stuff\n rem do stuff\n rem do stuff\n End Sub\n</code></pre>\n\n<p>One error I get is "Type Mismatch" calling MyMessageHandler where VB complains that Item is not a MailItem. Okay, but TypeName(Item) returns "MailItem", so how come Item is not a MailItem?</p>\n\n<p>Another one I get is where an email with an empty subject comes along. The line</p>\n\n<pre><code>strSubject = Item.Subject\n</code></pre>\n\n<p>gives me an error. I know Item.Subject should be blank, but why is that an error?</p>\n\n<p>Thanks.</p>\n'}, {'answer_id': 150607, 'author': 'Dave DuPlantis', 'author_id': 8174, 'author_profile': 'https://Stackoverflow.com/users/8174', 'pm_score': 2, 'selected': False, 'text': "<p>My memory is somewhat cloudy on this, but I believe that a MailItem is not a MailItem when it is something like a read receipt. (Unfortunately, the VBA code that demonstrated this was written at another job and isn't around now.)</p>\n\n<p>I also had code written to process incoming messages, probably for the same reason you did (too many rules for Exchange, or rules too complex for the Rules Wizard), and seem to recall running into the same problem you have, that some items seemed to be from a different type even though I was catching them with something like what you wrote.</p>\n\n<p>I'll see if I can produce a specific example if it will help.</p>\n"}, {'answer_id': 8672202, 'author': 'Killian Tyler', 'author_id': 1121762, 'author_profile': 'https://Stackoverflow.com/users/1121762', 'pm_score': 4, 'selected': False, 'text': '<p>This code showed me the different TypeNames that were in my Inbox:</p>\n\n<pre><code>Public Sub GetTypeNamesInbox()\nDim myOlItems As Outlook.Items\nSet myOlItems = application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items\nDim msg As Object\n\nFor Each msg In myOlItems\n Debug.Print TypeName(msg)\n \'emails are typename MailItem\n \'Meeting responses are typename MeetingItem\n \'Delivery receipts are typename ReportItem\nNext msg\n\nEnd Sub\n</code></pre>\n\n<p>HTH</p>\n'}, {'answer_id': 11145745, 'author': 'JimmyPena', 'author_id': 190829, 'author_profile': 'https://Stackoverflow.com/users/190829', 'pm_score': 1, 'selected': False, 'text': '<p>There are many types of items that can be seen in the default Inbox.</p>\n\n<p>In the called procedure, assign the incoming item to an <code>Object</code> type variable. Then use <code>TypeOf</code> or <code>TypeName</code> to determine if it is a <code>MailItem</code>. Only then should your code perform actions that apply to emails.</p>\n\n<p>i.e.</p>\n\n<pre><code>Dim obj As Object\n\nIf TypeName(obj) = "MailItem" Then\n \' your code for mail items here\nEnd If\n</code></pre>\n'}, {'answer_id': 11634371, 'author': 'Radek', 'author_id': 1549220, 'author_profile': 'https://Stackoverflow.com/users/1549220', 'pm_score': 1, 'selected': False, 'text': '<pre><code>Dim objInboxFolder As MAPIFolder\nDim oItem As MailItem\nSet objInboxFolder = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)\n\nFor Each Item In objInboxFolder.Items\n If TypeName(Item) = "MailItem" Then\n Set oItem = Item\n\nnext\n</code></pre>\n'}, {'answer_id': 12183994, 'author': 'Bruce E. Leandro', 'author_id': 1634032, 'author_profile': 'https://Stackoverflow.com/users/1634032', 'pm_score': 2, 'selected': False, 'text': '<p>I use the following VBA code snippet in other Office Applications, where the Outlook Library is directly referenced.</p>\n\n<pre><code>\' Outlook Variables\n\n Dim objOutlook As Outlook.Application: Set objOutlook = New Outlook.Application\n Dim objNameSpace As Outlook.NameSpace: Set objNameSpace = objOutlook.GetNamespace("MAPI")\n Dim objFolder As MAPIFolder: Set objFolder = objNameSpace.PickFolder()\n Dim objMailItem As Outlook.MailItem\n\n Dim iCounter As Integer: iCounter = objFolder.Items.Count\n Dim i As Integer\n\n For i = iCounter To 1 Step -1\n If TypeOf objFolder.Items(i) Is MailItem Then\n Set objMailItem = objFolder.Items(i)\n With objMailItem\n</code></pre>\n\n<p>etc.</p>\n'}, {'answer_id': 16250499, 'author': 'htd', 'author_id': 2234464, 'author_profile': 'https://Stackoverflow.com/users/2234464', 'pm_score': 0, 'selected': False, 'text': '<p>why not use a simple error handler for the code? Seriously. You could write an error for each read of a property or object that seems to fail. Then have it Resume no matter what. No need for complex error handling. Think of a test that shows an empty subject. Since you don\'t know what value it will return, if any, and it seems to error on an empty or blank subject, you need to picture it as a simple test with a possible error. Run the test as an if statement (one in which you will get an error anyway), and have the program resume on error.<br/></p>\n\n<pre><code>On Error Resume Next\nIf object.subject = Null \'produces an error when subject is null, otherwise allows a good read\n strSubject = "" \'sets the subject grab string to a null or empty string as a string\nElse\n strSubject = object.subject \'Sets the subject grab string to the subject of the message\\item\nEnd If\n</code></pre>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78924', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
78,932
<p>I have the following HTML <code>&lt;select&gt;</code> element:</p> <pre><code>&lt;select id="leaveCode" name="leaveCode"&gt; &lt;option value="10"&gt;Annual Leave&lt;/option&gt; &lt;option value="11"&gt;Medical Leave&lt;/option&gt; &lt;option value="14"&gt;Long Service&lt;/option&gt; &lt;option value="17"&gt;Leave Without Pay&lt;/option&gt; &lt;/select&gt; </code></pre> <p>Using a JavaScript function with the <code>leaveCode</code> number as a parameter, how do I select the appropriate option in the list?</p>
[{'answer_id': 78945, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 11, 'selected': True, 'text': '<p>You can use this function:</p>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>function selectElement(id, valueToSelect) { \n let element = document.getElementById(id);\n element.value = valueToSelect;\n}\n\nselectElement(\'leaveCode\', \'11\');</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;select id="leaveCode" name="leaveCode"&gt;\n &lt;option value="10"&gt;Annual Leave&lt;/option&gt;\n &lt;option value="11"&gt;Medical Leave&lt;/option&gt;\n &lt;option value="14"&gt;Long Service&lt;/option&gt;\n &lt;option value="17"&gt;Leave Without Pay&lt;/option&gt;\n&lt;/select&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n<p>Optionally if you want to trigger onchange event also, you can use :</p>\n<pre><code>element.dispatchEvent(new Event(\'change\'))\n</code></pre>\n'}, {'answer_id': 78947, 'author': 'Chase Seibert', 'author_id': 7679, 'author_profile': 'https://Stackoverflow.com/users/7679', 'pm_score': 5, 'selected': False, 'text': "<p>Not answering the question, but you can also select by index, where i is the index of the item you wish to select:</p>\n\n<pre><code>var formObj = document.getElementById('myForm');\nformObj.leaveCode[i].selected = true;\n</code></pre>\n\n<p>You can also loop through the items to select by display value with a loop:</p>\n\n<pre><code>for (var i = 0, len &lt; formObj.leaveCode.length; i &lt; len; i++) \n if (formObj.leaveCode[i].value == 'xxx') formObj.leaveCode[i].selected = true;\n</code></pre>\n"}, {'answer_id': 78950, 'author': 'Lucas Oman', 'author_id': 6726, 'author_profile': 'https://Stackoverflow.com/users/6726', 'pm_score': -1, 'selected': False, 'text': '<p>I\'m afraid I\'m unable to test this at the moment, but in the past, I believe I had to give each option tag an ID, and then I did something like:</p>\n\n<pre><code>document.getElementById("optionID").select();\n</code></pre>\n\n<p>If that doesn\'t work, maybe it\'ll get you closer to a solution :P</p>\n'}, {'answer_id': 78954, 'author': 'mmattax', 'author_id': 1638, 'author_profile': 'https://Stackoverflow.com/users/1638', 'pm_score': 2, 'selected': False, 'text': "<pre>\n<code>\nfunction foo(value)\n{\n var e = document.getElementById('leaveCode');\n if(e) e.value = value;\n}\n</code>\n</pre>\n"}, {'answer_id': 78960, 'author': 'William', 'author_id': 9193, 'author_profile': 'https://Stackoverflow.com/users/9193', 'pm_score': 4, 'selected': False, 'text': '<pre><code>document.getElementById(\'leaveCode\').value = \'10\';\n</code></pre>\n\n<p>That should set the selection to "Annual Leave"</p>\n'}, {'answer_id': 78976, 'author': 'Stephen Wrighton', 'author_id': 7516, 'author_profile': 'https://Stackoverflow.com/users/7516', 'pm_score': 2, 'selected': False, 'text': "<p>Should be something along these lines:</p>\n\n<pre><code>function setValue(inVal){\nvar dl = document.getElementById('leaveCode');\nvar el =0;\nfor (var i=0; i&lt;dl.options.length; i++){\n if (dl.options[i].value == inVal){\n el=i;\n break;\n }\n}\ndl.selectedIndex = el;\n}\n</code></pre>\n"}, {'answer_id': 79040, 'author': 'Robert Swisher', 'author_id': 1852, 'author_profile': 'https://Stackoverflow.com/users/1852', 'pm_score': 1, 'selected': False, 'text': "<p>Why not add a variable for the element's Id and make it a reusable function?</p>\n\n<pre><code>function SelectElement(selectElementId, valueToSelect)\n{ \n var element = document.getElementById(selectElementId);\n element.value = valueToSelect;\n}\n</code></pre>\n"}, {'answer_id': 79528, 'author': 'Milan Babuškov', 'author_id': 14690, 'author_profile': 'https://Stackoverflow.com/users/14690', 'pm_score': 2, 'selected': False, 'text': '<p>Suppose your form is named <strong>form1</strong>:</p>\n\n<pre><code>function selectValue(val)\n{\n var lc = document.form1.leaveCode;\n for (i=0; i&amp;lt;lc.length; i++)\n {\n if (lc.options[i].value == val)\n {\n lc.selectedIndex = i;\n return;\n }\n }\n}\n</code></pre>\n'}, {'answer_id': 79534, 'author': 'Andrew Hedges', 'author_id': 11577, 'author_profile': 'https://Stackoverflow.com/users/11577', 'pm_score': 5, 'selected': False, 'text': "<pre><code>function setSelectValue (id, val) {\n document.getElementById(id).value = val;\n}\nsetSelectValue('leaveCode', 14);\n</code></pre>\n"}, {'answer_id': 4519880, 'author': 'Einar Ólafsson', 'author_id': 373032, 'author_profile': 'https://Stackoverflow.com/users/373032', 'pm_score': 7, 'selected': False, 'text': '<p>If you are using jQuery you can also do this:</p>\n\n<pre><code>$(\'#leaveCode\').val(\'14\');\n</code></pre>\n\n<p>This will select the <code>&lt;option&gt;</code> with the value of 14.</p>\n\n<hr>\n\n<p>With plain Javascript, this can also be achieved with two <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document#Methods" rel="noreferrer"><code>Document</code> methods</a>:</p>\n\n<ul>\n<li><p>With <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector" rel="noreferrer"><code>document.querySelector</code></a>, you can select an element based on a CSS selector:</p>\n\n<pre><code>document.querySelector(\'#leaveCode\').value = \'14\'\n</code></pre></li>\n<li><p>Using the more established approach with <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById" rel="noreferrer"><code>document.getElementById()</code></a>, that will, as the name of the function implies, let you select an element based on its <code>id</code>:</p>\n\n<pre><code>document.getElementById(\'leaveCode\').value = \'14\'\n</code></pre></li>\n</ul>\n\n<p>You can run the below code snipped to see these methods and the jQuery function in action:</p>\n\n<p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">\r\n<div class="snippet-code snippet-currently-hidden">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>const jQueryFunction = () =&gt; {\r\n \r\n $(\'#leaveCode\').val(\'14\'); \r\n \r\n}\r\n\r\nconst querySelectorFunction = () =&gt; {\r\n \r\n document.querySelector(\'#leaveCode\').value = \'14\' \r\n \r\n}\r\n\r\nconst getElementByIdFunction = () =&gt; {\r\n \r\n document.getElementById(\'leaveCode\').value=\'14\' \r\n \r\n}</code></pre>\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>input {\r\n display:block;\r\n margin: 10px;\r\n padding: 10px\r\n}</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;select id="leaveCode" name="leaveCode"&gt;\r\n &lt;option value="10"&gt;Annual Leave&lt;/option&gt;\r\n &lt;option value="11"&gt;Medical Leave&lt;/option&gt;\r\n &lt;option value="14"&gt;Long Service&lt;/option&gt;\r\n &lt;option value="17"&gt;Leave Without Pay&lt;/option&gt;\r\n&lt;/select&gt;\r\n\r\n&lt;input type="button" value="$(\'#leaveCode\').val(\'14\');" onclick="jQueryFunction()" /&gt;\r\n&lt;input type="button" value="document.querySelector(\'#leaveCode\').value = \'14\'" onclick="querySelectorFunction()" /&gt;\r\n&lt;input type="button" value="document.getElementById(\'leaveCode\').value = \'14\'" onclick="getElementByIdFunction()" /&gt;\r\n\r\n&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}, {'answer_id': 5346940, 'author': 'Lana', 'author_id': 665322, 'author_profile': 'https://Stackoverflow.com/users/665322', 'pm_score': 2, 'selected': False, 'text': '<p>The easiest way if you need to:<br>\n1) Click a button which defines select option<br>\n2) Go to another page, where select option is<br>\n3) Have that option value selected on another page</p>\n\n<p><strong>1)</strong> your button links (say, on home page)</p>\n\n<pre><code>&lt;a onclick="location.href=\'contact.php?option=1\';" style="cursor:pointer;"&gt;Sales&lt;/a&gt;\n&lt;a onclick="location.href=\'contact.php?option=2\';" style="cursor:pointer;"&gt;IT&lt;/a&gt;\n</code></pre>\n\n<p>(where <strong>contact.php</strong> is your page with select options. Note the page url has ?option=1 or 2)</p>\n\n<p><strong>2)</strong> put this code on your second page (my case <strong>contact.php</strong>) </p>\n\n<pre><code>&lt;?\nif (isset($_GET[\'option\']) &amp;&amp; $_GET[\'option\'] != "") {\n$pg = $_GET[\'option\']; \n} ?&gt;\n</code></pre>\n\n<p><strong>3)</strong> make the option value selected, depending on the button clicked</p>\n\n<pre><code>&lt;select&gt;\n&lt;option value="Sales" &lt;? if ($pg == \'1\') { echo "selected"; } ?&gt; &gt;Sales&lt;/option&gt;\n&lt;option value="IT" &lt;? if ($pg == \'2\') { echo "selected"; } ?&gt; &gt;IT&lt;/option&gt;\n&lt;/select&gt;\n</code></pre>\n\n<p>.. and so on.<br>\nSo this is an easy way of passing the value to another page (with select option list) through GET in url. No forms, no IDs.. just 3 steps and it works perfect.</p>\n'}, {'answer_id': 11905147, 'author': 'Toskan', 'author_id': 533426, 'author_profile': 'https://Stackoverflow.com/users/533426', 'pm_score': 4, 'selected': False, 'text': '<p>I compared the different methods:</p>\n\n<p><a href="https://jsfiddle.net/8sM7s/1/" rel="nofollow noreferrer">Comparison of the different ways on how to set a value of a select with JS or jQuery</a></p>\n\n<p>code:</p>\n\n<pre class="lang-js prettyprint-override"><code>$(function() {\n var oldT = new Date().getTime();\n var element = document.getElementById(\'myId\');\n element.value = 4;\n console.error(new Date().getTime() - oldT);\n\n oldT = new Date().getTime();\n $("#myId option").filter(function() {\n return $(this).attr(\'value\') == 4;\n }).attr(\'selected\', true);\n console.error(new Date().getTime() - oldT);\n\n oldT = new Date().getTime();\n $("#myId").val("4");\n console.error(new Date().getTime() - oldT);\n});\n</code></pre>\n\n<p>Output on a select with ~4000 elements:</p>\n\n<ul>\n<li>1 ms </li>\n<li>58 ms</li>\n<li>612 ms</li>\n</ul>\n\n<p>With Firefox 10. Note: The only reason I did this test, was because jQuery performed super poorly on our list with ~2000 entries (they had longer texts between the options).\nWe had roughly 2 s delay after a val()</p>\n\n<p>Note as well: I am setting value depending on the real value, not the text value.</p>\n'}, {'answer_id': 21422704, 'author': 'almyz125', 'author_id': 1253882, 'author_profile': 'https://Stackoverflow.com/users/1253882', 'pm_score': -1, 'selected': False, 'text': '<p>If using PHP you could try something like this:</p>\n\n<pre><code>$value = \'11\';\n$first = \'\';\n$second = \'\';\n$third = \'\';\n$fourth = \'\';\n\nswitch($value) {\n case \'10\' :\n $first = \'selected\';\n break;\n case \'11\' :\n $second = \'selected\';\n break;\n case \'14\' :\n $third = \'selected\';\n break;\n case \'17\' :\n $fourth = \'selected\';\n break;\n }\n\necho\'\n&lt;select id="leaveCode" name="leaveCode"&gt;\n &lt;option value="10" \'. $first .\'&gt;Annual Leave&lt;/option&gt;\n &lt;option value="11" \'. $second .\'&gt;Medical Leave&lt;/option&gt;\n &lt;option value="14" \'. $third .\'&gt;Long Service&lt;/option&gt;\n &lt;option value="17" \'. $fourth .\'&gt;Leave Without Pay&lt;/option&gt;\n&lt;/select&gt;\';\n</code></pre>\n'}, {'answer_id': 30573683, 'author': 'lumi77', 'author_id': 236928, 'author_profile': 'https://Stackoverflow.com/users/236928', 'pm_score': 4, 'selected': False, 'text': '<p>I tried the above JavaScript/jQuery-based solutions, such as: </p>\n\n<pre><code>$("#leaveCode").val("14");\n</code></pre>\n\n<p>and</p>\n\n<pre><code>var leaveCode = document.querySelector(\'#leaveCode\');\nleaveCode[i].selected = true;\n</code></pre>\n\n<p>in an AngularJS app, where there was a <strong>required</strong> &lt;select&gt; element.</p>\n\n<p>None of them works, because the AngularJS form validation is not fired. Although the right option was selected (and is displayed in the form), the input remained invalid (<strong>ng-pristine</strong> and <strong>ng-invalid</strong> classes still present).</p>\n\n<p>To force the AngularJS validation, call jQuery <a href="https://api.jquery.com/change/" rel="noreferrer">change()</a> after selecting an option:</p>\n\n<pre><code>$("#leaveCode").val("14").change();\n</code></pre>\n\n<p>and</p>\n\n<pre><code>var leaveCode = document.querySelector(\'#leaveCode\');\nleaveCode[i].selected = true;\n$(leaveCode).change();\n</code></pre>\n'}, {'answer_id': 37445649, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': -1, 'selected': False, 'text': '<p>You most likely want this:</p>\n\n<pre><code>$("._statusDDL").val(\'2\');\n</code></pre>\n\n<p>OR</p>\n\n<pre><code>$(\'select\').prop(\'selectedIndex\', 3); \n</code></pre>\n'}, {'answer_id': 63377136, 'author': 'Ashutosh Tiwari', 'author_id': 12125692, 'author_profile': 'https://Stackoverflow.com/users/12125692', 'pm_score': 0, 'selected': False, 'text': "<p>Most of the code mentioned here didn't worked for me!</p>\n<p><strong>At last, this worked</strong></p>\n<p><em><strong>window.addEventListener</strong> is important, otherwise, your JS code will run before values are fetched in the Options</em></p>\n<pre><code> window.addEventListener(&quot;load&quot;, function () {\n // Selecting Element with ID - leaveCode //\n var formObj = document.getElementById('leaveCode');\n\n // Setting option as selected\n let len;\n for (let i = 0, len = formObj.length; i &lt; len; i++){\n if (formObj[i].value == '&lt;value to show in Select&gt;') \n formObj.options[i].selected = true;\n }\n });\n</code></pre>\n<p>Hope, this helps!</p>\n"}, {'answer_id': 63882977, 'author': 'Kamil Kiełczewski', 'author_id': 860099, 'author_profile': 'https://Stackoverflow.com/users/860099', 'pm_score': 4, 'selected': False, 'text': '<h1>Short</h1>\n<p>This is size improvement of <a href="https://stackoverflow.com/a/78960/860099">William answer</a></p>\n<pre><code>leaveCode.value = \'14\';\n</code></pre>\n<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">\r\n<div class="snippet-code snippet-currently-hidden">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>leaveCode.value = \'14\';</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;select id="leaveCode" name="leaveCode"&gt;\n &lt;option value="10"&gt;Annual Leave&lt;/option&gt;\n &lt;option value="11"&gt;Medical Leave&lt;/option&gt;\n &lt;option value="14"&gt;Long Service&lt;/option&gt;\n &lt;option value="17"&gt;Leave Without Pay&lt;/option&gt;\n&lt;/select&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78932', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6340/']
78,974
<p>I've written a control that inherits from the <code>System.Web.UI.WebControls.DropDownList</code> and so I don't have any code in front for this control, but I still want to set the OutputCache directive. I there any way to set this in the C# code, say with an attribute or something like that? </p> <p>I'm particularly hoping to be able to replicate the <code>VaryByParam</code> property</p>
[{'answer_id': 79012, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 1, 'selected': False, 'text': '<pre><code>Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));\nResponse.Cache.SetCacheability(HttpCacheability.Server);\nResponse.Cache.SetValidUntilExpires(true);\n</code></pre>\n'}, {'answer_id': 3258564, 'author': 'matt-dot-net', 'author_id': 380518, 'author_profile': 'https://Stackoverflow.com/users/380518', 'pm_score': 3, 'selected': True, 'text': '<p>I realize this is an incredibly old question but it is still worthy of an answer.</p>\n\n<p>What you are talking about isn\'t a User Control it is a Custom Control. What you want to do with the OutputCache can be done simply with the Context Cache.</p>\n\n<p>In your code where you are getting the data and binding to your DropDownList do something like this:</p>\n\n<pre><code> List&lt;Object&gt; listOfObjects = null;\n//assuming a List of Objects... it doesn\'t matter whatever type of data you use\n if (Context.Cache["MyDataCacheKey"] == null)\n {\n // data not cached, load it from database\n listOfObjects = GetDataFromDB();\n//add your data to the context cache with a sliding expiration of 10 minutes.\n Context.Cache.Add("MyDataCacheKey", listOfObjects, null,\n System.Web.Caching.Cache.NoAbsoluteExpiration,\n TimeSpan.FromMinutes(10.0),\n System.Web.Caching.CacheItemPriority.Normal, null);\n }\n else\n listOfObjects = (List&lt;Object&gt;)Context.Cache["MyDataCacheKey"];\n\n DropDownList1.DataSource = listOfObjects;\n DropDownList1.DataBind();\n</code></pre>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78974', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2975/']
78,978
<p>I'm working on a regular expression in a <code>.NET</code> project to get a specific tag. I would like to match the entire DIV tag and its contents:</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;title&gt;Test&lt;/title&gt;&lt;/head&gt; &lt;body&gt; &lt;p&gt;The first paragraph.&lt;/p&gt; &lt;div id='super_special'&gt; &lt;p&gt;The Store paragraph&lt;/p&gt; &lt;/div&gt; &lt;/body&gt; &lt;/head&gt; </code></pre> <p>Code:</p> <pre><code> Regex re = new Regex("(&lt;div id='super_special'&gt;.*?&lt;/div&gt;)", RegexOptions.Multiline); if (re.IsMatch(test)) Console.WriteLine("it matches"); else Console.WriteLine("no match"); </code></pre> <p>I want to match this:</p> <pre><code>&lt;div id="super_special"&gt; &lt;p&gt;Anything could go in here...doesn't matter. Let's get it all&lt;/p&gt; &lt;/div&gt; </code></pre> <p>I thought <code>.</code> was supposed to get all characters, but it seems to having trouble with the carriage returns. What is my regex missing?</p> <p>Thanks.</p>
[{'answer_id': 78985, 'author': 'mopoke', 'author_id': 14054, 'author_profile': 'https://Stackoverflow.com/users/14054', 'pm_score': 1, 'selected': False, 'text': '<p>Depends what language you\'re working in. \nFor example, in perl you\'d use the regex modifier s:</p>\n\n<pre><code>m{&lt;div id="super_special"&gt;.*?&lt;/span&gt;}s\n</code></pre>\n'}, {'answer_id': 78989, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 1, 'selected': False, 'text': "<p>What language are you using? In .NET you must set an option to ensure that it isn't single line. </p>\n"}, {'answer_id': 78992, 'author': 'Nescio', 'author_id': 14484, 'author_profile': 'https://Stackoverflow.com/users/14484', 'pm_score': 0, 'selected': False, 'text': '<p>. (dot) Matches any single character except line break characters \\r and \\n. Most regex flavors have an option to make the dot match line break characters too. . matches x or (almost) any other character </p>\n'}, {'answer_id': 78993, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 0, 'selected': False, 'text': '<p>maybe: .<em>[\\r\\n]</em>.<em>[\\r\\n]</em></p>\n'}, {'answer_id': 78995, 'author': 'Vinko Vrsalovic', 'author_id': 5190, 'author_profile': 'https://Stackoverflow.com/users/5190', 'pm_score': 1, 'selected': False, 'text': '<p>Depends on the language. If on python, you are missing the re.S flag, like this (to remove the match):</p>\n\n<pre><code>re.compile(\'&lt;div id="super_special"&gt;.*?&lt;/div&gt;\',re.S).sub(your_html,\'\')\n</code></pre>\n\n<p>Similar flags exist for other regexps implementations, they are called "Single Line" or "Multi Line" or something like that.</p>\n\n<p>But <strong>DO NOT USE REGEXPS TO PARSE HTML</strong>. It\'s a direct path to maintenance hell. Use a HTML parser like Beautiful Soup. Check <a href="https://stackoverflow.com/questions/55391/python-regular-expression-for-html-parsing-beautifulsoup#55424">these</a> <a href="https://stackoverflow.com/questions/2861/options-for-html-scraping#5093">links</a> for useful resources in that direction.</p>\n'}, {'answer_id': 79024, 'author': 'Jörg W Mittag', 'author_id': 2988, 'author_profile': 'https://Stackoverflow.com/users/2988', 'pm_score': 3, 'selected': False, 'text': "<p>Please, pretty please, do yourself a <em>huge</em> favor: use an HTML parser for parsing HTML. Seriously. That's what they are there for.</p>\n\n<p>HTML is a <em>very</em> complex language. No matter <em>how long</em> you will be tweaking, fiddling, fixing, honing your Regexp, there will <em>always</em> be a case you're missing.</p>\n\n<p>Anyway, you have to tell your Regexp engine to match multiple lines instead of just one. In some of the most popular ones you do that by applying the <code>/m</code> modifier.</p>\n\n<p>But let me repeat: <em>please</em> use an HTML parser. Everytime someone uses a Regexp to parse HTML, a kitten dies ...</p>\n"}, {'answer_id': 79032, 'author': 'Bennor McCarthy', 'author_id': 14451, 'author_profile': 'https://Stackoverflow.com/users/14451', 'pm_score': 1, 'selected': False, 'text': '<p>The problem is that the . metacharacter doesn\'t match newlines by default. You have to use the single-line modifier to achieve this. In .NET, you can either use RegexOptions.SingleLine as the last parameter to the method you\'re using, or use the modifier directly in the pattern, e.g:</p>\n\n<pre><code>(?s)(&lt;div id="super_special"&gt;.*?&lt;/div&gt;)\n</code></pre>\n'}, {'answer_id': 79066, 'author': 'Mike Tunnicliffe', 'author_id': 13956, 'author_profile': 'https://Stackoverflow.com/users/13956', 'pm_score': 1, 'selected': False, 'text': '<p>Most languages have some way to make . match newlines:</p>\n\n<ul>\n<li>In Java: Pattern.compile("pattern", Pattern.MULTILINE);</li>\n<li>In Perl and Ruby: /pattern/m</li>\n<li>In VB: Regex.IsMatch(s, "pattern", RegexOptions.Multiline)</li>\n</ul>\n\n<p>In general it\'s not a good idea to use regexp to match XML/HTML, because XML/HTML tags can be nested, for example:</p>\n\n<pre><code> &lt;div id="super_special"&gt;\n &lt;div&gt;Nothing&lt;/div&gt;\n &lt;p&gt;Anything could go in here...doesn\'t matter. Let\'s get it all&lt;/p&gt;\n &lt;/div&gt;\n</code></pre>\n\n<p>... here you could easily end up matching:</p>\n\n<pre><code> &lt;div id="super_special"&gt;\n &lt;div&gt;Nothing&lt;/div&gt;\n</code></pre>\n\n<p>On the other hand, if you know <strong>for sure</strong> that the HTML you are matching will always be safe for your regexp, then don\'t let me stop you (although, even then you should think twice about saving your future self from a potential debugging headache).</p>\n'}, {'answer_id': 79079, 'author': 'André Chalella', 'author_id': 4850, 'author_profile': 'https://Stackoverflow.com/users/4850', 'pm_score': 2, 'selected': True, 'text': '<p>Out-of-the-box, without special modifiers, most regex implementations don\'t go beyond the end-of-line to match text. You probably should look in the documentation of the regex engine you\'re using for such modifier.</p>\n\n<p>I have one other advice: beware of greed! Traditionally, regex <strong>are</strong> greedy which means that your regex would probably match this:</p>\n\n<pre><code>&lt;div id="super_special"&gt;\n I\'m the wanted div!\n&lt;/div&gt;\n&lt;div id="not_special"&gt;\n I\'m not wanted, but I\'ve been caught too :(\n&lt;/div&gt;\n</code></pre>\n\n<p>You should check for a "not-greedy" modifier, so that your regex would stop matching text at the <strong>first</strong> occurence of <code>&lt;/div&gt;</code>, not at the <strong>last</strong> one.</p>\n\n<p>Also, as others have said, consider using an HTML parser instead of regexes. It will save you a lot of headache.</p>\n\n<p><em>Edit: even a non-greedy regex wouldn\'t work as expected either, if <code>&lt;div&gt;</code>s are nested! Another reason to consider using an HTML parser.</em></p>\n'}, {'answer_id': 79377, 'author': 'Mike Kantor', 'author_id': 14607, 'author_profile': 'https://Stackoverflow.com/users/14607', 'pm_score': 0, 'selected': False, 'text': '<p>None of these regex suggestions will work. Depending on whether they\'re greedy or not, they will match either the very last &lt;/div&gt; in the document, or the very first &lt;/div&gt; after your starting string, which may be a div nested inside the one you\'re interested in.</p>\n\n<p>Regular expressions are not really the ideal tool for this purpose, but if your situation is simple enough that you don\'t really want to parse the HTML, you can do this using a Microsoft-proprietary extension to regex available in .NET. For a nice explanation, see <a href="http://www.codeproject.com/KB/recipes/Nested_RegEx_explained.aspx" rel="nofollow noreferrer">this nice article by Morten Maate</a>.</p>\n'}, {'answer_id': 110757, 'author': 'Martijn', 'author_id': 17439, 'author_profile': 'https://Stackoverflow.com/users/17439', 'pm_score': 0, 'selected': False, 'text': '<p>Regular expressions alone are simply not powerful enough to solve your problem. You need something more powerful, such as context-free grammars. See <a href="http://en.wikipedia.org/wiki/Chomsky_hierarchy" rel="nofollow noreferrer">Chomsky hierarchy</a> at Wikipedia.</p>\n\n<p>In other words (as has been said before), don\'t use regex to parse HTML.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78978', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/27870/']
78,983
<p>There are about 200 projects in cvs and at least 100 projects in vss. Some are inactive code in maintenance mode. Some are legacy apps. Some are old apps no longer in use. About 10% are in active development. The plan is to move everything to perforce my end of year 2009.</p> <p>Has anyone done a large migration like this? </p> <p>Has anyone come across best practices for moving from cvs to perforce? Or a similar migration. Any gotchas to look out for?</p>
[{'answer_id': 79202, 'author': 'Kevin Little', 'author_id': 14028, 'author_profile': 'https://Stackoverflow.com/users/14028', 'pm_score': 0, 'selected': False, 'text': '<p>Forgive my answering a question with a question, but doesn\'t <a href="http://www.perforce.com/" rel="nofollow noreferrer">Perforce</a> provide tools for this? Or, at the very least, documentation? I\'d be beating up my Perforce salesperson...</p>\n'}, {'answer_id': 79219, 'author': 'Jonathan Arkell', 'author_id': 11052, 'author_profile': 'https://Stackoverflow.com/users/11052', 'pm_score': 2, 'selected': False, 'text': "<p>I haven't had to do something of this scale, but I have a few ideas. First off, start by taking a small, unimportant project, and migrate that. That will give you an idea of how much trouble it is going to take to migrate the rest of the projects. Immediately after that you should choose a medium size project as there may be issues with migrating a larger project (say with branches) that might not be apparent on a small project.</p>\n\n<p>Make sure you spend a bit of time seeing how easy it is to convert cvs projects to vss, or the other way around. If converting from vss to perforce is a real pain, you can convert vss to cvs, and then to perforce. Don't sink days into it, but it could back you out of a sticky situation. I think the key here is go incremental.</p>\n\n<p>Backups are good. Period.</p>\n\n<p>Consider a cutoff date, and any projects that are inactive, and older then that, should be mothballed. Check out the final revision and store that in Perforce. Do you really need 15 yearold visual basic code?</p>\n"}, {'answer_id': 79495, 'author': 'Mark', 'author_id': 4405, 'author_profile': 'https://Stackoverflow.com/users/4405', 'pm_score': 4, 'selected': True, 'text': '<p>On the VSS side, there are conversion tools that are available to help with migration. They can mostly maintain version history (there are caveats that are explained in the readme and docs). I have migrated well over 50 VSS projcts into perforce using the VSS to perforce tool. Getting the data out of VSS can be a bit finicky and not terribly speedy, but it works. If you have direct access to the disks (i.e. not over a network share) to the VSS repository, the conversion can go much quicker. You can find information about the scripts <a href="http://kb.perforce.com/Conversions/VssToPerforce" rel="nofollow noreferrer">here</a>.</p>\n\n<p>There is a simlar page for CVS to perforce conversion <a href="http://kb.perforce.com/Conversions/CvsToPerforce" rel="nofollow noreferrer">here</a>, although I don\'t have direct experience with that. These links are good places to start. You can also search through the Perforce mailing lists at the Perforce Knowledge Base located <a href="http://kb.perforce.com/" rel="nofollow noreferrer">here</a>. I\'m pretty sure that you might find some conversion information in the mailing list archives.</p>\n\n<p>Migrate your old projects first. You can make sure that your process works. When we migrated active code to Perforce, I took one weekend and basically took down access to the servers and moved the code over to Perforce. Honestly, it was a pretty easy migration and when people came back on Monday they were ready to go. You might think about preparing your employees with Perforce cheat sheets after you start doing the migration.</p>\n\n<p>The biggest gotchas might actually be preparing your people to use Perforce. Had I done it over again, I would have migrated our smaller active projects first and prepared smaller numbers of people to use Perforce at once. As it was, I had to train 120+ people on day 1 after the migration and that was a bit much. Also, make sure that you don\'t have 100+ people hitting your server for a fresh sync on day 1 either. We wound up taking our server down multiple times during the first few days. We used a windows 32 bit server which I would not recommend. We have a windows 64bit server now and it\'s much more robust. If you can, I would actually use Linux as your OS for your perforce server. Again, there should be good info on the Perforce site about performance.</p>\n'}, {'answer_id': 79790, 'author': 'Matthew Jaskula', 'author_id': 4356, 'author_profile': 'https://Stackoverflow.com/users/4356', 'pm_score': 0, 'selected': False, 'text': '<p>Consider not migrating dead and inactive projects. Simply put their repositories in read-only mode. The data will still be available if needed and you save the time effort of migrating them. Just migrate the 10% that are in use. Document the process thoroughly. </p>\n\n<p>If one of the un-migrated projects gets resurrected some time in the future you can easily migrate it using your documentation as a reference.</p>\n'}, {'answer_id': 79820, 'author': 'Kevin Sheffield', 'author_id': 590, 'author_profile': 'https://Stackoverflow.com/users/590', 'pm_score': 1, 'selected': False, 'text': '<p>What ever you do, keep the old repositories in read-only mode some where.</p>\n'}, {'answer_id': 80733, 'author': 'Douglas Leeder', 'author_id': 3978, 'author_profile': 'https://Stackoverflow.com/users/3978', 'pm_score': 0, 'selected': False, 'text': '<p>We migrated our svn repository with a tool that we wrote, and just took the head revision of our starteam projects.</p>\n\n<p>Watch out for differences between single-file checkins (CVS) and multi-file changesets (Perforce).</p>\n\n<p>Watch out for branches is separate space (CVS) vs. branches in filepath-space (Perforce).</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/78983', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13753/']
78,984
<p>I am looking for a best practice for End to End Authentication for internal Web Applications to the Database layer.</p> <p>The most common scenario I have seen is to use a single SQL account with the permissions set to what is required by the application. This account is used by all application calls. Then when people require access over the database via query tools or such a separate Group is created with the query access and people are given access to that group.</p> <p>The other scenario I have seen is to use complete Windows Authentication End to End. So the users themselves are added to groups which have all the permissions set so the user is able to update and change outside the parameters of the application. This normally involves securing people down to the appropriate stored procedures so they aren't updating the tables directly. </p> <p>The first scenario seems relatively easily to maintain but raises concerns if there is a security hole in the application then the whole database is compromised.</p> <p>The second scenario seems more secure but has the opposite concern of having to much business logic in stored procedures on the database. This seems to limit the use of the some really cool technologies like Nhibernate and LINQ. However in this day and age where people can use data in so many different ways we don't foresee e.g. mash-ups etc is this the best approach.</p>
[{'answer_id': 79030, 'author': 'Stephen Wrighton', 'author_id': 7516, 'author_profile': 'https://Stackoverflow.com/users/7516', 'pm_score': 1, 'selected': False, 'text': "<p>Personally, I don't want normal end users in the database. For an intranet application (especially one which resides on a Domain) I would provide a single account for application access to the database which only has those rights which are needed for the application to function.</p>\n\n<p>Access to the application would then be controlled via the user's domain account (turn off anonymous access in IIS, etc.).</p>\n\n<p><strong>IF</strong> a user needs, and can justify, direct access to the database, then their <strong>domain account</strong> would be given access to the database, and they can log into the DBMS using the appropriate tools.</p>\n"}, {'answer_id': 79065, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>I've been responsible for developing several internal web applications over the past year.</p>\n\n<p>Our solution was using Windows Authentication (Active Directory or LDAP).</p>\n\n<p>Our purpose was merely to allow a simple login using an existing company ID/password. We also wanted to make sure that the existing department would still be responsible for verifying and managing access permissions.</p>\n\n<p>While I can't answer the argument concerning Nhibernate or LINQ, unless you have a specific killer feature these things can implement, Active Directory or LDAP are simple enough to implement and maintain that it's worth trying.</p>\n"}, {'answer_id': 79156, 'author': 'Dale Wright', 'author_id': 11523, 'author_profile': 'https://Stackoverflow.com/users/11523', 'pm_score': 0, 'selected': False, 'text': "<p>Stephen - Keeping normal end users out of the database is nice but I am wondering if in this day and age with so many experienced computer users coming out of University / College if this the right path. If someone wants to automate part of their job which includes a VBA update to a database which I allow them to do via the normal application are we losing gains by restricting their access in this way.</p>\n\n<p>I guess the other path implied here is you could open up the Application via services and then secure those services via groups and still keep the users separated from the database.</p>\n\n<p>Then via delegation you can allow departments to control access to their own accounts via the groups as per Jonathan's post.</p>\n"}, {'answer_id': 79204, 'author': 'Dave Neeley', 'author_id': 9660, 'author_profile': 'https://Stackoverflow.com/users/9660', 'pm_score': 0, 'selected': False, 'text': '<p>I agree with Stephen Wrighton. Domain security is the way to go. If you would like to use mashups and what-not, you can expose parts of the database via a machine-readable RESTful interface. <a href="http://subsonicproject.com" rel="nofollow noreferrer">SubSonic</a> has one <a href="http://subsonicproject.com/tips-and-tricks/webcast-using-subsonic-s-rest-handler/" rel="nofollow noreferrer">built in</a>.</p>\n'}, {'answer_id': 79208, 'author': 'Stephen Wrighton', 'author_id': 7516, 'author_profile': 'https://Stackoverflow.com/users/7516', 'pm_score': 3, 'selected': True, 'text': "<p>Dale - That's it exactly. If you want to provide access to the underlying data store to those users then do it via services. And in my experience, it is those experienced computer users coming out of Uni/College that damage things the most. As the saying goes, they know just enough to be dangerous.</p>\n\n<p>If they want to automate part of their job, and they can display they have the requisite knowledge, then go ahead, grant their <strong>domain account</strong> access to the backend. That way anything they do via their little VBA automation is tied to their account and you know exactly who to go look at when the data gets hosed. </p>\n\n<p>My basic point is that the database is the proverbial holy grail of the application. You want as few fingers in that particular pie as possible. </p>\n\n<p>As a consultant, whenever I hear that someone has allowed normal users into the database, my eyes light up because I know it's going to end up being a big paycheck for me when I get called to fix it.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/78984', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11523/']
79,023
<p>Briefly: Does anyone know of a GUI for gdb that brings it on par or close to the feature set you get in the more recent version of Visual C++?</p> <p>In detail: As someone who has spent a lot of time programming in Windows, one of the larger stumbling blocks I've found whenever I have to code C++ in Linux is that debugging anything using commandline gdb takes me several times longer than it does in Visual Studio, and it does not seem to be getting better with practice. Some things are just easier or faster to express graphically.</p> <p>Specifically, I'm looking for a GUI that:</p> <ul> <li>Handles all the basics like stepping over &amp; into code, watch variables and breakpoints</li> <li>Understands and can display the contents of complex &amp; nested C++ data types</li> <li>Doesn't get confused by and preferably can intelligently step through templated code and data structures while displaying relevant information such as the parameter types</li> <li>Can handle threaded applications and switch between different threads to step through or view the state of</li> <li>Can handle attaching to an already-started process or reading a core dump, in addition to starting the program up in gdb</li> </ul> <p>If such a program does not exist, then I'd like to hear about experiences people have had with programs that meet at least some of the bullet points. Does anyone have any recommendations?</p> <p><strong>Edit:</strong><br> Listing out the possibilities is great, and I'll take what I can get, but it would be even more helpful if you could include in your responses:<br> (a) Whether or not you've actually used this GUI and if so, what positive/negative feedback you have about it.<br> (b) If you know, which of the above-mentioned features are/aren't supported</p> <p>Lists are easy to come by, sites like this are great because you can get an idea of people's personal experiences with applications.</p>
[{'answer_id': 79050, 'author': 'Vicent Marti', 'author_id': 4381, 'author_profile': 'https://Stackoverflow.com/users/4381', 'pm_score': 7, 'selected': True, 'text': "<p>You won't find <em>anything</em> overlaying GDB which can compete with the raw power of the Visual Studio debugger. It's just too powerful, and it's just too well integrated inside the IDE. </p>\n\n<p>For a Linux alternative, try DDD if free software is your thing.</p>\n"}, {'answer_id': 79058, 'author': 'Allen', 'author_id': 6043, 'author_profile': 'https://Stackoverflow.com/users/6043', 'pm_score': 2, 'selected': False, 'text': "<p>What can be stepped through is going to be limited by the debugging information that g++ produces, to a large extent. Emacs provides an interface to gdb that lets you control it via the toolbars/menus and display data in separate windows, as well as type gdb commands directly. Eclipse's CDT provides similar tools. I've heard of Anjuta and Code::Blocks but never used them.</p>\n"}, {'answer_id': 79070, 'author': 'user14636', 'author_id': 14636, 'author_profile': 'https://Stackoverflow.com/users/14636', 'pm_score': 3, 'selected': False, 'text': '<p>Check out the Eclipse CDT project. It is a plugin for Eclipse geared towards C/C++ development and includes a fairly feature rich debugging perspective (that behind the scenes uses GDB). It is available on a wide variety of platforms.</p>\n'}, {'answer_id': 79080, 'author': 'mmattax', 'author_id': 1638, 'author_profile': 'https://Stackoverflow.com/users/1638', 'pm_score': 3, 'selected': False, 'text': '<p>DDD is the GNU frontend for gdb: <a href="http://www.gnu.org/software/ddd/" rel="noreferrer">http://www.gnu.org/software/ddd/</a></p>\n'}, {'answer_id': 79099, 'author': 'Harold Ekstrom', 'author_id': 8429, 'author_profile': 'https://Stackoverflow.com/users/8429', 'pm_score': 1, 'selected': False, 'text': '<p>KDevelop works pretty well.</p>\n'}, {'answer_id': 79177, 'author': 'Milan Babuškov', 'author_id': 14690, 'author_profile': 'https://Stackoverflow.com/users/14690', 'pm_score': 0, 'selected': False, 'text': '<p>Latest version of Geany supports it (only on Linux, though)</p>\n'}, {'answer_id': 79179, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 6, 'selected': False, 'text': '<p>gdb -tui works okay if you want something GUI-ish, but still character based.</p>\n'}, {'answer_id': 79186, 'author': 'Nick Bastin', 'author_id': 1502059, 'author_profile': 'https://Stackoverflow.com/users/1502059', 'pm_score': 4, 'selected': False, 'text': "<p>I use DDD a lot, and it's pretty powerful once you learn to use it. One thing I would say is don't use it over X over the WAN because it seems to do a lot of unnecessary screen updates.</p>\n\n<p>Also, if you're not mated to GDB and don't mind ponying up a little cash, then I would try TotalView. It has a bit of a steep learning curve (it could definitely be more intuitive), but it's the best C++ debugger I've ever used on any platform and can be extended to introspect your objects in custom ways (thus allowing you to view an STL list as an actual list of objects, and not a bunch of confusing internal data members, etc.)</p>\n"}, {'answer_id': 79209, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>As someone familiar with Visual Studio, I've looked at several open source IDE's to replace it, and KDevelop comes the closest IMO to being something that a Visual C++ person can just sit down and start using. When you run the project in debugging mode, it uses gdb but kdevelop pretty much handles the whole thing so that you don't have to know it's gdb; you're just single stepping or assigning watches to variables.</p>\n\n<p>It still isn't as good as the Visual Studio Debugger, unfortunately.</p>\n"}, {'answer_id': 79284, 'author': 'Jon Ball', 'author_id': 10216, 'author_profile': 'https://Stackoverflow.com/users/10216', 'pm_score': 6, 'selected': False, 'text': '<p>Eclipse CDT will provide an experience comparable to using Visual Studio. I use Eclipse CDT on a daily basis for writing code and debugging local and remote processes.</p>\n<p>If you\'re not familiar with using an Eclipse based IDE, the GUI will take a little getting used to. However, once you get to understand the GUI ideas that are unique to Eclipse (e.g. a perspective), using the tool becomes a nice experience.</p>\n<p>The CDT tooling provides a decent C/C++ indexer that allows you to quickly find references to methods in your code base. It also provides a nice macro expansion tool and limited refactoring support.</p>\n<p>With regards to support for debugging, CDT is able to do everything in your list with the exception of reading a core dump (it may support this, but I have never tried to use this feature). Also, my experience with debugging code using templates is limited, so I\'m not sure what kind of experience CDT will provide in this regard.</p>\n<p>For more information about debugging using Eclipse CDT, you may want to check out these guides:</p>\n<ul>\n<li><a href="http://www.ibm.com/developerworks/library/os-eclipse-cdt-debug2/index.html" rel="nofollow noreferrer">Interfacing with the CDT debugger, Part 2: Accessing gdb with the Eclipse CDT and MI</a></li>\n<li><a href="http://download.eclipse.org/tools/cdt/docs/tutorials/debug_tutorial/cdt_w_debug.htm" rel="nofollow noreferrer">CDT Debug Tutorial</a></li>\n</ul>\n'}, {'answer_id': 120575, 'author': 'Andrew Edgecombe', 'author_id': 11694, 'author_profile': 'https://Stackoverflow.com/users/11694', 'pm_score': 3, 'selected': False, 'text': '<p>I\'ve tried a couple of different guis for gdb and have found DDD to be the better of them.\nAnd while I can\'t comment on other, non-gdb offerings for linux I\'ve used a number of other debuggers on other platforms.</p>\n\n<p>gdb does the majority of the things that you have in your wish list. DDD puts a nicer front on them. For example thread switching is made simpler. Setting breakpoints is as simple as you would expect.</p>\n\n<p>You also get a cli window in case there is something obscure that you want to do.</p>\n\n<p>The one feature of DDD that stands out above any other debugger that I\'ve used is the data "graphing". This allows you to display and arrange structures, objects and memory as draggable boxes. Double clicking a pointer will open up the dereferenced data with visual links back to the parent.</p>\n'}, {'answer_id': 236840, 'author': 'codeguru', 'author_id': 31476, 'author_profile': 'https://Stackoverflow.com/users/31476', 'pm_score': 3, 'selected': False, 'text': '<p>I used KDbg (only works under KDE). </p>\n'}, {'answer_id': 405843, 'author': 'BubbaT', 'author_id': 29178, 'author_profile': 'https://Stackoverflow.com/users/29178', 'pm_score': 1, 'selected': False, 'text': "<p>Have you tried gdb -w with cygwin gdb.\nIt is supossed to have a windows interface which works fairly well.</p>\n\n<p>The only problem I found is that on my present machine it didn't run that way until after I installed ddd. I suspect that it requires tcltk which was installed when I installed ddd.</p>\n"}, {'answer_id': 409241, 'author': 'Johannes Schaub - litb', 'author_id': 34509, 'author_profile': 'https://Stackoverflow.com/users/34509', 'pm_score': 3, 'selected': False, 'text': '<p>Similar comfortable to the eclipse gdb frontend is the emacs frontend, tightly tied to the emacs IDE. If you already work with emacs, you will like it:</p>\n\n<p><a href="https://stackoverflow.com/questions/164693/whats-the-best-stable-c-ide-with-a-gui-that-runs-on-linux#350855">GDB Emacs Frontend</a></p>\n'}, {'answer_id': 501947, 'author': 'Adam Pierce', 'author_id': 5324, 'author_profile': 'https://Stackoverflow.com/users/5324', 'pm_score': 2, 'selected': False, 'text': '<p>You don\'t mention whether you are using Windows or UNIX.</p>\n\n<p>On UNIX systems, <a href="http://www.kdevelop.org/" rel="nofollow noreferrer">KDevelop</a> is good but I use <a href="http://www.kdbg.org/" rel="nofollow noreferrer">KDbg</a> because it is easy to use and will also work with apps not developed in KDevelop.</p>\n\n<p><a href="http://www.eclipse.org/" rel="nofollow noreferrer">Eclipse</a> is good on both platforms.</p>\n\n<p>On Windows, there is a great package called <a href="http://wascana.sourceforge.net/" rel="nofollow noreferrer">Wascana Desktop Developer</a> which is Eclipse CDT and MinGW all packaged up and preconfigured nicely for the minimum of pain. Its the best thing I\'ve found for developing GNU code on Windows.</p>\n\n<p>I have used all these debuggers and none of them are as good as MS Dev Studio. Eclipse/Wascana is probably the closest but it does have limitations like you cannot step into DLLs and it doesn\'t do as good a job at examining variables.</p>\n'}, {'answer_id': 501980, 'author': 'Adam Hawes', 'author_id': 54415, 'author_profile': 'https://Stackoverflow.com/users/54415', 'pm_score': 5, 'selected': False, 'text': "<p>I loathe the idea of Windows development, but the VC++ debugger is among the best I've seen. I haven't found a GUI front end that comes close to the VC one.</p>\n\n<p>GDB is awesome once you really get used to it. Use it in anger enough and you'll become very proficient. I can whiz around a program doing all the things you listed without much effort anymore. It did take a month or so of suffering over a SSH link to a remote server before I was proficient. I'd never go back though.</p>\n\n<p>DDD is really powerful but it was quite buggy. I found it froze up quite often when it got messages from GDB that it didn't grok. It's good because it has a gdb interface window so you can see what's going on and also interact with gdb directly. DDD can't be used on a remote X session in my environment (a real problem, since I'm sitting at a thin client when I do Unix dev) for some reason so it's out for me.</p>\n\n<p>KDevelop followed typical KDE style and exposed EVERYTHING to the user. I also never had any luck debugging non KDevelop programs in KDevelop.</p>\n\n<p>The Gnat Programming Studio (GPS) is actually quite a good front-end to GDB. It doesn't just manage Ada projects, so it's worth trying out if you are in need of a debugger.</p>\n\n<p>You could use Eclipse, but it's pretty heavy weight and a lot of seasoned Unix people I've worked with (me included) don't care much for its interface, which won't just STFU and get out of your way. Eclipse also seems to take up a lot of space and run like a dog.</p>\n"}, {'answer_id': 1130950, 'author': 'cod', 'author_id': 136206, 'author_profile': 'https://Stackoverflow.com/users/136206', 'pm_score': 5, 'selected': False, 'text': '<p>I use cgdb, simple and usefull</p>\n'}, {'answer_id': 1842740, 'author': 'Dominic.wig', 'author_id': 184997, 'author_profile': 'https://Stackoverflow.com/users/184997', 'pm_score': 0, 'selected': False, 'text': '<p>If you are looking for gdb under Visual Studio, then check <a href="http://www.wingdb.com" rel="nofollow noreferrer">WinGDB</a>.</p>\n'}, {'answer_id': 1842846, 'author': 'Radim Cernej', 'author_id': 104816, 'author_profile': 'https://Stackoverflow.com/users/104816', 'pm_score': 0, 'selected': False, 'text': '<p>In the last 15 months I use insight (came with FC6). It is not great, it is written in Tcl/Tk, but it is simple and useful. DDD is of similar quality / utility, but somewhat harder to use (various GUI gotchas and omissions). I also tried to integrate gdb with my IDE, SlickEdit. It worked OK (I played some 4 hours with it), but I did not like the GUI context switches. I like my IDE to remain unchanged while I am debugging; on Windows I use SlickEdit for IDE and Visual Studio Debugger for debugging. So from the 3: Insight, DDD and SlickEdit, Insight is my 1st choice, I use it >95% of the time, command-line gdb and DDD make up the other 5%. If I get the chance, I will eval Eclipse at some point, my work PC does not seem to have enough RAM (1GB only) to run Eclipse reasonably well.</p>\n\n<p>I have also heard a lot of praise for TotalView, including 1st hand during a job interview. I obtained an eval for our company in late 2008, but in the end we did not proceed as gdb was good enough for our needs; and it is free and ubiquitous.</p>\n'}, {'answer_id': 3557038, 'author': 'Soulman', 'author_id': 368491, 'author_profile': 'https://Stackoverflow.com/users/368491', 'pm_score': 5, 'selected': False, 'text': '<p>Qt Creator seems like good stuff. A colleague showed me one way set it up for debugging:</p>\n\n<ul>\n<li>Create a new project, "Import of Makefile-based Project".</li>\n<li>Point it to your root project folder (it will index sources under it, and it is impressively fast).</li>\n<li>Go to project settings and add a run configuration, then specify the executable you want to debug, and its arguments.</li>\n<li>Qt Creator seems to insist on building your project before debugging it. If you don\'t want that, or don\'t use make, just go to projects -> build (Left panel), then, on the right panel in "Build Steps", remove all the steps, including the step by default when you created the project. </li>\n</ul>\n\n<p>That may seem like a bit much work for debugging an app I had already compiled, but it is worth it. The debugger shows threads, stacks and local variables in a similar way to Visual Studio and even uses many of the same keyboard shortcuts. It seems to handle templates well, at least std::string and std::map. Attaching to existing processes and core dumps seems to be supported, though I haven\'t tested it yet.</p>\n\n<p>Keep in mind that I used it for less than and hour now, but I\'m impressed so far.</p>\n'}, {'answer_id': 4233557, 'author': 'Marv', 'author_id': 514555, 'author_profile': 'https://Stackoverflow.com/users/514555', 'pm_score': 3, 'selected': False, 'text': "<p>Qt Creator-on-Linux is certainly on par with Visual Studio-on-Windows for C++ nowadays. I'd even say better on the debugger side.</p>\n"}, {'answer_id': 6196790, 'author': 'Sergey Shandar', 'author_id': 374845, 'author_profile': 'https://Stackoverflow.com/users/374845', 'pm_score': 6, 'selected': False, 'text': '<p>Check out <a href="https://wiki.gnome.org/Apps/Nemiver">Nemiver C/C++ Debugger</a>. It is easy to install in Ubuntu (Developer Tools/Debugging).</p>\n\n<p><strong>Update:</strong> New link.</p>\n'}, {'answer_id': 8256149, 'author': 'crobar', 'author_id': 685984, 'author_profile': 'https://Stackoverflow.com/users/685984', 'pm_score': 2, 'selected': False, 'text': '<p>The <a href="http://www.codeblocks.org/" rel="nofollow">Code:Blocks</a> C++ IDE has a graphical wrapper, with a few of the features you want, but nothing like the power of VS.</p>\n'}, {'answer_id': 9307103, 'author': 'siddhusingh', 'author_id': 306819, 'author_profile': 'https://Stackoverflow.com/users/306819', 'pm_score': 0, 'selected': False, 'text': '<p>Use www.zero-bugs.com/\nZero debugger, it requires C++0x support from gcc</p>\n'}, {'answer_id': 19943130, 'author': 'Florent', 'author_id': 847202, 'author_profile': 'https://Stackoverflow.com/users/847202', 'pm_score': 3, 'selected': False, 'text': '<p>There\'s one IDE that is missing in this list and which is very efficient (I\'ve used it in many C/C++ projects without any issues): <a href="https://netbeans.org/kb/docs/cnd/quickstart.html" rel="noreferrer">Netbeans</a>.</p>\n'}, {'answer_id': 23900374, 'author': 'Sergey Zhukov', 'author_id': 1656467, 'author_profile': 'https://Stackoverflow.com/users/1656467', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://visualgdb.com" rel="nofollow">VisualGDB</a> is another Visual Studio plugin to develop and debug applications on linux and embedded platforms. </p>\n'}, {'answer_id': 29491016, 'author': 'Viktor Malyi', 'author_id': 1254211, 'author_profile': 'https://Stackoverflow.com/users/1254211', 'pm_score': 2, 'selected': False, 'text': '<p>Have you ever taken a look at <a href="https://developer.arm.com/products/software-development-tools/ds-5-development-studio/ds-5-debugger/overview" rel="nofollow noreferrer">DS-5 debugger</a>?</p>\n\n<p>There is a paid version which includes a lot of helpful features, but you can also use Community Edition for free (which is also quite useful especially for embedded systems).</p>\n\n<p>I have a positive experience with this tool when debugging Android applications on real device using eclipse.</p>\n'}, {'answer_id': 38191320, 'author': 'Cutton Eye', 'author_id': 5612605, 'author_profile': 'https://Stackoverflow.com/users/5612605', 'pm_score': 0, 'selected': False, 'text': '<p>I was searching for a debugger to step through a running programm. Say: Attach. The programm was build with eclipse, but because of maybe some multithreadding obstrucles, no sourcefiles where fond. What ever.</p>\n\n<p>I got very compfortable with NetBeans.</p>\n\n<ul>\n<li>[debug] from menu -> Attach Deugger...</li>\n<li>as process chose the one to debug</li>\n<li>as project [new project]</li>\n</ul>\n\n<p>Now the window disappars and you see nothing. detach from the process. The Read Square "Stop" helps.</p>\n\n<ul>\n<li>import source from the project as e.g. folder. ".../MyProject/src</li>\n<li>Now it appears in your project, and you can set breakpoints.</li>\n<li>again ttach debugger</li>\n<li>chose the process to debug.</li>\n<li>debugger should stop if programm reaches next breakpoint.</li>\n</ul>\n\n<p>Going to [window] -> [Debugging] -> Will your window make compfortable.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79023', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14266/']
79,033
<p>Have you ever been in a situation where a menu function you really really want to use but can't cause it's disabled or worse gone all together?</p> <p>There is an argument for always leaving menus enabled and then display a message to a user explaining why a menu function can not be activated when they click on it. I think there is merit in this but maybe there is a cleverer way of addressing this issue. </p> <p>I would be interested to hear what others think.</p>
[{'answer_id': 79052, 'author': 'Ana Betts', 'author_id': 5728, 'author_profile': 'https://Stackoverflow.com/users/5728', 'pm_score': 2, 'selected': False, 'text': "<p>Make it disabled but have the tooltip explain why it's disabled</p>\n"}, {'answer_id': 79062, 'author': 'Mikey', 'author_id': 13347, 'author_profile': 'https://Stackoverflow.com/users/13347', 'pm_score': 0, 'selected': False, 'text': "<p>I've always believed that you should hide as much as you can. (Your application shouldn't be any more complex than what the user can/should do.)</p>\n\n<p>If you display a menu option that a user shouldn't be using, they may click on it, but think your application is broken because nothing happens.</p>\n\n<p>That's what I think at least...</p>\n"}, {'answer_id': 79068, 'author': 'Josh', 'author_id': 257, 'author_profile': 'https://Stackoverflow.com/users/257', 'pm_score': 3, 'selected': False, 'text': '<p>If you\'re refering to Joel\'s post <a href="http://www.joelonsoftware.com/items/2008/07/01.html" rel="noreferrer">Don\'t hide or disable menu items</a>, he <a href="https://stackoverflow.fogbugz.com/default.asp?W13086" rel="noreferrer">clarified in the StackOverflow podcast</a> that he intended that there be information - not a dialog - telling you why a menu item wouldn\'t do anything:</p>\n\n<blockquote>\n <p>So, the use-case I was thinking of was, you had mentioned that in the Windows Media Player, you can play things faster when you\'re listening to podcasts and so forth, and it\'ll speed them up. And when I looked in there, that was disabled. And I couldn\'t figure out how to enable it. And obviously the help file is no help--not that anybody reads help files, but even if you did you couldn\'t find the answer to that. And that was kind of frustrating, and I\'d rather have that menu item be enabled and have it just tell me "I\'m not going to do this right now because of the following reason. I refuse to do this." </p>\n</blockquote>\n'}, {'answer_id': 79073, 'author': 'Joe Skora', 'author_id': 14057, 'author_profile': 'https://Stackoverflow.com/users/14057', 'pm_score': 0, 'selected': False, 'text': "<p>It depends on the situation. If the menu item has applies in the current context but isn't available because of state, it should be disabled. If the context has changed so it no longer applies, it should be removed.</p>\n"}, {'answer_id': 79086, 'author': 'jtimberman', 'author_id': 7672, 'author_profile': 'https://Stackoverflow.com/users/7672', 'pm_score': 0, 'selected': False, 'text': "<p>I've never really understood this myself (I don't program GUIs). Why even have menu items hidden or disabled in the first place? It is non-intuitive for most users who are looking for a particular menu option to find it disabled, or not even present.</p>\n\n<p>Tooltips are also non-intuitive. If I'm moving my mouse across menu items, I'm not going to pause long enough to get a tooltip explanation. I'm more likely to become frustrated that something I expected to be accessible through the menu isn't there, or is disabled. </p>\n\n<p>That said, I actually don't use GUI menus very often. I find the options available are often not useful, or are accessible in some more intuitive way, such as common keyboard shortcuts.</p>\n"}, {'answer_id': 79091, 'author': 'Bryan Oakley', 'author_id': 7432, 'author_profile': 'https://Stackoverflow.com/users/7432', 'pm_score': 2, 'selected': False, 'text': '<p>As with most questions about usability, the answer is "it depends". It depends on the problem domain, the type of user, how critical the function is and so on. There is no single answer to your question.</p>\n\n<p>I think the general consensus is, never ever totally remove items from a menu. Menus allow the user to freely discover what functions are available, but if those items are hidden or move around it does nothing to help the user. Also, moving them around makes it impossible to become proficient with the application since you have to constantly scan the menus for the item you want to select.</p>\n\n<p>As for disabling versus enabling an item and displaying a dialog or message explaining why it\'s not something you can do, I generally prefer the former. However, if there\'s a function that a user can\'t reasonably be expected to intuit from the display, leaving it enabled is a good choice. </p>\n\n<p>For example, if "Paste" is disabled it\'s reasonably obvious to most computer users that there\'s nothing to paste. However, if you have a "Frizzle the Bonfraz" menu item and the user may not know what a Bonfraz is or why they might want to enable it but can\'t, it\'s a good idea to leave it enabled at least for a while.</p>\n\n<p>So again, it depends. If at all possible, do what you think is best and then ask your users. </p>\n'}, {'answer_id': 79161, 'author': 'Swati', 'author_id': 12682, 'author_profile': 'https://Stackoverflow.com/users/12682', 'pm_score': 2, 'selected': False, 'text': '<p>To generalize it a bit (perhaps incorrectly...), which of these situations would you prefer:</p>\n\n<ol>\n<li>To find yourself on an island with no boat or bridge in site. Of course, you could talk to the villager in town and he would tell you the magical word to make a bridge appear...but you had no idea that magic existed.</li>\n<li>You see that there is a bridge; however, when you get to it, there is a sign telling you that the bridge is not open to use.</li>\n<li>You see that there is a bridge and celebrate! When you get to the end of the bridge, it tells you that the exit is not open. They must go back.</li>\n</ol>\n\n<p>Maybe I am biased, but I don\'t believe that leaving the menu options enabled and allowing the user to click on it is the best of idea. That\'s just wasting someone\'s time. There is no way for them to distinguish that the item is available or not until they click on the item. (Scenario #3)</p>\n\n<p>Hiding the item all together has its pros and cons. Completely hidden and you run the risk of the user never discovering all these features; however, at the same time, you are presented with the opportunity of making your application \'fun\' and \'discoverable.\' I\'ve always thought the visibility of actions is more suited to items like toolbars. A good example of that is in when in some applications the picture toolbar pops up when you click on an image...and disappears when you click on text. In general, I would say that something like this is best if the overall experience of your application lends towards a "discovering" and "exploring" attitude from the user. (Scenario #1)</p>\n\n<p>I would generally recommend disabling the items and providing a tooltip to the user informing them how to enable it (or even a link to Help?); however, this cannot be overdone. This must be done in moderation. (Scenario #2)</p>\n\n<p>In general, when it\'s a context-related action (i.e. picture toolbar) that the user can easily discover, hide the items. If the user won\'t easily find it, have it disabled. </p>\n'}, {'answer_id': 79475, 'author': 'Milan Babuškov', 'author_id': 14690, 'author_profile': 'https://Stackoverflow.com/users/14690', 'pm_score': 0, 'selected': False, 'text': "<p>You can display the 'reason' in the status bar. Or even better, use a text that describes the action and contains information when such action is possible. For example, for 'Copy' menu item, the text in status bar would be: Copy the selected text. Note the 'selected' part, which tells the user that he needs to select the text to enable the menu item.</p>\n\n<p>Another example in a tool I'm making, we have 'Drop database' menu item, but this action is only possible when you're connected to it. So, the text in status bar goes something like: 'Drop the database (only when connected)'.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79033', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9810/']
79,041
<p>I have a web system which has a classical parent-children menu saved in a database, with fields id as the PK, and parent_id to pointing to the owning menu. (Yes, I know this doesn't scale very well, but that's another topic). </p> <p>So for these records (id-parent_id pairs):</p> <pre><code>0-7 0-4 4-9 4-14 4-16 9-6 </code></pre> <p>I have this tree:</p> <pre><code>0 ├ 7 └ 4 ├ 9 | └ 6 ├ 14 └ 16 </code></pre> <p>I'm needing to hide a top node, so I have to make a list of all the childrens of that certain node, i.e. for 4, they will be (9, 6, 14, 16). Order doesn't matters.</p> <p>I'm confused... does this fits into the classical tree problems? or is it a graph one?</p> <p>How can I compose this structure and solve this problem using php?</p>
[{'answer_id': 79067, 'author': 'Blorgbeard', 'author_id': 369, 'author_profile': 'https://Stackoverflow.com/users/369', 'pm_score': 2, 'selected': True, 'text': "<p>This is the perfect chance to use recursion!</p>\n\n<p>Pseudo-code:</p>\n\n<pre><code>nodeList = {}\nenumerateNodes(rootNode, nodeList);\n\nfunction enumerateNodes(node, nodeList) {\n nodeList += node;\n foreach ( childnode in node.children ) {\n enumerateNodes(childnode, nodeList);\n }\n}\n</code></pre>\n\n<p>Edit: Didn't notice that your tree is in the adjacent list format. I would probably just build that into an actual tree datastructure before I started working with it. Just loop through all pairs (creating nodes the first time you see them) and linking them. I <em>think</em> it should be easy...</p>\n"}, {'answer_id': 79100, 'author': 'Brettski', 'author_id': 5836, 'author_profile': 'https://Stackoverflow.com/users/5836', 'pm_score': 2, 'selected': False, 'text': '<p>Adjacent list models are very difficult to deal with. The company I am with now uses them for hierarchies and it causes great headaches. I have successfully used Celko\'s nested set models for prior employers and they work great for creating, maintaining and using hierarchies (trees). </p>\n\n<p>I found this link which describes them: <a href="http://www.intelligententerprise.com/001020/celko.jhtml" rel="nofollow noreferrer">http://www.intelligententerprise.com/001020/celko.jhtml</a></p>\n\n<p>But I would also recommend the book "SQL for Smarties: Advanced SQL Programming" written by Joe Celko and covers nested sets. </p>\n\n<p><a href="https://rads.stackoverflow.com/amzn/click/com/0123693799" rel="nofollow noreferrer" rel="nofollow noreferrer">Joe Celko\'s SQL for Smarties: Advanced SQL Programming</a></p>\n\n<p><a href="https://rads.stackoverflow.com/amzn/click/com/1558609202" rel="nofollow noreferrer" rel="nofollow noreferrer">Joe Celko\'s Trees and Hierarchies in SQL for Smarties</a></p>\n'}, {'answer_id': 79112, 'author': 'Sridhar Iyer', 'author_id': 13820, 'author_profile': 'https://Stackoverflow.com/users/13820', 'pm_score': 0, 'selected': False, 'text': '<p>This is a graph problem. Check out <a href="http://en.wikipedia.org/wiki/Breadth-first_search" rel="nofollow noreferrer">BFS(breadth first search)</a> and <a href="http://en.wikipedia.org/wiki/Depth-first_search" rel="nofollow noreferrer">DFS(depth first search).</a>. You can google out those terms and find hundreds of implementations on the web.</p>\n'}, {'answer_id': 79232, 'author': 'hoyhoy', 'author_id': 3499, 'author_profile': 'https://Stackoverflow.com/users/3499', 'pm_score': 0, 'selected': False, 'text': '<p>This is trivial with a nested set implementation. See here for more details:</p>\n\n<p><a href="http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/" rel="nofollow noreferrer">http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/</a></p>\n\n<p>Otherwise, write something like this:</p>\n\n<pre><code>def get_subtree(node)\n if children.size &gt; 0\n return children.collect { |n| get_subtree(n) }\n else\n return node\n end\nend\n</code></pre>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79041', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/861/']
79,054
<p>Why does Leopard mangle some symbols with $non_lazy_ptr? More importantly what is the best method to fix undefined symbol errors because a symbol has been mangled with $non_lazy_ptr?</p>
[{'answer_id': 79951, 'author': 'Brian Mitchell', 'author_id': 13716, 'author_profile': 'https://Stackoverflow.com/users/13716', 'pm_score': 3, 'selected': False, 'text': '<p>From: <a href="http://developer.apple.com/library/mac/#documentation/developertools/conceptual/MachOTopics/1-Articles/indirect_addressing.html#//apple_ref/doc/uid/TP40004919-SW1" rel="nofollow noreferrer">Developer Connection - Indirect Addressing</a></p>\n\n<p>Indirect addressing is the name of the code generation technique that allows symbols defined in one file to be referenced from another file, without requiring the referencing file to have explicit knowledge of the layout of the file that defines the symbol. Therefore, the defining file can be modified independently of the referencing file. Indirect addressing minimizes the number of locations that must be modified by the dynamic linker, which facilitates code sharing and improves performance.</p>\n\n<p>When a file uses data that is defined in another file, it creates symbol references. A symbol reference identifies the file from which a symbol is imported and the referenced symbol. There are two types of symbol references: nonlazy and lazy.</p>\n\n<p>Nonlazy symbol references are resolved (bound to their definitions) by the dynamic linker when a module is loaded.\nA nonlazy symbol reference is essentially a symbol pointer—a pointer-sized piece of data. The compiler generates nonlazy symbol references for data symbols or function addresses.</p>\n\n<p>Lazy symbol references are resolved by the dynamic linker the first time they are used (not at load time). Subsequent calls to the referenced symbol jump directly to the symbol’s definition.\nLazy symbol references are made up of a symbol pointer and a symbol stub, a small amount of code that directly dereferences and jumps through the symbol pointer. The compiler generates lazy symbol references when it encounters a call to a function defined in another file.</p>\n'}, {'answer_id': 290199, 'author': 'Vladimir Panteleev', 'author_id': 21501, 'author_profile': 'https://Stackoverflow.com/users/21501', 'pm_score': 2, 'selected': False, 'text': "<p>In human-speak: the compiler generates stubs with $non_lazy_ptr appended to them to speed up linking. You're probably seeing that function Foo referenced from _Foo$non_lazy_ptr is undefined, or something like that - these are not the same thing. Make sure that the symbol is actually declared and exported in the object files/libraries you're linking your app to. At least that was my problem, I also thought it's a weird linker thing until I found that my problem was elsewhere - there are several other possible causes found on Google.</p>\n"}, {'answer_id': 1055687, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>ranlib -c on your library file fixes the problem</p>\n'}, {'answer_id': 3062322, 'author': 'Ciryon', 'author_id': 22012, 'author_profile': 'https://Stackoverflow.com/users/22012', 'pm_score': 1, 'selected': False, 'text': '<p>If someone else stumbles the same problem I had: </p>\n\n<p>Had a <code>extern NSString* const someString;</code> in the header file, but forgot to put it the implementation file. as <code>NSString* const someString=@"someString";</code></p>\n\n<p>This solved it.</p>\n'}, {'answer_id': 3462790, 'author': 'Tom S.', 'author_id': 393049, 'author_profile': 'https://Stackoverflow.com/users/393049', 'pm_score': 2, 'selected': False, 'text': '<pre><code>ranlib -c libwhatever.a\n</code></pre>\n\n<p>is a solid fix for the issue. I had the same problem when building the PJSIP library for iOS. This library sort-of uses an autoconf based make system, but needs a little tweaking to various files to make everything alright for iOS. In the process of doing that I managed to remove the ranlib line in the rule for libraries and then started getting an error in the link of my project about <code>_PJ_NO_MEMORY_EXCEPTION</code> referenced from <code>_PJ_NO_MEMORY_EXCEPTION$non_lazy_ptr</code> being undefined.</p>\n\n<p>Adding the ranlib line back to the library file solved it. Now my full entry for LIBS in rules.mak is</p>\n\n<pre><code>$(LIB): $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP)\n if test ! -d $(LIBDIR); then $(subst @@,$(subst /,$(HOST_PSEP),$(LIBDIR)),$(HOST_MKDIR)); fi\n $(LIBTOOL) -o $(LIB) $(OBJS)\n $(RANLIB) -c $(LIB)\n</code></pre>\n\n<p>Hope this helps others as well trying to use general UNIX configured external libraries with iPhone or iOS.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79054', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
79,093
<p>Frameworks simplify coding at the cost of speed and obfuscation of the OS. With the passing of Moore's law do you thing that there might be a shift away from Frameworks?</p> <p>I suspect that one of the reasons for Vista not being an outstanding success was that it ran much slower than XP, and, because computers had not improved as greatly in speed as in the past, this change seemed like a step backwards.</p> <p>For years CPU speed outstripped the speed of software so new frameworks that added layers of OS obfuscation and bloat did little harm. Just imagine how fast Windows 95 would run on today's hardware (given a few memory tweaks). Win2K then WinXP were great improvements, and we could live with them being slower because of faster computers.</p> <p>However, even years ago, I noticed that programs written in MS foundation classes didn't seem quite as crisp as code doing the same thing written directly to the API. Since the proliferation of these frameworks like .Net and others can only have made this situation worse, is it possible that we might discover that being able to write code in 'C' directly to the Win32 API (or the equivalent in other OS's) will become a strong competitive advantage, even if it does take longer to write? Or will the trade off in longer development time just not ever be worth it?</p>
[{'answer_id': 79128, 'author': 'Roger Ween', 'author_id': 6143, 'author_profile': 'https://Stackoverflow.com/users/6143', 'pm_score': 0, 'selected': False, 'text': "<p>Stepping away from frameworks would be a step backwards and I think and hope that this won't happen.</p>\n"}, {'answer_id': 79131, 'author': 'Tom Leys', 'author_id': 11440, 'author_profile': 'https://Stackoverflow.com/users/11440', 'pm_score': 2, 'selected': False, 'text': '<p>If there is selective pressure to make apps faster, I think that people will become better at writing frameworks that encapsulate functionality without slowing down the system too much.</p>\n\n<p>The Boost::Gil framework that handles pixels is a nice template-based system that boils down to many inlined functions - the compiler creates the same output as it would if you had no wrapper for the pixels and accessed the values directly. </p>\n\n<p>So - as for your question, I think the ball is in the court of the framework writers to ensure that their frameworks are fast and lean. This might mean that they detect which features are in use and remove code relating to unused features.</p>\n'}, {'answer_id': 79175, 'author': 'Steven A. Lowe', 'author_id': 9345, 'author_profile': 'https://Stackoverflow.com/users/9345', 'pm_score': 1, 'selected': False, 'text': "<p>frameworks exist to encapsulate common functionality; this will never change</p>\n\n<p>and what makes you think moore's law is dead? with MIT students growing bacteria that self-assemble nanowire circuits, moore's not dead yet...</p>\n"}, {'answer_id': 79213, 'author': 'Daniel', 'author_id': 13615, 'author_profile': 'https://Stackoverflow.com/users/13615', 'pm_score': 0, 'selected': False, 'text': '<p>What exactly do you mean by <strong>"frameworks"</strong>. This word is overloaded so much in our industry. If you mean something like MFC or .Net then I think they are here to stay. They have nothing to do with performance at runtime. <em>They have everything to do with code reuse, maintainability and separation of concerns.</em></p>\n\n<p>By the way Vista is not slow because it uses frameworks; <em>it is slow because it uses a lot of useless frameworks like DRM</em>. It might also suffer from low quality since MS is slowly becoming a more bureaucratic corporation - <em>my perception</em>. Vista also suffers from a lack of purpose. It doesn\'t bring anything worth upgrading for. It tried to compensate with GUI frosting.</p>\n'}, {'answer_id': 79228, 'author': 'jpoh', 'author_id': 4368, 'author_profile': 'https://Stackoverflow.com/users/4368', 'pm_score': 1, 'selected': False, 'text': "<p>The challenge I think for this to happen would be to find enough developers who are confident writing code without the 'crutch' of the many frameworks that there are out there today. More and more computer science/software engineering academic courses are ignoring the C's of the world in favour of the Java and .NET's (not that I have anything against Java or .NET, I earn a living from .NET as I'm sure many, many others do) because that is what the industry demands today. </p>\n\n<p>As a result, recent graduates take many frameworks for granted (unless they have enough interest to find out for themselves what happens 'under the hood'). Self-taught developers would also more than likely go for stuff that is easier to learn and easier to use. Again, this is notwithstanding the folks who are really keen and take the trouble to learn what happens behind the scenes of any framework that they use.</p>\n\n<p>And so I agree with a previous post, it'll probably be down to the writers of the framework to come up with creative ways to ensure that their stuff runs efficiently. My impression is that a sizeable number of developers aren't really interested in how a framework does X, they just want it to do it for them so that it helps them do their work quicker. Having to move away from frameworks would not be easy for many people, in my opinion.</p>\n"}, {'answer_id': 80043, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>"This word is overloaded so much in our industry. If you mean something like MFC or .Net then I think they are here to stay. They have nothing to do with performance at runtime. They have everything to do with code reuse, maintainability and separation of concerns."</p>\n\n<p>I have to say they do have a lot to do with performance at runtime, in many cases. Even if you called the framework, and it directly called the API call (in which case there would be no point, but this is the best possible case for speed), there would still be the performance penalty for an extra function call, which can be significant at times.</p>\n\n<p>Also, I have to admit, wish respect to the original poster, Vista <em>is</em> a step backwords. It is slow due to things like DRM that are not "features". Windows XP was actually faster than windows 2000 in many respects. Vista certainly is not. </p>\n'}, {'answer_id': 80938, 'author': 'Len Holgate', 'author_id': 7925, 'author_profile': 'https://Stackoverflow.com/users/7925', 'pm_score': 1, 'selected': False, 'text': "<p>For many pieces of software performance isn't the problem, it's time to market. This is often the case 'in-house' where a team may care much more about getting an initial version of an app in front of the users quickly than about how fast (or even how stable) it is. Add to this the fact that a well written framework will simplify development of applications that are the target of the framework's design and you'd often be mad NOT to use a framework if one is available. Of course you're taking the risk that the framework will allow you to get 80% of the way to your goal and then leave you high and dry, but, well, you can usually mitigate that by working outside of the framework for that last 20%. Like everything good in software it's often all about layering; you might first select .Net as a 'framework' and then decide to use a particular .Net GUI 'framework' for parts of your app and then, perhaps, a separate socket's 'framework' for other parts. Or, you might decide to work in C++ and use boost as a framework, or, perhaps pick a more focused framework that offers you more abstraction and (hopefully) greater coding speed.</p>\n\n<p>The problem is, often, selecting the right framework and deciding how much performance you are willing to sacrifice for ease of development.</p>\n"}, {'answer_id': 10411031, 'author': 'Ricibob', 'author_id': 159361, 'author_profile': 'https://Stackoverflow.com/users/159361', 'pm_score': 0, 'selected': False, 'text': "<p>Isn't WinRT all about addressing exactly this i.e an attempt have our cake and eat it? It is my understanding that WinRT is supposed to give us the higherlevel interaction whilst maintaining speed because its not an additional layer but a replacement for C/C++ baselevel OS api for use directly by .NET?</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79093', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3137/']
79,111
<p>Kind of a special case problem:</p> <ul> <li>I start a process with <code>System.Diagnostics.Process.Start(..)</code></li> <li>The process opens a splash screen -- this splash screen becomes the main window.</li> <li>The splash screen closes and the 'real' UI is shown. The main window (splash screen) is now invalid.</li> <li>I still have the Process object, and I can query its handle, module, etc. But the main window handle is now invalid.</li> </ul> <p>I need to get the process's UI (or UI handle) at this point. Assume I cannot change the behavior of the process to make this any easier (or saner).</p> <p>I have looked around online but I'll admit I didn't look for more than an hour. Seemed like it should be somewhat trivial :-(</p>
[{'answer_id': 79174, 'author': 'ageektrapped', 'author_id': 631, 'author_profile': 'https://Stackoverflow.com/users/631', 'pm_score': 1, 'selected': False, 'text': '<p>If you know the window\'s title, you can use the Win32 call, FindWindow, through P/Invoke.</p>\n\n<p>You can find the signature <a href="http://pinvoke.net/default.aspx/user32/FindWindow.html" rel="nofollow noreferrer">here</a> on pinvoke.net</p>\n'}, {'answer_id': 79201, 'author': 'Ash', 'author_id': 5023, 'author_profile': 'https://Stackoverflow.com/users/5023', 'pm_score': 3, 'selected': False, 'text': '<p>@ageektrapped is on the right track, however <code>FindWindow</code> will not search child windows.</p>\n\n<p>For that you will need to use <a href="http://pinvoke.net/default.aspx/user32/FindWindowEx.html" rel="nofollow noreferrer"><code>FindWindowEx</code></a></p>\n'}, {'answer_id': 79205, 'author': 'MB.', 'author_id': 11961, 'author_profile': 'https://Stackoverflow.com/users/11961', 'pm_score': 4, 'selected': True, 'text': '<p>If you don\'t mind using the Windows API, you could use <a href="http://msdn.microsoft.com/en-gb/library/windows/desktop/ms633498.aspx" rel="nofollow noreferrer"><code>EnumWindowsProc</code></a>, and check each of the handles that that turns up using <a href="http://msdn.microsoft.com/en-gb/library/windows/desktop/ms633522.aspx" rel="nofollow noreferrer"><code>GetWindowThreadProcessId</code></a> (to see that it\'s in your process), and then maybe <code>IsWindowVisible</code>, <code>GetWindowCaption</code> and <code>GetWindowTextLength</code> to determine which <code>hWnd</code> in your process is the one you want.</p>\n\n<p>Though if you haven\'t used those functions before that approach will be a real pain, so hopefully there\'s a simpler way.</p>\n'}, {'answer_id': 79277, 'author': 'blackwing', 'author_id': 9107, 'author_profile': 'https://Stackoverflow.com/users/9107', 'pm_score': 1, 'selected': False, 'text': '<p>From what I understand <code>MainWindowHandle</code> property of the process you are starting is not valid. If that\'s the case, you can use <a href="http://msdn.microsoft.com/en-us/library/ms633499.aspx" rel="nofollow noreferrer"><code>FindWindow</code></a> function (from Win32 SDK) which returns the window handle you need. All you need is the class name of target application\'s main window. You can obtain it using Spy++ or <a href="http://www.windows-spy.com/" rel="nofollow noreferrer">Winspector</a>. You also need to ensure you have the right window by checking that window\'s process id using <a href="http://msdn.microsoft.com/en-us/library/ms633522.aspx" rel="nofollow noreferrer"><code>GetWindowThreadProcessId</code></a>.</p>\n\n<p>At last, I have to say I am not an expert on Win32 and there might be a better solution for your case.</p>\n'}, {'answer_id': 214519, 'author': 'GregUzelac', 'author_id': 27068, 'author_profile': 'https://Stackoverflow.com/users/27068', 'pm_score': 2, 'selected': False, 'text': '<p>You may find that if you call .Refresh() that you get the new top-level window.</p>\n'}, {'answer_id': 247825, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Use Process.GetProcessById(proc.Id); where proc was your splash screen.\nWorks for me.</p>\n\n<p>Now, how do you get to main window properties in System.Windows.Forms to give it focus w/o using win32?\nAfter all .net is supposed to be a one-stop solution - is it not?</p>\n'}, {'answer_id': 429793, 'author': 'Marcus Erickson', 'author_id': 38373, 'author_profile': 'https://Stackoverflow.com/users/38373', 'pm_score': 0, 'selected': False, 'text': '<p>Somewhere in the code, the "real" main window is created. You can just save the window handle at that time and then after the splash screen closes you can set Application.MainWindow to the real window.</p>\n'}, {'answer_id': 429855, 'author': 'Matt Ellis', 'author_id': 29306, 'author_profile': 'https://Stackoverflow.com/users/29306', 'pm_score': 0, 'selected': False, 'text': "<p>The MainWindowHandle property is cached after it is first accessed which is why you don't see it changing even after the handle becomes invalid. GregUzelac's information is correct. Calling Proces.Refresh will causes the next call to Process.MainWindowHandle to re-do the logic to find a new main window handle. Michael's logic also works because the new Process doesn't have a cached version of the MainWindowHandle.</p>\n"}, {'answer_id': 4536066, 'author': 'Giova', 'author_id': 554557, 'author_profile': 'https://Stackoverflow.com/users/554557', 'pm_score': 2, 'selected': False, 'text': '<p>Thank you for your answers. Thanks to you here, I figured out how to know if the main window of a process is in front or not:</p>\n\n<p>N.B : of course this needs System.Diagnostic and System.Runtime.Interrop</p>\n\n<pre><code>public bool IsWindowActive(Int32 PID)\n{\n return IsWindowActive(Process.GetProcessById(PID));\n}\n\n[DllImport("user32.dll")]\nprivate static extern\nIntPtr GetForegroundWindow();\n\npublic bool IsWindowActive(Process proc)\n{\n proc.Refresh();\n return proc.MainWindowHandle.Equals(GetForegroundWindow());\n}\n</code></pre>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79111', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14656/']
79,121
<p>So, im trying to write some code that utilizes Nvidia's CUDA architecture. I noticed that copying to and from the device was really hurting my overall performance, so now I am trying to move a large amount of data onto the device.</p> <p>As this data is used in numerous functions, I would like it to be global. Yes, I can pass pointers around, but I would really like to know how to work with globals in this instance. </p> <p>So, I have device functions that want to access a device allocated array.</p> <p>Ideally, I could do something like:</p> <pre><code>__device__ float* global_data; main() { cudaMalloc(global_data); kernel1&lt;&lt;&lt;blah&gt;&gt;&gt;(blah); //access global data kernel2&lt;&lt;&lt;blah&gt;&gt;&gt;(blah); //access global data again } </code></pre> <p>However, I havent figured out how to create a dynamic array. I figured out a work around by declaring the array as follows:</p> <pre><code>__device__ float global_data[REALLY_LARGE_NUMBER]; </code></pre> <p>And while that doesn't require a cudaMalloc call, I would prefer the dynamic allocation approach.</p>
[{'answer_id': 79256, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Spend some time focusing on the copious documentation offered by NVIDIA.</p>\n\n<p>From the Programming Guide:</p>\n\n<pre><code>float* devPtr;\ncudaMalloc((void**)&amp;devPtr, 256 * sizeof(*devPtr));\ncudaMemset(devPtr, 0, 256 * sizeof(*devPtr));\n</code></pre>\n\n<p>That\'s a simple example of how to allocate memory. Now, in your kernels, you should accept a pointer to a float like so:</p>\n\n<pre><code>__global__\nvoid kernel1(float *some_neat_data)\n{\n some_neat_data[threadIdx.x]++;\n}\n\n__global__\nvoid kernel2(float *potentially_that_same_neat_data)\n{\n potentially_that_same_neat_data[threadIdx.x] *= 0.3f;\n}\n</code></pre>\n\n<p>So now you can invoke them like so:</p>\n\n<pre><code>float* devPtr;\ncudaMalloc((void**)&amp;devPtr, 256 * sizeof(*devPtr));\ncudaMemset(devPtr, 0, 256 * sizeof(*devPtr));\n\nkernel1&lt;&lt;&lt;1,128&gt;&gt;&gt;(devPtr);\nkernel2&lt;&lt;&lt;1,128&gt;&gt;&gt;(devPtr);\n</code></pre>\n\n<blockquote>\n <p>As this data is used in numerous\n functions, I would like it to be\n global.</p>\n</blockquote>\n\n<p>There are few good reasons to use globals. This definitely is not one. I\'ll leave it as an exercise to expand this example to include moving "devPtr" to a global scope.</p>\n\n<p>EDIT:</p>\n\n<p>Ok, the fundamental problem is this: your kernels can only access device memory and the only global-scope pointers that they can use are GPU ones. When calling a kernel from your CPU, behind the scenes what happens is that the pointers and primitives get copied into GPU registers and/or shared memory before the kernel gets executed.</p>\n\n<p>So the closest I can suggest is this: use cudaMemcpyToSymbol() to achieve your goals. But, in the background, consider that a different approach might be the Right Thing.</p>\n\n<pre><code>#include &lt;algorithm&gt;\n\n__constant__ float devPtr[1024];\n\n__global__\nvoid kernel1(float *some_neat_data)\n{\n some_neat_data[threadIdx.x] = devPtr[0] * devPtr[1];\n}\n\n__global__\nvoid kernel2(float *potentially_that_same_neat_data)\n{\n potentially_that_same_neat_data[threadIdx.x] *= devPtr[2];\n}\n\n\nint main(int argc, char *argv[])\n{\n float some_data[256];\n for (int i = 0; i &lt; sizeof(some_data) / sizeof(some_data[0]); i++)\n {\n some_data[i] = i * 2;\n }\n cudaMemcpyToSymbol(devPtr, some_data, std::min(sizeof(some_data), sizeof(devPtr) ));\n float* otherDevPtr;\n cudaMalloc((void**)&amp;otherDevPtr, 256 * sizeof(*otherDevPtr));\n cudaMemset(otherDevPtr, 0, 256 * sizeof(*otherDevPtr));\n\n kernel1&lt;&lt;&lt;1,128&gt;&gt;&gt;(otherDevPtr);\n kernel2&lt;&lt;&lt;1,128&gt;&gt;&gt;(otherDevPtr);\n\n return 0;\n}\n</code></pre>\n\n<p>Don\'t forget \'--host-compilation=c++\' for this example.</p>\n'}, {'answer_id': 79336, 'author': 'Voltaire', 'author_id': 14621, 'author_profile': 'https://Stackoverflow.com/users/14621', 'pm_score': 0, 'selected': False, 'text': "<p>Erm, it was exactly that problem of moving devPtr to global scope that was my problem.</p>\n\n<p>I have an implementation that does exactly that, with the two kernels having a pointer to data passed in. I explicitly don't want to pass in those pointers.</p>\n\n<p>I have read the documentation fairly closely, and hit up the nvidia forums (and google searched for an hour or so), but I haven't found an implementation of a global dynamic device array that actually runs (i have tried several that compile and then fail in new and interesting ways).</p>\n"}, {'answer_id': 79796, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': True, 'text': '<p>Something like this should probably work.</p>\n\n<pre><code>#include &lt;algorithm&gt;\n\n#define NDEBUG\n#define CUT_CHECK_ERROR(errorMessage) do { \\\n cudaThreadSynchronize(); \\\n cudaError_t err = cudaGetLastError(); \\\n if( cudaSuccess != err) { \\\n fprintf(stderr, "Cuda error: %s in file \'%s\' in line %i : %s.\\n", \\\n errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\\\n exit(EXIT_FAILURE); \\\n } } while (0)\n\n\n__device__ float *devPtr;\n\n__global__\nvoid kernel1(float *some_neat_data)\n{\n devPtr = some_neat_data;\n}\n\n__global__\nvoid kernel2(void)\n{\n devPtr[threadIdx.x] *= .3f;\n}\n\n\nint main(int argc, char *argv[])\n{\n float* otherDevPtr;\n cudaMalloc((void**)&amp;otherDevPtr, 256 * sizeof(*otherDevPtr));\n cudaMemset(otherDevPtr, 0, 256 * sizeof(*otherDevPtr));\n\n kernel1&lt;&lt;&lt;1,128&gt;&gt;&gt;(otherDevPtr);\n CUT_CHECK_ERROR("kernel1");\n\n kernel2&lt;&lt;&lt;1,128&gt;&gt;&gt;();\n\n CUT_CHECK_ERROR("kernel2");\n\n return 0;\n}\n</code></pre>\n\n<p>Give it a whirl.</p>\n'}, {'answer_id': 89477, 'author': 'Mark Borgerding', 'author_id': 3343, 'author_profile': 'https://Stackoverflow.com/users/3343', 'pm_score': 0, 'selected': False, 'text': '<p>check out the samples included with the SDK. Many of those sample projects are a decent way to learn by example.</p>\n'}, {'answer_id': 94437, 'author': 'Voltaire', 'author_id': 14621, 'author_profile': 'https://Stackoverflow.com/users/14621', 'pm_score': 1, 'selected': False, 'text': '<p>I went ahead and tried the solution of allocating a temporary pointer and passing it to a simple global function similar to kernel1.</p>\n\n<p>The good news is that it does work :)</p>\n\n<p>However, I think it confuses the compiler as I now get "Advisory: Cannot tell what pointer points to, assuming global memory space" whenever I try to access the global data. Luckily, the assumption happens to be correct, but the warnings are annoying.</p>\n\n<p>Anyway, for the record - I have looked at many of the examples and did run through the nvidia exercises where the point is to get the output to say "Correct!". However, I haven\'t looked at <em>all</em> of them. If anyone knows of an sdk example where they do dynamic global device memory allocation, I would still like to know.</p>\n'}, {'answer_id': 3511490, 'author': 'Nils', 'author_id': 44232, 'author_profile': 'https://Stackoverflow.com/users/44232', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n <p>As this data is used in numerous functions, I would like it to be global.</p>\n</blockquote>\n\n<p>-</p>\n\n<blockquote>\n <p>There are few good reasons to use globals. This definitely is not one. I\'ll leave it as an \n exercise to expand this example to include moving "devPtr" to a global scope.</p>\n</blockquote>\n\n<p>What if the kernel operates on a large const structure consisting of arrays? Using the so called constant memory is not an option, because it\'s very limited in size.. so then you have to put it in global memory..?</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79121', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14621/']
79,126
<p>I'm building a function to extend the <code>Enum.Parse</code> concept that</p> <ul> <li>Allows a default value to be parsed in case that an Enum value is not found</li> <li>Is case insensitive</li> </ul> <p>So I wrote the following:</p> <pre><code>public static T GetEnumFromString&lt;T&gt;(string value, T defaultValue) where T : Enum { if (string.IsNullOrEmpty(value)) return defaultValue; foreach (T item in Enum.GetValues(typeof(T))) { if (item.ToString().ToLower().Equals(value.Trim().ToLower())) return item; } return defaultValue; } </code></pre> <p>I am getting a Error Constraint cannot be special class <code>System.Enum</code>.</p> <p>Fair enough, but is there a workaround to allow a Generic Enum, or am I going to have to mimic the <code>Parse</code> function and pass a type as an attribute, which forces the ugly boxing requirement to your code.</p> <p><strong>EDIT</strong> All suggestions below have been greatly appreciated, thanks.</p> <p>Have settled on (I've left the loop to maintain case insensitivity - I am using this when parsing XML)</p> <pre><code>public static class EnumUtils { public static T ParseEnum&lt;T&gt;(string value, T defaultValue) where T : struct, IConvertible { if (!typeof(T).IsEnum) throw new ArgumentException(&quot;T must be an enumerated type&quot;); if (string.IsNullOrEmpty(value)) return defaultValue; foreach (T item in Enum.GetValues(typeof(T))) { if (item.ToString().ToLower().Equals(value.Trim().ToLower())) return item; } return defaultValue; } } </code></pre> <p><strong>EDIT:</strong> (16th Feb 2015) Christopher Currens has posted <a href="https://stackoverflow.com/a/8086788">a compiler enforced type-safe generic solution in MSIL or F#</a> below, which is well worth a look, and an upvote. I will remove this edit if the solution bubbles further up the page.</p> <p><strong>EDIT 2:</strong> (13th Apr 2021) As this has now been addressed, and supported, since C# 7.3, I have changed the accepted answer, though full perusal of the top answers is worth it for academic, and historical, interest :)</p>
[{'answer_id': 79148, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 3, 'selected': False, 'text': '<p>Hope this is helpful:</p>\n\n<pre><code>public static TValue ParseEnum&lt;TValue&gt;(string value, TValue defaultValue)\n where TValue : struct // enum \n{\n try\n {\n if (String.IsNullOrEmpty(value))\n return defaultValue;\n return (TValue)Enum.Parse(typeof (TValue), value);\n }\n catch(Exception ex)\n {\n return defaultValue;\n }\n}\n</code></pre>\n'}, {'answer_id': 79251, 'author': 'Bivoauc', 'author_id': 14715, 'author_profile': 'https://Stackoverflow.com/users/14715', 'pm_score': 4, 'selected': False, 'text': '<p>I modified the sample by dimarzionist. This version will only work with Enums and not let structs get through. </p>\n\n<pre><code>public static T ParseEnum&lt;T&gt;(string enumString)\n where T : struct // enum \n {\n if (String.IsNullOrEmpty(enumString) || !typeof(T).IsEnum)\n throw new Exception("Type given must be an Enum");\n try\n {\n\n return (T)Enum.Parse(typeof(T), enumString, true);\n }\n catch (Exception ex)\n {\n return default(T);\n }\n}\n</code></pre>\n'}, {'answer_id': 79319, 'author': 'Karg', 'author_id': 12685, 'author_profile': 'https://Stackoverflow.com/users/12685', 'pm_score': 4, 'selected': False, 'text': '<p>You can define a static constructor for the class that will check that the type T is an enum and throw an exception if it is not. This is the method mentioned by Jeffery Richter in his book CLR via C#.</p>\n\n<pre><code>internal sealed class GenericTypeThatRequiresAnEnum&lt;T&gt; {\n static GenericTypeThatRequiresAnEnum() {\n if (!typeof(T).IsEnum) {\n throw new ArgumentException("T must be an enumerated type");\n }\n }\n}\n</code></pre>\n\n<p>Then in the parse method, you can just use Enum.Parse(typeof(T), input, true) to convert from string to the enum. The last true parameter is for ignoring case of the input. </p>\n'}, {'answer_id': 79903, 'author': 'Vivek', 'author_id': 7418, 'author_profile': 'https://Stackoverflow.com/users/7418', 'pm_score': 10, 'selected': False, 'text': '<p>Since <code>Enum</code> Type implements <code>IConvertible</code> interface, a better implementation should be something like this:</p>\n\n<pre><code>public T GetEnumFromString&lt;T&gt;(string value) where T : struct, IConvertible\n{\n if (!typeof(T).IsEnum) \n {\n throw new ArgumentException("T must be an enumerated type");\n }\n\n //...\n}\n</code></pre>\n\n<p>This will still permit passing of value types implementing <code>IConvertible</code>. The chances are rare though.</p>\n'}, {'answer_id': 1093531, 'author': 'Andrew', 'author_id': 15127, 'author_profile': 'https://Stackoverflow.com/users/15127', 'pm_score': 2, 'selected': False, 'text': '<p>Interestingly enough, apparently this is <a href="http://social.msdn.microsoft.com/Forums/en-US/vs2010ctpvbcs/thread/5844d719-3ef6-4000-913c-27c108269e71" rel="nofollow noreferrer">possible in other langauges</a> (Managed C++, IL directly). </p>\n\n<p>To Quote:</p>\n\n<blockquote>\n <p>... Both constraints actually produce valid IL and can also be consumed by C# if written in another language (you can declare those constraints in managed C++ or in IL).</p>\n</blockquote>\n\n<p>Who knows </p>\n'}, {'answer_id': 2661254, 'author': 'Sunny Rajwadi', 'author_id': 319544, 'author_profile': 'https://Stackoverflow.com/users/319544', 'pm_score': 3, 'selected': False, 'text': '<p>I do have specific requirement where I required to use enum with text associated with enum value. For example when I use enum to specify error type it required to describe error details.</p>\n\n<pre><code>public static class XmlEnumExtension\n{\n public static string ReadXmlEnumAttribute(this Enum value)\n {\n if (value == null) throw new ArgumentNullException("value");\n var attribs = (XmlEnumAttribute[]) value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof (XmlEnumAttribute), true);\n return attribs.Length &gt; 0 ? attribs[0].Name : value.ToString();\n }\n\n public static T ParseXmlEnumAttribute&lt;T&gt;(this string str)\n {\n foreach (T item in Enum.GetValues(typeof(T)))\n {\n var attribs = (XmlEnumAttribute[])item.GetType().GetField(item.ToString()).GetCustomAttributes(typeof(XmlEnumAttribute), true);\n if(attribs.Length &gt; 0 &amp;&amp; attribs[0].Name.Equals(str)) return item;\n }\n return (T)Enum.Parse(typeof(T), str, true);\n }\n}\n\npublic enum MyEnum\n{\n [XmlEnum("First Value")]\n One,\n [XmlEnum("Second Value")]\n Two,\n Three\n}\n\n static void Main()\n {\n // Parsing from XmlEnum attribute\n var str = "Second Value";\n var me = str.ParseXmlEnumAttribute&lt;MyEnum&gt;();\n System.Console.WriteLine(me.ReadXmlEnumAttribute());\n // Parsing without XmlEnum\n str = "Three";\n me = str.ParseXmlEnumAttribute&lt;MyEnum&gt;();\n System.Console.WriteLine(me.ReadXmlEnumAttribute());\n me = MyEnum.One;\n System.Console.WriteLine(me.ReadXmlEnumAttribute());\n}\n</code></pre>\n'}, {'answer_id': 3859812, 'author': 'Jeff', 'author_id': 164438, 'author_profile': 'https://Stackoverflow.com/users/164438', 'pm_score': 2, 'selected': False, 'text': '<p>I always liked this (you could modify as appropriate):</p>\n\n<pre><code>public static IEnumerable&lt;TEnum&gt; GetEnumValues()\n{\n Type enumType = typeof(TEnum);\n\n if(!enumType.IsEnum)\n throw new ArgumentException("Type argument must be Enum type");\n\n Array enumValues = Enum.GetValues(enumType);\n return enumValues.Cast&lt;TEnum&gt;();\n}\n</code></pre>\n'}, {'answer_id': 4460247, 'author': 'Martin', 'author_id': 394076, 'author_profile': 'https://Stackoverflow.com/users/394076', 'pm_score': 4, 'selected': False, 'text': '<p>I tried to improve the code a bit:</p>\n\n<pre><code>public T LoadEnum&lt;T&gt;(string value, T defaultValue = default(T)) where T : struct, IComparable, IFormattable, IConvertible\n{\n if (Enum.IsDefined(typeof(T), value))\n {\n return (T)Enum.Parse(typeof(T), value, true);\n }\n return defaultValue;\n}\n</code></pre>\n'}, {'answer_id': 8086788, 'author': 'Christopher Currens', 'author_id': 721276, 'author_profile': 'https://Stackoverflow.com/users/721276', 'pm_score': 11, 'selected': True, 'text': '<h2>This feature is finally supported in C# 7.3!</h2>\n<p>The following snippet (from <a href="https://github.com/dotnet/samples/blob/3ee82879284e3f4755251fd33c3b3e533f7b3485/snippets/csharp/keywords/GenericWhereConstraints.cs#L180-L190" rel="noreferrer">the dotnet samples</a>) demonstrates how:</p>\n<pre><code>public static Dictionary&lt;int, string&gt; EnumNamedValues&lt;T&gt;() where T : System.Enum\n{\n var result = new Dictionary&lt;int, string&gt;();\n var values = Enum.GetValues(typeof(T));\n\n foreach (int item in values)\n result.Add(item, Enum.GetName(typeof(T), item));\n return result;\n}\n</code></pre>\n<p>Be sure to set your language version in your C# project to version 7.3.</p>\n<hr />\n<p>Original Answer below:</p>\n<p>I\'m late to the game, but I took it as a challenge to see how it could be done. It\'s not possible in C# (or VB.NET, but scroll down for F#), but <em>is possible</em> in MSIL. I wrote this little....thing</p>\n<pre><code>// license: http://www.apache.org/licenses/LICENSE-2.0.html\n.assembly MyThing{}\n.class public abstract sealed MyThing.Thing\n extends [mscorlib]System.Object\n{\n .method public static !!T GetEnumFromString&lt;valuetype .ctor ([mscorlib]System.Enum) T&gt;(string strValue,\n !!T defaultValue) cil managed\n {\n .maxstack 2\n .locals init ([0] !!T temp,\n [1] !!T return_value,\n [2] class [mscorlib]System.Collections.IEnumerator enumerator,\n [3] class [mscorlib]System.IDisposable disposer)\n // if(string.IsNullOrEmpty(strValue)) return defaultValue;\n ldarg strValue\n call bool [mscorlib]System.String::IsNullOrEmpty(string)\n brfalse.s HASVALUE\n br RETURNDEF // return default it empty\n \n // foreach (T item in Enum.GetValues(typeof(T)))\n HASVALUE:\n // Enum.GetValues.GetEnumerator()\n ldtoken !!T\n call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)\n call class [mscorlib]System.Array [mscorlib]System.Enum::GetValues(class [mscorlib]System.Type)\n callvirt instance class [mscorlib]System.Collections.IEnumerator [mscorlib]System.Array::GetEnumerator() \n stloc enumerator\n .try\n {\n CONDITION:\n ldloc enumerator\n callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext()\n brfalse.s LEAVE\n \n STATEMENTS:\n // T item = (T)Enumerator.Current\n ldloc enumerator\n callvirt instance object [mscorlib]System.Collections.IEnumerator::get_Current()\n unbox.any !!T\n stloc temp\n ldloca.s temp\n constrained. !!T\n \n // if (item.ToString().ToLower().Equals(value.Trim().ToLower())) return item;\n callvirt instance string [mscorlib]System.Object::ToString()\n callvirt instance string [mscorlib]System.String::ToLower()\n ldarg strValue\n callvirt instance string [mscorlib]System.String::Trim()\n callvirt instance string [mscorlib]System.String::ToLower()\n callvirt instance bool [mscorlib]System.String::Equals(string)\n brfalse.s CONDITION\n ldloc temp\n stloc return_value\n leave.s RETURNVAL\n \n LEAVE:\n leave.s RETURNDEF\n }\n finally\n {\n // ArrayList\'s Enumerator may or may not inherit from IDisposable\n ldloc enumerator\n isinst [mscorlib]System.IDisposable\n stloc.s disposer\n ldloc.s disposer\n ldnull\n ceq\n brtrue.s LEAVEFINALLY\n ldloc.s disposer\n callvirt instance void [mscorlib]System.IDisposable::Dispose()\n LEAVEFINALLY:\n endfinally\n }\n \n RETURNDEF:\n ldarg defaultValue\n stloc return_value\n \n RETURNVAL:\n ldloc return_value\n ret\n }\n} \n</code></pre>\n<p>Which generates a function that <strong>would</strong> look like this, if it were valid C#:</p>\n<pre><code>T GetEnumFromString&lt;T&gt;(string valueString, T defaultValue) where T : Enum\n</code></pre>\n<p>Then with the following C# code:</p>\n<pre><code>using MyThing;\n// stuff...\nprivate enum MyEnum { Yes, No, Okay }\nstatic void Main(string[] args)\n{\n Thing.GetEnumFromString(&quot;No&quot;, MyEnum.Yes); // returns MyEnum.No\n Thing.GetEnumFromString(&quot;Invalid&quot;, MyEnum.Okay); // returns MyEnum.Okay\n Thing.GetEnumFromString(&quot;AnotherInvalid&quot;, 0); // compiler error, not an Enum\n}\n</code></pre>\n<p>Unfortunately, this means having this part of your code written in MSIL instead of C#, with the only added benefit being that you\'re able to constrain this method by <code>System.Enum</code>. It\'s also kind of a bummer, because it gets compiled into a separate assembly. However, it doesn\'t mean you have to deploy it that way.</p>\n<p>By removing the line <code>.assembly MyThing{}</code> and invoking ilasm as follows:</p>\n<pre><code>ilasm.exe /DLL /OUTPUT=MyThing.netmodule\n</code></pre>\n<p>you get a netmodule instead of an assembly.</p>\n<p>Unfortunately, VS2010 (and earlier, obviously) does not support adding netmodule references, which means you\'d have to leave it in 2 separate assemblies when you\'re debugging. The only way you can add them as part of your assembly would be to run csc.exe yourself using the <code>/addmodule:{files}</code> command line argument. It wouldn\'t be <em>too</em> painful in an MSBuild script. Of course, if you\'re brave or stupid, you can run csc yourself manually each time. And it certainly gets more complicated as multiple assemblies need access to it.</p>\n<p>So, it CAN be done in .Net. Is it worth the extra effort? Um, well, I guess I\'ll let you decide on that one.</p>\n<hr />\n<h3>F# Solution as alternative</h3>\n<p>Extra Credit: It turns out that a generic restriction on <code>enum</code> is possible in at least one other .NET language besides MSIL: F#.</p>\n<pre class="lang-ml prettyprint-override"><code>type MyThing =\n static member GetEnumFromString&lt;\'T when \'T :&gt; Enum&gt; str defaultValue: \'T =\n /// protect for null (only required in interop with C#)\n let str = if isNull str then String.Empty else str\n\n Enum.GetValues(typedefof&lt;\'T&gt;)\n |&gt; Seq.cast&lt;_&gt;\n |&gt; Seq.tryFind(fun v -&gt; String.Compare(v.ToString(), str.Trim(), true) = 0)\n |&gt; function Some x -&gt; x | None -&gt; defaultValue\n</code></pre>\n<p>This one is easier to maintain since it\'s a well-known language with full Visual Studio IDE support, but you still need a separate project in your solution for it. However, it naturally produces considerably different IL (the code <em>is</em> very different) and it relies on the <code>FSharp.Core</code> library, which, just like any other external library, needs to become part of your distribution.</p>\n<p>Here\'s how you can use it (basically the same as the MSIL solution), and to show that it correctly fails on otherwise synonymous structs:</p>\n<pre><code>// works, result is inferred to have type StringComparison\nvar result = MyThing.GetEnumFromString(&quot;OrdinalIgnoreCase&quot;, StringComparison.Ordinal);\n// type restriction is recognized by C#, this fails at compile time\nvar result = MyThing.GetEnumFromString(&quot;OrdinalIgnoreCase&quot;, 42);\n</code></pre>\n'}, {'answer_id': 10273741, 'author': 'expert', 'author_id': 226895, 'author_profile': 'https://Stackoverflow.com/users/226895', 'pm_score': 1, 'selected': False, 'text': '<p>I loved Christopher Currens\'s solution using IL but for those who don\'t want to deal with tricky business of including MSIL into their build process I wrote similar function in C#.</p>\n\n<p>Please note though that you can\'t use generic restriction like <code>where T : Enum</code> because Enum is special type. Therefore I have to check if given generic type is really enum.</p>\n\n<p>My function is:</p>\n\n<pre><code>public static T GetEnumFromString&lt;T&gt;(string strValue, T defaultValue)\n{\n // Check if it realy enum at runtime \n if (!typeof(T).IsEnum)\n throw new ArgumentException("Method GetEnumFromString can be used with enums only");\n\n if (!string.IsNullOrEmpty(strValue))\n {\n IEnumerator enumerator = Enum.GetValues(typeof(T)).GetEnumerator();\n while (enumerator.MoveNext())\n {\n T temp = (T)enumerator.Current;\n if (temp.ToString().ToLower().Equals(strValue.Trim().ToLower()))\n return temp;\n }\n }\n\n return defaultValue;\n}\n</code></pre>\n'}, {'answer_id': 16736914, 'author': 'Yahoo Serious', 'author_id': 422877, 'author_profile': 'https://Stackoverflow.com/users/422877', 'pm_score': 5, 'selected': False, 'text': '<p><strong>Edit</strong></p>\n\n<p>The question has now superbly been answered by <a href="https://stackoverflow.com/a/28527552/422877">Julien Lebosquain</a>.\nI would also like to extend his answer with <code>ignoreCase</code>, <code>defaultValue</code> and optional arguments, while adding <code>TryParse</code> and <code>ParseOrDefault</code>.</p>\n\n<pre><code>public abstract class ConstrainedEnumParser&lt;TClass&gt; where TClass : class\n// value type constraint S ("TEnum") depends on reference type T ("TClass") [and on struct]\n{\n // internal constructor, to prevent this class from being inherited outside this code\n internal ConstrainedEnumParser() {}\n // Parse using pragmatic/adhoc hard cast:\n // - struct + class = enum\n // - \'guaranteed\' call from derived &lt;System.Enum&gt;-constrained type EnumUtils\n public static TEnum Parse&lt;TEnum&gt;(string value, bool ignoreCase = false) where TEnum : struct, TClass\n {\n return (TEnum)Enum.Parse(typeof(TEnum), value, ignoreCase);\n }\n public static bool TryParse&lt;TEnum&gt;(string value, out TEnum result, bool ignoreCase = false, TEnum defaultValue = default(TEnum)) where TEnum : struct, TClass // value type constraint S depending on T\n {\n var didParse = Enum.TryParse(value, ignoreCase, out result);\n if (didParse == false)\n {\n result = defaultValue;\n }\n return didParse;\n }\n public static TEnum ParseOrDefault&lt;TEnum&gt;(string value, bool ignoreCase = false, TEnum defaultValue = default(TEnum)) where TEnum : struct, TClass // value type constraint S depending on T\n {\n if (string.IsNullOrEmpty(value)) { return defaultValue; }\n TEnum result;\n if (Enum.TryParse(value, ignoreCase, out result)) { return result; }\n return defaultValue;\n }\n}\n\npublic class EnumUtils: ConstrainedEnumParser&lt;System.Enum&gt;\n// reference type constraint to any &lt;System.Enum&gt;\n{\n // call to parse will then contain constraint to specific &lt;System.Enum&gt;-class\n}\n</code></pre>\n\n<p>Examples of usage:</p>\n\n<pre><code>WeekDay parsedDayOrArgumentException = EnumUtils.Parse&lt;WeekDay&gt;("monday", ignoreCase:true);\nWeekDay parsedDayOrDefault;\nbool didParse = EnumUtils.TryParse&lt;WeekDay&gt;("clubs", out parsedDayOrDefault, ignoreCase:true);\nparsedDayOrDefault = EnumUtils.ParseOrDefault&lt;WeekDay&gt;("friday", ignoreCase:true, defaultValue:WeekDay.Sunday);\n</code></pre>\n\n<hr>\n\n<p><strong>Old</strong></p>\n\n<p>My old improvements on <a href="https://stackoverflow.com/a/79903">Vivek\'s answer</a> by using the comments and \'new\' developments:</p>\n\n<ul>\n<li>use <code>TEnum</code> for clarity for users</li>\n<li>add more interface-constraints for additional constraint-checking</li>\n<li>let <a href="http://msdn.microsoft.com/en-us/library/dd991317.aspx" rel="noreferrer"><code>TryParse</code></a> handle <code>ignoreCase</code> with the existing parameter\n(introduced in VS2010/.Net 4) </li>\n<li>optionally use the generic <a href="http://msdn.microsoft.com/en-us/library/xwth0h0d.aspx" rel="noreferrer"><code>default</code> value</a> (introduced in VS2005/.Net 2)</li>\n<li>use <a href="http://msdn.microsoft.com/en-us/library/dd264739.aspx" rel="noreferrer">optional arguments</a>(introduced in VS2010/.Net 4) with default values, for <code>defaultValue</code> and <code>ignoreCase</code></li>\n</ul>\n\n<p>resulting in:</p>\n\n<pre><code>public static class EnumUtils\n{\n public static TEnum ParseEnum&lt;TEnum&gt;(this string value,\n bool ignoreCase = true,\n TEnum defaultValue = default(TEnum))\n where TEnum : struct, IComparable, IFormattable, IConvertible\n {\n if ( ! typeof(TEnum).IsEnum) { throw new ArgumentException("TEnum must be an enumerated type"); }\n if (string.IsNullOrEmpty(value)) { return defaultValue; }\n TEnum lResult;\n if (Enum.TryParse(value, ignoreCase, out lResult)) { return lResult; }\n return defaultValue;\n }\n}\n</code></pre>\n'}, {'answer_id': 17852186, 'author': 'niaher', 'author_id': 111438, 'author_profile': 'https://Stackoverflow.com/users/111438', 'pm_score': 1, 'selected': False, 'text': '<p>I\'ve encapsulated Vivek\'s solution into a utility class that you can reuse. Please note that you still should define type constraints "where T : struct, IConvertible" on your type.</p>\n\n<pre><code>using System;\n\ninternal static class EnumEnforcer\n{\n /// &lt;summary&gt;\n /// Makes sure that generic input parameter is of an enumerated type.\n /// &lt;/summary&gt;\n /// &lt;typeparam name="T"&gt;Type that should be checked.&lt;/typeparam&gt;\n /// &lt;param name="typeParameterName"&gt;Name of the type parameter.&lt;/param&gt;\n /// &lt;param name="methodName"&gt;Name of the method which accepted the parameter.&lt;/param&gt;\n public static void EnforceIsEnum&lt;T&gt;(string typeParameterName, string methodName)\n where T : struct, IConvertible\n {\n if (!typeof(T).IsEnum)\n {\n string message = string.Format(\n "Generic parameter {0} in {1} method forces an enumerated type. Make sure your type parameter {0} is an enum.",\n typeParameterName,\n methodName);\n\n throw new ArgumentException(message);\n }\n }\n\n /// &lt;summary&gt;\n /// Makes sure that generic input parameter is of an enumerated type.\n /// &lt;/summary&gt;\n /// &lt;typeparam name="T"&gt;Type that should be checked.&lt;/typeparam&gt;\n /// &lt;param name="typeParameterName"&gt;Name of the type parameter.&lt;/param&gt;\n /// &lt;param name="methodName"&gt;Name of the method which accepted the parameter.&lt;/param&gt;\n /// &lt;param name="inputParameterName"&gt;Name of the input parameter of this page.&lt;/param&gt;\n public static void EnforceIsEnum&lt;T&gt;(string typeParameterName, string methodName, string inputParameterName)\n where T : struct, IConvertible\n {\n if (!typeof(T).IsEnum)\n {\n string message = string.Format(\n "Generic parameter {0} in {1} method forces an enumerated type. Make sure your input parameter {2} is of correct type.",\n typeParameterName,\n methodName,\n inputParameterName);\n\n throw new ArgumentException(message);\n }\n }\n\n /// &lt;summary&gt;\n /// Makes sure that generic input parameter is of an enumerated type.\n /// &lt;/summary&gt;\n /// &lt;typeparam name="T"&gt;Type that should be checked.&lt;/typeparam&gt;\n /// &lt;param name="exceptionMessage"&gt;Message to show in case T is not an enum.&lt;/param&gt;\n public static void EnforceIsEnum&lt;T&gt;(string exceptionMessage)\n where T : struct, IConvertible\n {\n if (!typeof(T).IsEnum)\n {\n throw new ArgumentException(exceptionMessage);\n }\n }\n}\n</code></pre>\n'}, {'answer_id': 22636379, 'author': 'KarmaEDV', 'author_id': 2620046, 'author_profile': 'https://Stackoverflow.com/users/2620046', 'pm_score': 2, 'selected': False, 'text': '<p>This is my take at it. Combined from the answers and MSDN</p>\n\n<pre><code>public static TEnum ParseToEnum&lt;TEnum&gt;(this string text) where TEnum : struct, IConvertible, IComparable, IFormattable\n{\n if (string.IsNullOrEmpty(text) || !typeof(TEnum).IsEnum)\n throw new ArgumentException("TEnum must be an Enum type");\n\n try\n {\n var enumValue = (TEnum)Enum.Parse(typeof(TEnum), text.Trim(), true);\n return enumValue;\n }\n catch (Exception)\n {\n throw new ArgumentException(string.Format("{0} is not a member of the {1} enumeration.", text, typeof(TEnum).Name));\n }\n}\n</code></pre>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/kxydatf9%28v=vs.110%29.aspx" rel="nofollow">MSDN Source</a></p>\n'}, {'answer_id': 28527552, 'author': 'Julien Lebosquain', 'author_id': 183367, 'author_profile': 'https://Stackoverflow.com/users/183367', 'pm_score': 8, 'selected': False, 'text': '<h1>C# ≥ 7.3</h1>\n\n<p>Starting with C# 7.3 (available with Visual Studio 2017 ≥ v15.7), this code is now completely valid:</p>\n\n<pre><code>public static TEnum Parse&lt;TEnum&gt;(string value)\n where TEnum : struct, Enum\n{\n ...\n}\n</code></pre>\n\n<hr>\n\n<h1>C# ≤ 7.2</h1>\n\n<p>You can have a real compiler enforced enum constraint by abusing constraint inheritance. The following code specifies both a <code>class</code> and a <code>struct</code> constraints at the same time:</p>\n\n<pre><code>public abstract class EnumClassUtils&lt;TClass&gt;\nwhere TClass : class\n{\n\n public static TEnum Parse&lt;TEnum&gt;(string value)\n where TEnum : struct, TClass\n {\n return (TEnum) Enum.Parse(typeof(TEnum), value);\n }\n\n}\n\npublic class EnumUtils : EnumClassUtils&lt;Enum&gt;\n{\n}\n</code></pre>\n\n<p>Usage:</p>\n\n<pre><code>EnumUtils.Parse&lt;SomeEnum&gt;("value");\n</code></pre>\n\n<p>Note: this is specifically stated in the C# 5.0 language specification:</p>\n\n<blockquote>\n <p>If type parameter S depends on type parameter T then:\n [...] It is valid for\n S to have the value type constraint and T to have the reference type\n constraint. Effectively this limits T to the types System.Object,\n System.ValueType, System.Enum, and any interface type.</p>\n</blockquote>\n'}, {'answer_id': 40357283, 'author': 'Basheer AL-MOMANI', 'author_id': 4251431, 'author_profile': 'https://Stackoverflow.com/users/4251431', 'pm_score': 1, 'selected': False, 'text': '<p>I created an extension Method <code>to get integer value from enum</code> \ntake look at method implementation </p>\n\n<pre><code>public static int ToInt&lt;T&gt;(this T soure) where T : IConvertible//enum\n{\n if (typeof(T).IsEnum)\n {\n return (int) (IConvertible)soure;// the tricky part\n }\n //else\n // throw new ArgumentException("T must be an enumerated type");\n return soure.ToInt32(CultureInfo.CurrentCulture);\n}\n</code></pre>\n\n<p>this is usage </p>\n\n<pre><code>MemberStatusEnum.Activated.ToInt()// using extension Method\n(int) MemberStatusEnum.Activated //the ordinary way\n</code></pre>\n'}, {'answer_id': 45274236, 'author': 'BatteryBackupUnit', 'author_id': 684096, 'author_profile': 'https://Stackoverflow.com/users/684096', 'pm_score': 1, 'selected': False, 'text': '<p>As stated in other answers before; while this cannot be expressed in source-code it can actually be done on IL Level.\n@Christopher Currens <a href="https://stackoverflow.com/a/8086788/684096">answer</a> shows how the IL do to that.</p>\n\n<p>With <a href="https://github.com/Fody/Fody" rel="nofollow noreferrer">Fody</a>s Add-In <a href="https://github.com/Fody/ExtraConstraints" rel="nofollow noreferrer">ExtraConstraints.Fody</a> there\'s a very simple way, complete with build-tooling, to achieve this. Just add their nuget packages (<code>Fody</code>, <code>ExtraConstraints.Fody</code>) to your project and add the constraints as follows (Excerpt from the Readme of ExtraConstraints):</p>\n\n<pre><code>public void MethodWithEnumConstraint&lt;[EnumConstraint] T&gt;() {...}\n\npublic void MethodWithTypeEnumConstraint&lt;[EnumConstraint(typeof(ConsoleColor))] T&gt;() {...}\n</code></pre>\n\n<p>and Fody will add the necessary IL for the constraint to be present.\nAlso note the additional feature of constraining delegates:</p>\n\n<pre><code>public void MethodWithDelegateConstraint&lt;[DelegateConstraint] T&gt; ()\n{...}\n\npublic void MethodWithTypeDelegateConstraint&lt;[DelegateConstraint(typeof(Func&lt;int&gt;))] T&gt; ()\n{...}\n</code></pre>\n\n<p>Regarding Enums, you might also want to take note of the highly interesting <a href="https://github.com/TylerBrinkley/Enums.NET" rel="nofollow noreferrer">Enums.NET</a>.</p>\n'}, {'answer_id': 47457596, 'author': 'uluorta', 'author_id': 785915, 'author_profile': 'https://Stackoverflow.com/users/785915', 'pm_score': 0, 'selected': False, 'text': "<p>If it's ok to use direct casting afterwards, I guess you can use the <code>System.Enum</code> base class in your method, wherever necessary. You just need to replace the type parameters carefully. So the method implementation would be like:</p>\n\n<pre><code>public static class EnumUtils\n{\n public static Enum GetEnumFromString(string value, Enum defaultValue)\n {\n if (string.IsNullOrEmpty(value)) return defaultValue;\n foreach (Enum item in Enum.GetValues(defaultValue.GetType()))\n {\n if (item.ToString().ToLower().Equals(value.Trim().ToLower())) return item;\n }\n return defaultValue;\n }\n}\n</code></pre>\n\n<p>Then you can use it like:</p>\n\n<pre><code>var parsedOutput = (YourEnum)EnumUtils.GetEnumFromString(someString, YourEnum.DefaultValue);\n</code></pre>\n"}, {'answer_id': 49432554, 'author': 'DiskJunky', 'author_id': 1838819, 'author_profile': 'https://Stackoverflow.com/users/1838819', 'pm_score': 5, 'selected': False, 'text': '<p>The existing answers are true as of C# &lt;=7.2. However, there is a C# language <a href="https://github.com/dotnet/csharplang/issues/104" rel="noreferrer">feature request</a> (tied to a <a href="https://github.com/dotnet/corefx/issues/15453" rel="noreferrer">corefx</a> feature request) to allow the following;</p>\n\n<pre><code>public class MyGeneric&lt;TEnum&gt; where TEnum : System.Enum\n{ }\n</code></pre>\n\n<p>At time of writing, the feature is "In discussion" at the Language Development Meetings.</p>\n\n<p><strong>EDIT</strong></p>\n\n<p>As per <a href="https://stackoverflow.com/users/661933/nawfal">nawfal</a>\'s info, this is being introduced in C# <a href="https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-Preview-relnotes#csharp" rel="noreferrer">7.3</a>.</p>\n\n<p><strong>EDIT 2</strong></p>\n\n<p>This is now in C# 7.3 forward (<a href="https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3" rel="noreferrer">release notes</a>)</p>\n\n<p>Sample;</p>\n\n<pre><code>public static Dictionary&lt;int, string&gt; EnumNamedValues&lt;T&gt;()\n where T : System.Enum\n{\n var result = new Dictionary&lt;int, string&gt;();\n var values = Enum.GetValues(typeof(T));\n\n foreach (int item in values)\n result.Add(item, Enum.GetName(typeof(T), item));\n return result;\n}\n</code></pre>\n'}, {'answer_id': 50270186, 'author': 'baumgarb', 'author_id': 4587483, 'author_profile': 'https://Stackoverflow.com/users/4587483', 'pm_score': 4, 'selected': False, 'text': '<p>It should also be considered that since the release of C# 7.3 using Enum constraints is supported out-of-the-box without having to do additional checking and stuff.</p>\n\n<p>So going forward and given you\'ve changed the language version of your project to C# 7.3 the following code is going to work perfectly fine:</p>\n\n<pre><code> private static T GetEnumFromString&lt;T&gt;(string value, T defaultValue) where T : Enum\n {\n // Your code goes here...\n }\n</code></pre>\n\n<p>In case you\'re don\'t know how to change the language version to C# 7.3 see the following screenshot:\n<a href="https://i.stack.imgur.com/GMWgy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GMWgy.png" alt="enter image description here"></a></p>\n\n<p><strong>EDIT 1 - Required Visual Studio Version and considering ReSharper</strong></p>\n\n<p>For Visual Studio to recognize the new syntax you need at least version 15.7. You can find that also mentioned in Microsoft\'s release notes, see <a href="https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes#whats-new-in-157" rel="noreferrer">Visual Studio 2017 15.7 Release Notes</a>. Thanks @MohamedElshawaf for pointing out this valid question.</p>\n\n<p>Pls also note that in my case ReSharper 2018.1 as of writing this EDIT does not yet support C# 7.3. Having ReSharper activated it highlights the Enum constraint as an error telling me <em>Cannot use \'System.Array\', \'System.Delegate\', \'System.Enum\', \'System.ValueType\', \'object\' as type parameter constraint</em>. \nReSharper suggests as a quick fix to <em>Remove \'Enum\' constraint of type paramter T of method</em> </p>\n\n<p>However, if you turn off ReSharper temporarily under <em>Tools -> Options -> ReSharper Ultimate -> General</em> you\'ll see that the syntax is perfectly fine given that you use VS 15.7 or higher and C# 7.3 or higher. </p>\n'}, {'answer_id': 50596283, 'author': 'Rodney P. Barbati', 'author_id': 1588303, 'author_profile': 'https://Stackoverflow.com/users/1588303', 'pm_score': -1, 'selected': False, 'text': '<p>Just for completeness, the following is a Java solution. I am certain the same could be done in C# as well. It avoids having to specify the type anywhere in code - instead, you specify it in the strings you are trying to parse.</p>\n\n<p>The problem is that there isn\'t any way to know which enumeration the String might match - so the answer is to solve that problem.</p>\n\n<p>Instead of accepting just the string value, accept a String that has both the enumeration and the value in the form "enumeration.value". Working code is below - requires Java 1.8 or later. This would also make the XML more precise as in you would see something like color="Color.red" instead of just color="red".</p>\n\n<p>You would call the acceptEnumeratedValue() method with a string containing the enum name dot value name. </p>\n\n<p>The method returns the formal enumerated value.</p>\n\n<pre><code>import java.util.HashMap;\nimport java.util.Map;\nimport java.util.function.Function;\n\n\npublic class EnumFromString {\n\n enum NumberEnum {One, Two, Three};\n enum LetterEnum {A, B, C};\n\n\n Map&lt;String, Function&lt;String, ? extends Enum&gt;&gt; enumsByName = new HashMap&lt;&gt;();\n\n public static void main(String[] args) {\n EnumFromString efs = new EnumFromString();\n\n System.out.print("\\nFirst string is NumberEnum.Two - enum is " + efs.acceptEnumeratedValue("NumberEnum.Two").name());\n System.out.print("\\nSecond string is LetterEnum.B - enum is " + efs.acceptEnumeratedValue("LetterEnum.B").name());\n\n }\n\n public EnumFromString() {\n enumsByName.put("NumberEnum", s -&gt; {return NumberEnum.valueOf(s);});\n enumsByName.put("LetterEnum", s -&gt; {return LetterEnum.valueOf(s);});\n }\n\n public Enum acceptEnumeratedValue(String enumDotValue) {\n\n int pos = enumDotValue.indexOf(".");\n\n String enumName = enumDotValue.substring(0, pos);\n String value = enumDotValue.substring(pos + 1);\n\n Enum enumeratedValue = enumsByName.get(enumName).apply(value);\n\n return enumeratedValue;\n }\n\n\n}\n</code></pre>\n'}, {'answer_id': 58731308, 'author': 'Cubelaster', 'author_id': 1562834, 'author_profile': 'https://Stackoverflow.com/users/1562834', 'pm_score': 1, 'selected': False, 'text': '<p>This is my implementation. Basically, you can setup any attribute and it works. </p>\n\n<pre><code>public static class EnumExtensions\n {\n public static string GetDescription(this Enum @enum)\n {\n Type type = @enum.GetType();\n FieldInfo fi = type.GetField(@enum.ToString());\n DescriptionAttribute[] attrs =\n fi.GetCustomAttributes(typeof(DescriptionAttribute), false) as DescriptionAttribute[];\n if (attrs.Length &gt; 0)\n {\n return attrs[0].Description;\n }\n return null;\n }\n }\n</code></pre>\n'}, {'answer_id': 69573641, 'author': 'Chris F Carroll', 'author_id': 550314, 'author_profile': 'https://Stackoverflow.com/users/550314', 'pm_score': 3, 'selected': False, 'text': "<p>note that <code>System.Enum</code> <code>Parse()</code> &amp; <code>TryParse()</code> methods still have <code>where struct</code> constraints rather than <code>where Enum</code>, so that this won't compile:</p>\n<pre><code> bool IsValid&lt;TE&gt;(string attempted) where TE : Enum\n {\n return Enum.TryParse(attempted, out TE _);\n }\n</code></pre>\n<p>but this will:</p>\n<pre><code>bool Ok&lt;TE&gt;(string attempted) where TE : struct,Enum\n{\n return Enum.TryParse(attempted, out var _)\n}\n</code></pre>\n<p>as a result, <code>where struct,Enum</code> may be preferable to just <code>where Enum</code></p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79126', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5302/']
79,129
<p>For the life of me, I cannot get the SqlProfileProvider to work in an MVC project that I'm working on.</p> <p>The first interesting thing that I realized is that Visual Studio does not automatically generate the ProfileCommon proxy class for you. That's not a big deal since it's simpy a matter of extending the ProfileBase class. After creating a ProfileCommon class, I wrote the following Action method for creating the user profile.</p> <pre><code>[AcceptVerbs("POST")] public ActionResult CreateProfile(string company, string phone, string fax, string city, string state, string zip) { MembershipUser user = Membership.GetUser(); ProfileCommon profile = ProfileCommon.Create(user.UserName, user.IsApproved) as ProfileCommon; profile.Company = company; profile.Phone = phone; profile.Fax = fax; profile.City = city; profile.State = state; profile.Zip = zip; profile.Save(); return RedirectToAction("Index", "Account"); }</code></pre> <p>The problem that I'm having is that the call to ProfileCommon.Create() cannot cast to type ProfileCommon, so I'm not able to get back my profile object, which obviously causes the next line to fail since profile is null.</p> <p>Following is a snippet of my web.config:</p> <p><pre><code>&lt;profile defaultProvider="AspNetSqlProfileProvider" automaticSaveEnabled="false" enabled="true"&gt; &lt;providers&gt; &lt;clear/&gt; &lt;add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="/" /&gt; &lt;/providers&gt; &lt;properties&gt; &lt;add name="FirstName" type="string" /&gt; &lt;add name="LastName" type="string" /&gt; &lt;add name="Company" type="string" /&gt; &lt;add name="Phone" type="string" /&gt; &lt;add name="Fax" type="string" /&gt; &lt;add name="City" type="string" /&gt; &lt;add name="State" type="string" /&gt; &lt;add name="Zip" type="string" /&gt; &lt;add name="Email" type="string" &gt; &lt;/properties&gt; &lt;/profile&gt;</pre></code></p> <p>The MembershipProvider is working without a hitch, so I know that the connection string is good.</p> <p>Just in case it's helpful, here is my ProfileCommon class:</p> <pre><code>public class ProfileCommon : ProfileBase { public virtual string Company { get { return ((string)(this.GetPropertyValue("Company"))); } set { this.SetPropertyValue("Company", value); } } public virtual string Phone { get { return ((string)(this.GetPropertyValue("Phone"))); } set { this.SetPropertyValue("Phone", value); } } public virtual string Fax { get { return ((string)(this.GetPropertyValue("Fax"))); } set { this.SetPropertyValue("Fax", value); } } public virtual string City { get { return ((string)(this.GetPropertyValue("City"))); } set { this.SetPropertyValue("City", value); } } public virtual string State { get { return ((string)(this.GetPropertyValue("State"))); } set { this.SetPropertyValue("State", value); } } public virtual string Zip { get { return ((string)(this.GetPropertyValue("Zip"))); } set { this.SetPropertyValue("Zip", value); } } public virtual ProfileCommon GetProfile(string username) { return ((ProfileCommon)(ProfileBase.Create(username))); } }</code></pre> <p>Any thoughts on what I might be doing wrong? Have any of the rest of you successfully integrated a ProfileProvider with your ASP.NET MVC projects?</p> <p>Thank you in advance...</p>
[{'answer_id': 80594, 'author': 'Mladen Mihajlovic', 'author_id': 11421, 'author_profile': 'https://Stackoverflow.com/users/11421', 'pm_score': 3, 'selected': False, 'text': "<p>Not sure about the whole question, but one thing I noticed in your code:</p>\n\n<pre><code>ProfileCommon profile = (ProfileCommon)ProfileCommon.Create(user.UserName, user.IsApproved) as ProfileCommon;\n</code></pre>\n\n<p>You do not need both the (ProfileCommon) and the as ProfileCommon. They both do casts, but the () throws and exception while the as returns a null if the cast can't be made.</p>\n"}, {'answer_id': 93963, 'author': 'Dave Dunkin', 'author_id': 453303, 'author_profile': 'https://Stackoverflow.com/users/453303', 'pm_score': 3, 'selected': False, 'text': '<p>Try <a href="http://code.msdn.microsoft.com/WebProfileBuilder" rel="nofollow noreferrer">Web Profile Builder</a>. It\'s a build script that automagically generates a WebProfile class (equivalent to ProfileCommon) from web.config.</p>\n'}, {'answer_id': 260926, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>The web.config file in the MVC Beta is wrong. The SqlProfileProvider is in System.Web.Profile, not System.Web.Security. Change this, and it should start working for you.</p>\n'}, {'answer_id': 434793, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 7, 'selected': True, 'text': '<p>Here\'s what you need to do:</p>\n\n<p>1) In Web.config\'s section, add "inherits" attribute in addition to your other attribute settings:</p>\n\n<pre><code>&lt;profile inherits="MySite.Models.ProfileCommon" defaultProvider="....\n</code></pre>\n\n<p>2) Remove entire <code>&lt;properties&gt;</code> section from Web.config, since you have already defined them in your custom ProfileCommon class and also instructed to inherit from your custom class in previous step</p>\n\n<p>3) Change the code of your ProfileCommon.GetProfile() method to </p>\n\n<pre><code>public virtual ProfileCommon GetProfile(string username) \n{ \n return Create(username) as ProfileCommon; \n}\n</code></pre>\n\n<p>Hope this helps.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79129', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10792/']
79,133
<p>In other words:</p> <ol> <li>Log on as Bert (who is an administrator)</li> <li>Using fast user switching, log on as Ernie (Bert remains logged on)</li> <li>Switch back to Bert</li> <li>Bert logs Ernie off</li> </ol> <p>What is the best way to achieve step 4?</p>
[{'answer_id': 79280, 'author': 'andrewdotnich', 'author_id': 10569, 'author_profile': 'https://Stackoverflow.com/users/10569', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://macosx.com/tech-support/mac/force-shutdown-logoff-restart-via-applescript/25909.html" rel="nofollow noreferrer">This forum post</a> has a bash script for OSX that should do the trick. It takes a username as an argument and logs off that user.</p>\n\n<p>I\'ve not tried it, so your mileage may vary. But it looks like it suits your needs.\nWhat exactly are you trying to achieve?</p>\n'}, {'answer_id': 42917620, 'author': 'Babak', 'author_id': 4676, 'author_profile': 'https://Stackoverflow.com/users/4676', 'pm_score': 3, 'selected': True, 'text': "<p><code>sudo launchctl bootout user/$(id -u &lt;username&gt;)</code></p>\n\n<p>Replace <code>&lt;username&gt;</code> with the target user's user name.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79133', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4676/']
79,136
<p>I would like to create a file format for my app like Quake, OO, and MS Office 07 have.</p> <p>Basically a uncompressed zip folder, or tar file.</p> <p>I need this to be cross platform (mac and windows).</p> <p>Can I do something via command prompt and bash?</p>
[{'answer_id': 79146, 'author': 'André Chalella', 'author_id': 4850, 'author_profile': 'https://Stackoverflow.com/users/4850', 'pm_score': 2, 'selected': False, 'text': '<p>Zip is supported everywhere. If a container is all you need, than those are surely good options.</p>\n'}, {'answer_id': 79152, 'author': 'Ash', 'author_id': 5023, 'author_profile': 'https://Stackoverflow.com/users/5023', 'pm_score': 3, 'selected': True, 'text': '<p>Have a look at the open source <a href="http://www.7-zip.org/" rel="nofollow noreferrer">7Zip</a> compression format. For your specific needs, you can use it in an "Archive" mode, zero compression but very fast.</p>\n\n<p>It provides a powerful SDK, LZMA, from the site:</p>\n\n<p>"LZMA is the default and general compression method of 7z format in the 7-Zip program. LZMA provides a high compression ratio and very fast decompression, so it is very suitable for embedded applications. For example, it can be used for ROM (firmware) compressing.</p>\n\n<p>The LZMA SDK provides the documentation, samples, header files, libraries, and tools you need to develop applications that use LZMA compression."</p>\n'}, {'answer_id': 79159, 'author': 'Bryan Oakley', 'author_id': 7432, 'author_profile': 'https://Stackoverflow.com/users/7432', 'pm_score': 2, 'selected': False, 'text': '<p>If you want a single file that is portable to all platforms and which contain structured data, consider using sqlite. You\'ll get a full featured ACID compliant database that exists on disk as a single file.</p>\n\n<p>There are libraries you can link against to directly access the file, and there is a command line tool you can use as well. No matter what language you are using, most likely there is support for it.</p>\n\n<p><a href="http://www.sqlite.org" rel="nofollow noreferrer">http://www.sqlite.org</a></p>\n'}, {'answer_id': 79172, 'author': 'shea241', 'author_id': 14656, 'author_profile': 'https://Stackoverflow.com/users/14656', 'pm_score': 0, 'selected': False, 'text': '<p>First thing you should ask yourself is, "Do I really need to make my own?"</p>\n\n<p>Depending on what you want to use it for, you are probably better off using a common format and some pre-made libraries which already handle one of those formats very well.</p>\n\n<p>Good places to start:\n<a href="http://www.destructor.de/libtar/index.htm" rel="nofollow noreferrer">http://www.destructor.de/libtar/index.htm</a> (tar -- a the \'container\' format)\n<a href="http://www.zlib.net/" rel="nofollow noreferrer">http://www.zlib.net/</a> (zlib -- a method of compressing data before or after you put it in the container)</p>\n\n<p>If you still really think you need to make your own, I would suggest studying something very simple first, like tar\'s format:</p>\n\n<p><a href="http://en.wikipedia.org/wiki/Tar_(file_format)" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Tar_(file_format)</a>\nor\n<a href="http://schmidt.devlib.org/file-formats/tar-archive-file-format.html" rel="nofollow noreferrer">http://schmidt.devlib.org/file-formats/tar-archive-file-format.html</a></p>\n'}, {'answer_id': 79206, 'author': 'Javier', 'author_id': 11649, 'author_profile': 'https://Stackoverflow.com/users/11649', 'pm_score': 1, 'selected': False, 'text': '<p>SQLite is great.</p>\n\n<p>A single file, crossplatform, a tiny library, SQL access to data, transactions, the whole enchilada.</p>\n\n<p>you can use transactions to guarantee consistent return points in case of crashing. check <a href="http://sqlite.org/whentouse.html" rel="nofollow noreferrer">uses for sqlite</a>, they specifically advocate using it as a data model layer for desktop applications.</p>\n\n<p>also, there\'s a command-line tool to manually access the data.</p>\n'}, {'answer_id': 87787, 'author': 'Brian Mitchell', 'author_id': 13716, 'author_profile': 'https://Stackoverflow.com/users/13716', 'pm_score': 0, 'selected': False, 'text': "<p>Instead of making a format, I'd just decide on a convention. One or more named files within the container have the metadata you need to access the rest of the files, and know what to do with them. The container itself, though, should just be some ubiquitous format, such as zip. No need to reinvent the wheel, here.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79136', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10472/']
79,165
<p>I read the Git manual, FAQ, Git - SVN crash course, etc. and they all explain this and that, but nowhere can you find a simple instruction like:</p> <p>SVN repository in: <code>svn://myserver/path/to/svn/repos</code></p> <p>Git repository in: <code>git://myserver/path/to/git/repos</code></p> <pre><code>git-do-the-magic-svn-import-with-history \ svn://myserver/path/to/svn/repos \ git://myserver/path/to/git/repos </code></pre> <p>I don't expect it to be that simple, and I don't expect it to be a single command. But I do expect it not to try to explain anything - just to say what steps to take given this example.</p>
[{'answer_id': 79178, 'author': 'jfm3', 'author_id': 11138, 'author_profile': 'https://Stackoverflow.com/users/11138', 'pm_score': 10, 'selected': True, 'text': '<p>Magic:</p>\n\n<pre><code>$ git svn clone http://svn/repo/here/trunk\n</code></pre>\n\n<p>Git and SVN operate very differently. You need to learn Git, and if you want to track changes from SVN upstream, you need to learn <code>git-svn</code>. The <code>git-svn</code> <a href="https://git-scm.com/docs/git-svn" rel="noreferrer">main page has a good examples section</a>:</p>\n\n<pre><code>$ git svn --help\n</code></pre>\n'}, {'answer_id': 79188, 'author': 'Eugene Yokota', 'author_id': 3827, 'author_profile': 'https://Stackoverflow.com/users/3827', 'pm_score': 8, 'selected': False, 'text': '<p><a href="https://web.archive.org/web/20160314221641/https://jonmaddox.com/2008/03/05/cleanly-migrate-your-subversion-repository-to-a-git-repository/" rel="noreferrer">Cleanly Migrate Your Subversion Repository To a Git Repository</a>. First you have to create a file that maps your Subversion commit author names to Git commiters, say <code>~/authors.txt</code>:</p>\n\n<pre><code>jmaddox = Jon Maddox &lt;[email protected]&gt;\nbigpappa = Brian Biggs &lt;[email protected]&gt;\n</code></pre>\n\n<p>Then you can download the Subversion data into a Git repository:</p>\n\n<pre><code>mkdir repo &amp;&amp; cd repo\ngit svn init http://subversion/repo --no-metadata\ngit config svn.authorsfile ~/authors.txt\ngit svn fetch\n</code></pre>\n\n<p>If you’re on a Mac, you can get <code>git-svn</code> from MacPorts by installing <code>git-core +svn</code>.</p>\n\n<p>If your subversion repository is on the same machine as your desired git repository,\nthen you can use this syntax for the init step, otherwise all the same:</p>\n\n<pre><code>git svn init file:///home/user/repoName --no-metadata\n</code></pre>\n'}, {'answer_id': 85456, 'author': 'EfForEffort', 'author_id': 14113, 'author_profile': 'https://Stackoverflow.com/users/14113', 'pm_score': 4, 'selected': False, 'text': '<p>See the official <a href="http://git-scm.com/docs/git-svn" rel="noreferrer">git-svn manpage</a>. In particular, look under "Basic Examples":</p>\n\n<blockquote>\n <p>Tracking and contributing to an entire Subversion-managed project (complete\n with a trunk, tags and branches):</p>\n</blockquote>\n\n<pre><code># Clone a repo (like git clone):\n git svn clone http://svn.foo.org/project -T trunk -b branches -t tags\n</code></pre>\n'}, {'answer_id': 86094, 'author': 'webmat', 'author_id': 6349, 'author_profile': 'https://Stackoverflow.com/users/6349', 'pm_score': 6, 'selected': False, 'text': '<p>I suggest getting comfortable with Git before trying to use git-svn constantly, i.e. keeping SVN as the centralized repo and using Git locally.</p>\n<p>However, for a simple migration with all the history, here are the few simple steps:</p>\n<p>Initialize the local repo:</p>\n<pre><code>mkdir project\ncd project\ngit svn init http://svn.url\n</code></pre>\n<p>Mark how far back you want to start importing revisions:</p>\n<pre><code>git svn fetch -r42\n</code></pre>\n<p>(or just &quot;git svn fetch&quot; for all revs)</p>\n<p>Actually, fetch everything since then:</p>\n<pre><code>git svn rebase\n</code></pre>\n<p>You can check the result of the import with Gitk. I\'m not sure if this works on Windows, it works on OSX and Linux:</p>\n<pre><code>gitk\n</code></pre>\n<p>When you\'ve got your SVN repo cloned locally, you may want to push it to a centralized Git repo for easier collaboration.</p>\n<p>First create your empty remote repo (maybe on <a href="http://github.com" rel="nofollow noreferrer">GitHub</a>?):</p>\n<pre><code>git remote add origin [email protected]:user/project-name.git\n</code></pre>\n<p>Then, optionally sync your main branch so the pull operation will automatically merge the remote master with your local master when both contain new stuff:</p>\n<pre><code>git config branch.master.remote origin\ngit config branch.master.merge refs/heads/master\n</code></pre>\n<p>After that, you may be interested in trying out my very own <code>git_remote_branch</code> tool, which helps to deal with remote branches:</p>\n<p>First explanatory post: &quot;<a href="http://programblings.com/2008/06/23/git-remote-branches/" rel="nofollow noreferrer">Git remote branches</a>&quot;</p>\n<p>Follow-up for the most recent version: &quot;<a href="http://programblings.com/2008/08/06/time-to-git-collaborating-with-git_remote_branch/" rel="nofollow noreferrer">Time to git collaborating with git_remote_branch</a>&quot;</p>\n'}, {'answer_id': 110020, 'author': 'webmat', 'author_id': 6349, 'author_profile': 'https://Stackoverflow.com/users/6349', 'pm_score': 3, 'selected': False, 'text': '<p>GitHub now has a feature to <a href="http://github.com/blog/156-subversion-importing" rel="noreferrer">import from an SVN repository</a>. I never tried it, though.</p>\n'}, {'answer_id': 139428, 'author': 'Gregg Lind', 'author_id': 15842, 'author_profile': 'https://Stackoverflow.com/users/15842', 'pm_score': 2, 'selected': False, 'text': '<p>As another aside, the git-stash command is a godsend when trying to git with git-svn dcommits.</p>\n\n<p>A typical process:</p>\n\n<ol>\n<li>set up git repo</li>\n<li>do some work on different files</li>\n<li>decide to check some of the work in, using git</li>\n<li>decide to <code>svn-dcommit</code></li>\n<li>get the dreaded "cannot commit with a dirty index" error. </li>\n</ol>\n\n<p>The solution (requires git 1.5.3+): </p>\n\n<pre><code>git stash; git svn dcommit ; git stash apply\n</code></pre>\n'}, {'answer_id': 3787897, 'author': 'burkestar', 'author_id': 391678, 'author_profile': 'https://Stackoverflow.com/users/391678', 'pm_score': 0, 'selected': False, 'text': '<p><em><a href="http://www.viget.com/extend/effectively-using-git-with-subversion/" rel="nofollow">Effectively using Git with Subversion</a></em> is a gentle introduction to git-svn. For existing SVN repositories, git-svn makes this super easy. If you\'re starting a new repository, it\'s vastly easier to first create an empty SVN repository and then import using git-svn than it is going in the opposite direction. Creating a new Git repository then importing into SVN can be done, but it is a bit painful, especially if you\'re new to Git and hope to preserve the commit history.</p>\n'}, {'answer_id': 3972103, 'author': 'cmcginty', 'author_id': 64313, 'author_profile': 'https://Stackoverflow.com/users/64313', 'pm_score': 11, 'selected': False, 'text': '<p>Create a users file (i.e. <code>users.txt</code>) for mapping SVN users to Git:</p>\n<pre><code>user1 = First Last Name &lt;[email protected]&gt;\nuser2 = First Last Name &lt;[email protected]&gt;\n...\n</code></pre>\n<p>You can use this one-liner to build a template from your existing SVN repository:</p>\n<pre><code>svn log -q | awk -F \'|\' \'/^r/ {gsub(/ /, &quot;&quot;, $2); sub(&quot; $&quot;, &quot;&quot;, $2); print $2&quot; = &quot;$2&quot; &lt;&quot;$2&quot;&gt;&quot;}\' | sort -u &gt; users.txt\n</code></pre>\n<p>SVN will stop if it finds a missing SVN user, not in the file. But after that, you can update the file and pick up where you left off.</p>\n<p>Now pull the SVN data from the repository:</p>\n<pre><code>git svn clone --stdlayout --no-metadata --authors-file=users.txt svn://hostname/path dest_dir-tmp\n</code></pre>\n<p>This command will create a new Git repository in <code>dest_dir-tmp</code> and start pulling the SVN repository. Note that the &quot;--stdlayout&quot; flag implies you have the common &quot;trunk/, branches/, tags/&quot; SVN layout. If your layout differs, become familiar with <code>--tags</code>, <code>--branches</code>, <code>--trunk</code> options (in general <code>git svn help</code>).</p>\n<p>All common protocols are allowed: <code>svn://</code>, <code>http://</code>, <code>https://</code>. The URL should target the base repository, something like <a href="http://svn.mycompany.com/myrepo/repository" rel="noreferrer">http://svn.mycompany.com/myrepo/repository</a>. The URL string must <strong>not</strong> include <code>/trunk</code>, <code>/tag</code> or <code>/branches</code>.</p>\n<p>Note that after executing this command it very often looks like the operation is &quot;hanging/frozen&quot;, and it\'s quite normal that it can be stuck for a long time after initializing the new repository. Eventually, you will then see log messages which indicate that it\'s migrating.</p>\n<p>Also note that if you omit the <code>--no-metadata</code> flag, Git will append information about the corresponding SVN revision to the commit message (i.e. <code>git-svn-id: svn://svn.mycompany.com/myrepo/&lt;branchname/trunk&gt;@&lt;RevisionNumber&gt; &lt;Repository UUID&gt;</code>)</p>\n<p>If a user name is not found, update your <code>users.txt</code> file then:</p>\n<pre><code>cd dest_dir-tmp\ngit svn fetch\n</code></pre>\n<p>You might have to repeat that last command several times, if you have a large project until all of the Subversion commits have been fetched:</p>\n<pre><code>git svn fetch\n</code></pre>\n<p>When completed, Git will checkout the SVN <code>trunk</code> into a new branch. Any other branches are set up as remotes. You can view the other SVN branches with:</p>\n<pre><code>git branch -r\n</code></pre>\n<p>If you want to keep other remote branches in your repository, you want to create a local branch for each one manually. (Skip trunk/master.) If you don\'t do this, the branches won\'t get cloned in the final step.</p>\n<pre><code>git checkout -b local_branch remote_branch\n# It\'s OK if local_branch and remote_branch are the same names\n</code></pre>\n<p>Tags are imported as branches. You have to create a local branch, make a tag and delete the branch to have them as tags in Git. To do it with tag &quot;v1&quot;:</p>\n<pre><code>git checkout -b tag_v1 remotes/tags/v1\ngit checkout master\ngit tag v1 tag_v1\ngit branch -D tag_v1\n</code></pre>\n<p>Clone your GIT-SVN repository into a clean Git repository:</p>\n<pre><code>git clone dest_dir-tmp dest_dir\nrm -rf dest_dir-tmp\ncd dest_dir\n</code></pre>\n<p>The local branches that you created earlier from remote branches will only have been copied as remote branches into the newly cloned repository. (Skip trunk/master.) For each branch you want to keep:</p>\n<pre><code>git checkout -b local_branch origin/remote_branch\n</code></pre>\n<p>Finally, remove the remote from your clean Git repository that points to the now-deleted temporary repository:</p>\n<pre><code>git remote rm origin\n</code></pre>\n'}, {'answer_id': 4860157, 'author': 'Thiago Leão Moreira', 'author_id': 141639, 'author_profile': 'https://Stackoverflow.com/users/141639', 'pm_score': 6, 'selected': False, 'text': '<p>I used the <a href="https://github.com/nirvdrum/svn2git" rel="noreferrer">svn2git script</a> and works like a charm.</p>\n'}, {'answer_id': 4974152, 'author': 'kdahlhaus', 'author_id': 164133, 'author_profile': 'https://Stackoverflow.com/users/164133', 'pm_score': 4, 'selected': False, 'text': '<p>Pro Git 8.2 explains it:\n<a href="http://git-scm.com/book/en/Git-and-Other-Systems-Migrating-to-Git" rel="noreferrer">http://git-scm.com/book/en/Git-and-Other-Systems-Migrating-to-Git</a></p>\n'}, {'answer_id': 5385391, 'author': 'ripper234', 'author_id': 11236, 'author_profile': 'https://Stackoverflow.com/users/11236', 'pm_score': 2, 'selected': False, 'text': '<p>I highly recommend this <a href="http://www.tfnico.com/presentations/git-and-subversion" rel="nofollow">short series of screencasts</a> I just discovered. The author walks you through the basic operations, and showcases some more advanced usages.</p>\n'}, {'answer_id': 8262076, 'author': 'Alexander Kitaev', 'author_id': 351457, 'author_profile': 'https://Stackoverflow.com/users/351457', 'pm_score': 5, 'selected': False, 'text': '<p>There is a new solution for smooth migration from Subversion to Git (or for using both simultaneously): <a href="http://subgit.com/" rel="nofollow noreferrer">SubGit</a>. </p>\n\n<p>I\'m working on this project myself. We use SubGit in our repositories - some of my teammates use Git and some Subversion and so far it works very well.</p>\n\n<p>To migrate from Subversion to Git with SubGit you need to run:</p>\n\n<pre><code>$ subgit install svn_repos\n...\nTRANSLATION SUCCESSFUL \n</code></pre>\n\n<p>After that you\'ll get Git repository in svn_repos/.git and may clone it, or just continue to use Subversion and this new Git repository together: SubGit will make sure that both are always kept in sync. </p>\n\n<p>In case your Subversion repository contains multiple projects, then multiple Git repositories will be created in svn_repos/git directory. To customize translation before running it do the following:</p>\n\n<pre><code>$ subgit configure svn_repos\n$ edit svn_repos/conf/subgit.conf (change mapping, add authors mapping, etc)\n$ subgit install svn_repos\n</code></pre>\n\n<p>With <a href="http://subgit.com/" rel="nofollow noreferrer">SubGit</a> you may migrate to pure Git (not git-svn) and start using it while still keeping Subversion as long as you need it (for your already configured build tools, for instance).</p>\n\n<p>Hope this helps!</p>\n'}, {'answer_id': 9316931, 'author': 'Jason Huntley', 'author_id': 1214542, 'author_profile': 'https://Stackoverflow.com/users/1214542', 'pm_score': 2, 'selected': False, 'text': '<p>I just wanted to add my contribution to the Git community. I wrote a simple bash script which automates the full import. Unlike other migration tools, this tool relies on native git instead of jGit. This tool also supports repositories with a large revision history and or large blobs. It\'s available via github:</p>\n\n<p><a href="https://github.com/onepremise/SGMS" rel="nofollow">https://github.com/onepremise/SGMS</a></p>\n\n<p>This script will convert projects stored in SVN with the following format:</p>\n\n<pre><code>/trunk\n /Project1\n /Project2\n/branches\n /Project1\n /Project2\n/tags\n /Project1\n /Project2\n</code></pre>\n\n<p>This scheme is also popular and supported as well:</p>\n\n<pre><code>/Project1\n /trunk\n /branches\n /tags\n/Project2\n /trunk\n /branches\n /tags\n</code></pre>\n\n<p>Each project will get synchronized over by project name:</p>\n\n<pre><code>Ex: ./migration https://svnurl.com/basepath project1\n</code></pre>\n\n<p>If you wish to convert the full repo over, use the following syntax:</p>\n\n<pre><code>Ex: ./migration https://svnurl.com/basepath .\n</code></pre>\n'}, {'answer_id': 16074080, 'author': 'CAD bloke', 'author_id': 492, 'author_profile': 'https://Stackoverflow.com/users/492', 'pm_score': 3, 'selected': False, 'text': '<p>TortoiseGit does this. see this blog post: <a href="http://jimmykeen.net/articles/03-nov-2012/how-migrate-from-svn-to-git-windows-using-tortoise-clients" rel="noreferrer">http://jimmykeen.net/articles/03-nov-2012/how-migrate-from-svn-to-git-windows-using-tortoise-clients</a></p>\n\n<p>Yeah, I know answering with links isn\'t splendid but it\'s a solution, eh?</p>\n'}, {'answer_id': 19001024, 'author': 'thoutbeckers', 'author_id': 2338613, 'author_profile': 'https://Stackoverflow.com/users/2338613', 'pm_score': 3, 'selected': False, 'text': '<p>A somewhat extended answer using just git, SVN, and bash. It includes steps for SVN repositories that do not use the conventional layout with a trunk/branches/tags directory layout (SVN does absolutely nothing to enforce this kind of layout).</p>\n\n<p>First use this bash script to scan your SVN repo for the different people who contributed and to generate a template for a mapping file:</p>\n\n<pre><code>#!/usr/bin/env bash\nauthors=$(svn log -q | grep -e \'^r\' | awk \'BEGIN { FS = "|" } ; { print $2 }\' | sort | uniq)\nfor author in ${authors}; do\n echo "${author} = NAME &lt;USER@DOMAIN&gt;";\ndone\n</code></pre>\n\n<p>Use this to create an <code>authors</code> file where you map svn usernames to usernames and email as set by your developers using <a href="https://www.kernel.org/pub/software/scm/git/docs/git-config.html" rel="nofollow"><code>git config</code></a> properties <code>user.name</code> and <code>user.email</code> (note that for a service like GitHub only having a matching email is enough).</p>\n\n<p>Then have <a href="https://www.kernel.org/pub/software/scm/git/docs/git-svn.html" rel="nofollow"><code>git svn</code></a> clone the svn repository to a git repository, telling it about the mapping:</p>\n\n<p><code>git svn clone --authors-file=authors --stdlayout svn://example.org/Folder/projectroot</code></p>\n\n<p>This can take incredibly long, since git svn will individually check out every revision for every tag or branch that exists. (note that tags in SVN are just really branches, so they end up as such in Git). You can speed this up by removing old tags and branches in SVN you don\'t need. </p>\n\n<p>Running this on a server in the same network or on the same server can also really speed this up. Also, if for some reason this process gets interrupted you <em>can</em> resume it using</p>\n\n<p><code>git svn rebase --continue</code></p>\n\n<p>In a lot of cases you\'re done here. But if your SVN repo has an unconventional layout where you simply have a directory in SVN you want to put in a git branch you can do some extra steps.</p>\n\n<p>The simplest is to just make a new SVN repo on your server that does follow convention and use <code>svn copy</code> to put your directory in trunk or a branch. This might be the only way if your directory is all the way at the root of the repo, when I last tried this <code>git svn</code> simply refused to do a checkout.</p>\n\n<p>You can also do this using git. For <code>git svn clone</code> simply use the directory you want to to put in a git branch.</p>\n\n<p>After run</p>\n\n<pre><code>git branch --set-upstream master git-svn\ngit svn rebase\n</code></pre>\n\n<p>Note that this required Git 1.7 or higher.</p>\n'}, {'answer_id': 19814186, 'author': 'NateS', 'author_id': 187883, 'author_profile': 'https://Stackoverflow.com/users/187883', 'pm_score': 2, 'selected': False, 'text': '<p>Here is a simple shell script with no dependencies that will convert one or more SVN repositories to git and push them to GitHub.</p>\n\n<p><a href="https://gist.github.com/NathanSweet/7327535" rel="nofollow">https://gist.github.com/NathanSweet/7327535</a></p>\n\n<p>In about 30 lines of script it: clones using git SVN, creates a .gitignore file from SVN::ignore properties, pushes into a bare git repository, renames SVN trunk to master, converts SVN tags to git tags, and pushes it to GitHub while preserving the tags.</p>\n\n<p>I went thru a lot of pain to move a dozen SVN repositories from Google Code to GitHub. It didn\'t help that I used Windows. Ruby was all kinds of broken on my old Debian box and getting it working on Windows was a joke. Other solutions failed to work with Cygwin paths. Even once I got something working, I couldn\'t figure out how to get the tags to show up on GitHub (the secret is --follow-tags).</p>\n\n<p>In the end I cobbled together two short and simple scripts, linked above, and it works great. The solution does not need to be any more complicated than that!</p>\n'}, {'answer_id': 22380906, 'author': 'Andrew B', 'author_id': 329028, 'author_profile': 'https://Stackoverflow.com/users/329028', 'pm_score': 3, 'selected': False, 'text': '<p>This guide on atlassian\'s website is one of the best I have found:</p>\n\n<p><a href="https://www.atlassian.com/git/migration" rel="noreferrer">https://www.atlassian.com/git/migration</a></p>\n\n<p>This tool - <a href="https://bitbucket.org/atlassian/svn-migration-scripts" rel="noreferrer">https://bitbucket.org/atlassian/svn-migration-scripts</a> - is also really useful for generating your authors.txt among other things.</p>\n'}, {'answer_id': 24255861, 'author': 'Craig Myles', 'author_id': 373406, 'author_profile': 'https://Stackoverflow.com/users/373406', 'pm_score': 2, 'selected': False, 'text': '<p>If you are using SourceTree you can do this directly from the app. Goto File -> New/Clone then do the following: </p>\n\n<ol>\n<li>Enter the remote SVN URL as the "Source Path / URL".</li>\n<li>Enter your credentials when prompted.</li>\n<li>Enter the local folder location as the "Destination path". </li>\n<li>Give it a name. </li>\n<li>In the advanced options select "Git" from the dropdown in "Create local\nrepository of type".</li>\n<li>You can optionally specify a revision to clone from.</li>\n<li>Hit Clone.</li>\n</ol>\n\n<p>Open the repo in SourceTree and you\'ll see your commit messages have been migrated too.</p>\n\n<p>Now go to Repository -> Repository Settings and add the new remote repo details. Delete the SVN remote if you wish (I did this through the "Edit Config File" option.</p>\n\n<p>Push the code to the new remote repo when you are ready and code freely.</p>\n'}, {'answer_id': 24879012, 'author': 'Valarpirai', 'author_id': 3863121, 'author_profile': 'https://Stackoverflow.com/users/3863121', 'pm_score': 3, 'selected': False, 'text': '<p>You have to Install</p>\n\n<pre><code>git\ngit-svn\n</code></pre>\n\n<p>Copied from this link <a href="http://john.albin.net/git/convert-subversion-to-git" rel="noreferrer">http://john.albin.net/git/convert-subversion-to-git</a>.</p>\n\n<p><strong>1. Retrieve a list of all Subversion committers</strong></p>\n\n<p>Subversion simply lists the username for each commit. Git’s commits have much richer data, but at its simplest, the commit author needs to have a name and email listed. By default the git-svn tool will just list the SVN username in both the author and email fields. But with a little bit of work, you can create a list of all SVN users and what their corresponding Git name and emails are. This list can be used by git-svn to transform plain svn usernames into proper Git committers.</p>\n\n<p>From the root of your local Subversion checkout, run this command:</p>\n\n<pre><code>svn log -q | awk -F \'|\' \'/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" &lt;"$2"&gt;"}\' | sort -u &gt; authors-transform.txt\n</code></pre>\n\n<p>That will grab all the log messages, pluck out the usernames, eliminate any duplicate usernames, sort the usernames and place them into a “authors-transform.txt” file. Now edit each line in the file. For example, convert:</p>\n\n<pre><code>jwilkins = jwilkins &lt;jwilkins&gt;\n</code></pre>\n\n<p>into this:</p>\n\n<pre><code>jwilkins = John Albin Wilkins &lt;[email protected]&gt;\n</code></pre>\n\n<p><strong>2. Clone the Subversion repository using git-svn</strong></p>\n\n<pre><code>git svn clone [SVN repo URL] --no-metadata -A authors-transform.txt --stdlayout ~/temp\n</code></pre>\n\n<p>This will do the standard git-svn transformation (using the authors-transform.txt file you created in step 1) and place the git repository in the “~/temp” folder inside your home directory.</p>\n\n<p><strong>3. Convert svn:ignore properties to .gitignore</strong></p>\n\n<p>If your svn repo was using svn:ignore properties, you can easily convert this to a .gitignore file using:</p>\n\n<pre><code>cd ~/temp\ngit svn show-ignore &gt; .gitignore\ngit add .gitignore\ngit commit -m \'Convert svn:ignore properties to .gitignore.\'\n</code></pre>\n\n<p><strong>4. Push repository to a bare git repository</strong></p>\n\n<p>First, create a bare repository and make its default branch match svn’s “trunk” branch name.</p>\n\n<pre><code>git init --bare ~/new-bare.git\ncd ~/new-bare.git\ngit symbolic-ref HEAD refs/heads/trunk\n</code></pre>\n\n<p>Then push the temp repository to the new bare repository.</p>\n\n<pre><code>cd ~/temp\ngit remote add bare ~/new-bare.git\ngit config remote.bare.push \'refs/remotes/*:refs/heads/*\'\ngit push bare\n</code></pre>\n\n<p>You can now safely delete the ~/temp repository.</p>\n\n<p><strong>5. Rename “trunk” branch to “master”</strong></p>\n\n<p>Your main development branch will be named “trunk” which matches the name it was in Subversion. You’ll want to rename it to Git’s standard “master” branch using:</p>\n\n<pre><code>cd ~/new-bare.git\ngit branch -m trunk master\n</code></pre>\n\n<p><strong>6. Clean up branches and tags</strong></p>\n\n<p>git-svn makes all of Subversions tags into very-short branches in Git of the form “tags/name”. You’ll want to convert all those branches into actual Git tags using:</p>\n\n<pre><code>cd ~/new-bare.git\ngit for-each-ref --format=\'%(refname)\' refs/heads/tags |\ncut -d / -f 4 |\nwhile read ref\ndo\n git tag "$ref" "refs/heads/tags/$ref";\n git branch -D "tags/$ref";\ndone\n</code></pre>\n\n<p>This step will take a bit of typing. :-) But, don’t worry; your unix shell will provide a > secondary prompt for the extra-long command that starts with git for-each-ref.</p>\n'}, {'answer_id': 25823518, 'author': 'leftclickben', 'author_id': 1007512, 'author_profile': 'https://Stackoverflow.com/users/1007512', 'pm_score': 2, 'selected': False, 'text': '<p>For <strong>GitLab</strong> users I\'ve put up a gist on how I migrated from SVN here:</p>\n<p><a href="https://gist.github.com/leftclickben/322b7a3042cbe97ed2af" rel="nofollow noreferrer">https://gist.github.com/leftclickben/322b7a3042cbe97ed2af</a></p>\n<h1>Steps to migrate from SVN to GitLab</h1>\n<h2>Setup</h2>\n<ul>\n<li>SVN is hosted at <code>svn.domain.com.au</code>.</li>\n<li>SVN is accessible via <code>http</code> (other protocols should work).</li>\n<li>GitLab is hosted at <code>git.domain.com.au</code> and:\n<ul>\n<li>A group is created with the namespace <code>dev-team</code>.</li>\n<li>At least one user account is created, added to the group, and has an SSH key for the account being used for the migration (test using <code>ssh [email protected]</code>).</li>\n<li>The project <code>favourite-project</code> is created in the <code>dev-team</code> namespace.</li>\n</ul>\n</li>\n<li>The file <code>users.txt</code> contains the relevant user details, one user per line, of the form <code>username = First Last &lt;[email protected]&gt;</code>, where <code>username</code> is the username given in SVN logs. (See first link in References section for details, in particular answer by user Casey).</li>\n</ul>\n<h2>Versions</h2>\n<ul>\n<li>subversion version 1.6.17 (r1128011)</li>\n<li>git version 1.9.1</li>\n<li>GitLab version 7.2.1 ff1633f</li>\n<li>Ubuntu server 14.04</li>\n</ul>\n<h2>Commands</h2>\n<pre><code>bash\ngit svn clone --stdlayout --no-metadata -A users.txt \nhttp://svn.domain.com.au/svn/repository/favourite-project\ncd favourite-project\ngit remote add gitlab [email protected]:dev-team/favourite-project.git\ngit push --set-upstream gitlab master\n</code></pre>\n<p>That\'s it! Reload the project page in GitLab web UI and you will see all commits and files now listed.</p>\n<h2>Notes</h2>\n<ul>\n<li>If there are unknown users, the <code>git svn clone</code> command will stop, in which case, update <code>users.txt</code>, <code>cd favourite-project</code> and <code>git svn fetch</code> will continue from where it stopped.</li>\n<li>The standard <code>trunk</code>-<code>tags</code>-<code>branches</code> layout for SVN repository is required.</li>\n<li>The SVN URL given to the <code>git svn clone</code> command stops at the level immediately above <code>trunk/</code>, <code>tags/</code> and <code>branches/</code>.</li>\n<li>The <code>git svn clone</code> command produces a lot of output, including some warnings at the top; I ignored the warnings.</li>\n</ul>\n'}, {'answer_id': 28364465, 'author': 'it3xl', 'author_id': 390940, 'author_profile': 'https://Stackoverflow.com/users/390940', 'pm_score': 4, 'selected': False, 'text': '<h1><a href="http://www.subgit.com/" rel="nofollow noreferrer">SubGit</a> (vs Blue Screen of Death)</h1>\n<pre><code>subgit import --svn-url url://svn.serv/Bla/Bla directory/path/Local.git.Repo\n</code></pre>\n<p>It\'s all.</p>\n<p>+ To update from SVN, a Git repository is created by the first command.</p>\n<pre><code>subgit import directory/path/Local.git.Repo\n</code></pre>\n<hr />\n<p>I used a way to migrate to Git instantly for a huge repository. <br/>\nOf course, you need some preparation. <br/>\nBut you may don\'t stop the development process, at all.</p>\n<p>Here is my way.</p>\n<p>My solution looks like:</p>\n<ul>\n<li><strong>Migrate SVN to a Git repository</strong></li>\n<li><strong>Update the Git repository just before team\'s switching to</strong>.</li>\n</ul>\n<p>Migration takes a lot of time for a big SVN repository. <br/>\nBut updating of the completed migration just seconds.</p>\n<p>Of course, I\'m using <a href="http://www.subgit.com/remote-book.html#7" rel="nofollow noreferrer">SubGit</a>, mama.\ngit-svn makes me <a href="http://en.wikipedia.org/wiki/Blue_Screen_of_Death" rel="nofollow noreferrer">Blue Screen of Death</a>. Just constantly.\nAnd git-svn is boring me with Git\'s &quot;<a href="https://stackoverflow.com/questions/21123415/git-pull-aborted-with-error-filename-too-long">filename too long</a>&quot; fatal error.</p>\n<p><strong>STEPS</strong></p>\n<p><strong>1.</strong> <a href="http://www.subgit.com/download.html" rel="nofollow noreferrer">Download SubGit</a></p>\n<p><strong>2.</strong> Prepare migrate and update commands.</p>\n<p>Let\'s say we do it for Windows (it\'s trivial to port to Linux). <br/>\nIn a SubGit\'s installation <strong>bin</strong> directory (subgit-2.X.X\\bin), create two .bat files.</p>\n<p>Content of a file/command for the migration:</p>\n<pre><code>start subgit import --svn-url url://svn.serv/Bla/Bla directory/path/Local.git.Repo\n</code></pre>\n<p>The &quot;start&quot; command is optional here (Windows). It\'ll allow to see errors on start and left a shell opened after completion of the SubGit.</p>\n<p>You may add here <a href="http://www.subgit.com/remote-book.html#7" rel="nofollow noreferrer">additional parameters similar to git-svn</a>.\nI\'m using only <strong>--default-domain myCompanyDomain.com</strong> to fix the domain of the email address of SVN authors. <br/>\nI have the standard SVN repository\'s structure (trunk/branches/tags) and we didn\'t have troubles with &quot;authors mapping&quot;. So I\'m doing nothing anymore.</p>\n<p><em>(If you want to migrate tags like branches or your SVN have multiple branches/tags folders you may consider using the more verbose SubGit <a href="https://stackoverflow.com/questions/23251394/subgit-import-and-multiple-branches-directories">approach</a>)</em></p>\n<p><strong>Tip 1</strong>: Use --minimal-revision YourSvnRevNumber to see fast how things boil out (some kind of a debugging).\nEspecially useful is to see resolved author names or emails. <br/>\nOr to limit the migration history depth.</p>\n<p><strong>Tip 2</strong>: Migration may be interrupted (<kbd>Ctrl</kbd> + <kbd>C</kbd>) and restored by running of the next updating command/file. <br/>\nI don\'t advise doing this for big repositories. I have received &quot;Out of memory Java+Windows exception&quot;.</p>\n<p><strong>Tip 3</strong>: Better to create a copy of your result bare repository.</p>\n<p>Content of a file/command for updating:</p>\n<pre><code>start subgit import directory/path/Local.git.Repo\n</code></pre>\n<p>You may run it any amount of time when you want to obtain the last team\'s commits to your Git repository.</p>\n<p><strong>Warning!</strong> Don\'t touch your bare repository (creation of branches for example). <br/>\nYou\'ll take the next fatal error:</p>\n<blockquote>\n<p>Unrecoverable error: are out of sync and cannot be synced ... Translating Subversion revisions to Git commits...</p>\n</blockquote>\n<p><strong>3.</strong> Run the first command/file. It\'ll take a loooong time for a big repository. 30 hours for my humble repository.</p>\n<p>It\'s all. <br/>\nYou may update your Git repository from SVN at any time any amount of times by running the second file/command. And before switching your development team to Git. <br/>\nIt\'ll take just seconds.</p>\n<hr />\n<hr />\n<p>There\'s one more useful task.</p>\n<p><strong>Push your local Git repository to a remote Git repository</strong></p>\n<p>Is it your case? Let\'s proceed.</p>\n<ol>\n<li>Configure your remotes</li>\n</ol>\n<p>Run:</p>\n<pre><code>$ git remote add origin url://your/repo.git\n</code></pre>\n<ol start="2">\n<li>Prepare to initial send of your huge local Git repository to a remote repository</li>\n</ol>\n<p>By default your Git can\'t send big chunks.\n<a href="https://stackoverflow.com/a/18696820/390940">fatal: The remote end hung up unexpectedly</a></p>\n<p>Let\'s run for it:</p>\n<pre><code>git config --global http.postBuffer 1073741824\n</code></pre>\n<p>524288000 - 500 MB\n1073741824 - 1 GB, etc.</p>\n<p>Fix your local <a href="https://www.google.com/search?newwindow=1&amp;espv=2&amp;q=windows+git+unable+to+get+local+issuer+certificate&amp;oq=windows+git+unable+to+get+local+issuer+certificate&amp;gs_l=serp.3...53528.55201.0.55497.12.9.0.0.0.1.398.398.3-1.1.0.msedr...0...1c.1.61.serp..12.0.0.rqc3smB1Tyo" rel="nofollow noreferrer">certificate troubles</a>. If your git-server uses a broken certificate.</p>\n<p><strong>I have disabled <a href="https://stackoverflow.com/a/8755199/390940">certificates</a>.</strong></p>\n<p>Also your Git server may have a <a href="https://stackoverflow.com/questions/13456025/rpc-failed-result-22-http-code-404">request amount limitations needing to be corrected</a>.</p>\n<ol start="3">\n<li><a href="https://stackoverflow.com/questions/6865302/push-local-git-repo-to-new-remote-including-all-branches-and-tags">Push all migration</a> to the team\'s remote Git repository.</li>\n</ol>\n<p>Run with a local Git:</p>\n<pre><code>git push origin --mirror\n</code></pre>\n<p>(<em>git push origin \'*:*\'</em> for old Git versions)</p>\n<p>If you get the following: <strong>error: cannot spawn git: No such file or directory</strong>... For me the full recreation of my repository solves this error (30 hours). You can try the next commands</p>\n<pre><code>git push origin --all\ngit push origin --tags\n</code></pre>\n<p>Or try to <a href="https://groups.google.com/d/msg/msysgit/6bFAPUQDQLI/d_ko7gWViC8J" rel="nofollow noreferrer">reinstall Git</a> (<strong>useless for me</strong>).\nOr you may create branches from all you tags and push them. Or, or, or...</p>\n'}, {'answer_id': 29173307, 'author': 'krlmlr', 'author_id': 946850, 'author_profile': 'https://Stackoverflow.com/users/946850', 'pm_score': 4, 'selected': False, 'text': '<h1><a href="http://www.catb.org/esr/reposurgeon/" rel="noreferrer">reposurgeon</a></h1>\n\n<p>For complicated cases, reposurgeon by <a href="https://en.wikipedia.org/wiki/Eric_S._Raymond" rel="noreferrer">Eric S. Raymond</a> is the tool of choice. In addition to SVN, it supports many other version control systems via the <code>fast-export</code> format, and also <a href="http://en.wikipedia.org/wiki/Concurrent_Versions_System" rel="noreferrer">CVS</a>. The author reports successful conversions of ancient repositories such as <a href="http://en.wikipedia.org/wiki/Emacs" rel="noreferrer">Emacs</a> and <a href="https://en.wikipedia.org/wiki/FreeBSD" rel="noreferrer">FreeBSD</a>.</p>\n\n<p>The tool apparently <a href="http://www.catb.org/~esr/reposurgeon/features.html" rel="noreferrer">aims at near perfect conversion</a> (such as converting SVN\'s <code>svn:ignore</code> properties to <code>.gitignore</code> files) even for difficult repository layouts with a long history. For many cases, other tools might be easier to use.</p>\n\n<p>Before delving into the documentation of the <code>reposurgeon</code> command line, be sure to read the excellent <a href="http://www.catb.org/esr/dvcs-migration-guide.html" rel="noreferrer">DVCS migration guide</a> which goes over the conversion process step by step.</p>\n'}, {'answer_id': 31318711, 'author': 'Nanda', 'author_id': 4990518, 'author_profile': 'https://Stackoverflow.com/users/4990518', 'pm_score': 0, 'selected': False, 'text': '<p>Download the Ruby installer for Windows and install the latest version with it. Add Ruby executables to your path.</p>\n\n<ul>\n<li>Install svn2git</li>\n<li>Start menu -> All programs -> Ruby -> Start a command prompt with Ruby</li>\n<li><p>Then type “gem install svn2git” and enter</p>\n\n<p><strong>Migrate Subversion repository</strong></p></li>\n<li><p>Open a Ruby command prompt and go to the directory where the files are to be migrated</p>\n\n<p>Then svn2git <a href="http://[domain" rel="nofollow">http://[domain</a> name]/svn/ [repository root]</p></li>\n<li><p>It may take few hours to migrate the project to Git depends on the project code size.</p></li>\n<li><p>This major step helps in creating the Git repository structure as mentioned below.</p>\n\n<p>SVN (/Project_components) trunk --> Git master\nSVN (/Project_components) branches --> Git branches\nSVN (/Project_components) tags --> Git tags</p></li>\n</ul>\n\n<p>Create the remote repository and push the changes.</p>\n'}, {'answer_id': 31727222, 'author': 'Josh Benson', 'author_id': 5174258, 'author_profile': 'https://Stackoverflow.com/users/5174258', 'pm_score': 0, 'selected': False, 'text': "<p>GitHub has an importer. Once you've created the repository, you can import from an existing repository, via its URL. It will ask for your credentials if applicable and go from there.</p>\n\n<p>As it's running it will find authors, and you can simply map them to users on GitHub.</p>\n\n<p>I have used it for a few repositories now, and it's pretty accurate and much faster too! It took 10 minutes for a repository with ~4000 commits, and after it took my friend four days!</p>\n"}, {'answer_id': 34879129, 'author': 'Zitrax', 'author_id': 11722, 'author_profile': 'https://Stackoverflow.com/users/11722', 'pm_score': 0, 'selected': False, 'text': '<p>Several answers here refer to <a href="https://github.com/nirvdrum/svn2git" rel="nofollow">https://github.com/nirvdrum/svn2git</a>, but for large repositories this can be slow. I had a try using <a href="https://github.com/svn-all-fast-export/svn2git" rel="nofollow">https://github.com/svn-all-fast-export/svn2git</a> instead which is a tool with exactly the same name but was used to migrate KDE from SVN to Git.</p>\n\n<p>Slightly more work to set it up but when done the conversion itself for me took minutes where the other script spent hours.</p>\n'}, {'answer_id': 35410032, 'author': 'Ruslan Makrenko', 'author_id': 4953065, 'author_profile': 'https://Stackoverflow.com/users/4953065', 'pm_score': 0, 'selected': False, 'text': '<p>There are different methods to achieve this goal. I\'ve tried some of them and found really working one with just git and svn installed on Windows OS.</p>\n\n<p>Prerequisites: </p>\n\n<ol>\n<li>git on windows (I\'ve used this one) <a href="https://git-scm.com/" rel="nofollow noreferrer">https://git-scm.com/</a> </li>\n<li>svn with console tools installed (I\'ve used tortoise svn) </li>\n<li>Dump file of your SVN repository. \n<code>svnadmin dump /path/to/repository &gt; repo_name.svn_dump</code></li>\n</ol>\n\n<p>Steps to achieve final goal (move all repository with history to a git, firstly local git, then remote)</p>\n\n<ol>\n<li><p>Create empty repository (using console tools or tortoiseSVN) in directory REPO_NAME_FOLDER\n<code>cd REPO_NAME_PARENT_FOLDER</code>, put dumpfile.dump into REPO_NAME_PARENT_FOLDER</p></li>\n<li><p><code>svnadmin load REPO_NAME_FOLDER &lt; dumpfile.dump</code> Wait for this operation, it may be long</p></li>\n<li><p>This command is silent, so open second cmd window : <code>svnserve -d -R --root REPO_NAME_FOLDER</code> \nWhy not just use file:///...... ? Cause next command will fail with <code>Unable to open ... to URL:</code>, thanks to the answer <a href="https://stackoverflow.com/a/6300968/4953065">https://stackoverflow.com/a/6300968/4953065</a></p></li>\n<li><p>Create new folder SOURCE_GIT_FOLDER</p></li>\n<li><code>cd SOURCE_GIT_FOLDER</code></li>\n<li>git svn clone svn://localhost/ Wait for this operation.</li>\n</ol>\n\n<p>Finally, what do we got?</p>\n\n<p>Lets check our Local repository : </p>\n\n<pre><code>git log\n</code></pre>\n\n<p>See your previous commits? If yes - okay</p>\n\n<p>So now you have fully functional local git repository with your sources and old svn history.\nNow, if you want to move it to some server, use the following commands : </p>\n\n<pre><code>git remote add origin https://fullurlpathtoyourrepo/reponame.git\ngit push -u origin --all # pushes up the repo and its refs for the first time\ngit push -u origin --tags # pushes up any tags\n</code></pre>\n\n<p>In my case, I\'ve dont need tags command cause my repo dont have tags.</p>\n\n<p>Good luck!</p>\n'}, {'answer_id': 35605248, 'author': 'Pablo Belaustegui', 'author_id': 5975111, 'author_profile': 'https://Stackoverflow.com/users/5975111', 'pm_score': 3, 'selected': False, 'text': '<p>I\'ve posted an step by step guide (<a href="http://blog.10pines.com/2016/02/24/svn-to-git/" rel="noreferrer">here</a>) to convert svn in to git including converting svn tags in to git tags and svn branches in to git branches.</p>\n\n<p>Short version:</p>\n\n<p>1) clone svn from an specific revision number. (the revision number must be the oldest you want to migrate)</p>\n\n<pre><code>git svn clone --username=yourSvnUsername -T trunk_subdir -t tags_subdir -b branches_subdir -r aRevisionNumber svn_url gitreponame\n</code></pre>\n\n<p>2) fetch svn data. This step it\'s the one it takes most time.</p>\n\n<pre><code>cd gitreponame\ngit svn fetch\n</code></pre>\n\n<p>repeat git svn fetch until finishes without error</p>\n\n<p>3) get master branch updated</p>\n\n<pre><code>git svn rebase\n</code></pre>\n\n<p>4) Create local branches from svn branches by copying references</p>\n\n<pre><code>cp .git/refs/remotes/origin/* .git/refs/heads/\n</code></pre>\n\n<p>5) convert svn tags into git tags</p>\n\n<pre><code>git for-each-ref refs/remotes/origin/tags | sed \'s#^.*\\([[:xdigit:]]\\{40\\}\\).*refs/remotes/origin/tags/\\(.*\\)$#\\2 \\1#g\' | while read p; do git tag -m "tag from svn" $p; done\n</code></pre>\n\n<p>6) Put a repository at a better place like github</p>\n\n<pre><code>git remotes add newrepo [email protected]:aUser/aProjectName.git\ngit push newrepo refs/heads/*\ngit push --tags newrepo\n</code></pre>\n\n<p>If you want more details, read my <a href="http://blog.10pines.com/2016/02/24/svn-to-git/" rel="noreferrer">post</a> or ask me.</p>\n'}, {'answer_id': 36986911, 'author': 'Pankaj', 'author_id': 926520, 'author_profile': 'https://Stackoverflow.com/users/926520', 'pm_score': 3, 'selected': False, 'text': '<p>We can use <code>git svn clone</code> commands as below.</p>\n\n<ul>\n<li><code>svn log -q &lt;SVN_URL&gt; | awk -F \'|\' \'/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" &lt;"$2"&gt;"}\' | sort -u &gt; authors.txt</code></li>\n</ul>\n\n<p>Above command will create authors file from SVN commits.</p>\n\n<ul>\n<li><code>svn log --stop-on-copy &lt;SVN_URL&gt;</code></li>\n</ul>\n\n<p>Above command will give you first revision number when your SVN project got created.</p>\n\n<ul>\n<li><code>git svn clone -r&lt;SVN_REV_NO&gt;:HEAD --no-minimize-url --stdlayout --no-metadata --authors-file authors.txt &lt;SVN_URL&gt;</code></li>\n</ul>\n\n<p>Above command will create the Git repository in local.</p>\n\n<p>Problem is that it won\'t convert branches and tags to push. You will have to do them manually. For example below for branches:</p>\n\n<pre><code>$ git remote add origin https://github.com/pankaj0323/JDProjects.git\n$ git branch -a\n* master\n remotes/origin/MyDevBranch\n remotes/origin/tags/MyDevBranch-1.0\n remotes/origin/trunk\n$$ git checkout -b MyDevBranch origin/MyDevBranch\nBranch MyDevBranch set up to track remote branch MyDevBranch from origin.\nSwitched to a new branch \'MyDevBranch\'\n$ git branch -a\n* MyDevBranch\n master\n remotes/origin/MyDevBranch\n remotes/origin/tags/MyDevBranch-1.0\n remotes/origin/trunk\n$\n</code></pre>\n\n<p>For tags:</p>\n\n<pre><code>$git checkout origin/tags/MyDevBranch-1.0\nNote: checking out \'origin/tags/MyDevBranch-1.0\'.\nYou are in \'detached HEAD\' state. You can look around, make experimental\nchanges and commit them, and you can discard any commits you make in this\nstate without impacting any branches by performing another checkout.\n\nIf you want to create a new branch to retain commits you create, you may\ndo so (now or later) by using -b with the checkout command again. Example:\n\n git checkout -b new_branch_name\n\nHEAD is now at 3041d81... Creating a tag\n$ git branch -a\n* (detached from origin/tags/MyDevBranch-1.0)\n MyDevBranch\n master\n remotes/origin/MyDevBranch\n remotes/origin/tags/MyDevBranch-1.0\n remotes/origin/trunk\n$ git tag -a MyDevBranch-1.0 -m "creating tag"\n$git tag\nMyDevBranch-1.0\n$\n</code></pre>\n\n<p>Now push master, branches and tags to remote git repository.</p>\n\n<pre><code>$ git push origin master MyDevBranch MyDevBranch-1.0\nCounting objects: 14, done.\nDelta compression using up to 8 threads.\nCompressing objects: 100% (11/11), done.\nWriting objects: 100% (14/14), 2.28 KiB | 0 bytes/s, done.\nTotal 14 (delta 3), reused 0 (delta 0)\nTo https://github.com/pankaj0323/JDProjects.git\n * [new branch] master -&gt; master\n * [new branch] MyDevBranch -&gt; MyDevBranch\n * [new tag] MyDevBranch-1.0 -&gt; MyDevBranch-1.0\n$\n</code></pre>\n\n<h1><strong>svn2git utility</strong></h1>\n\n<p><a href="https://github.com/nirvdrum/svn2git" rel="noreferrer">svn2git</a> utility removes manual efforts with branches and tags.</p>\n\n<p>Install it using command <code>sudo gem install svn2git</code>. After that run below command.</p>\n\n<ul>\n<li><code>$ svn2git &lt;SVN_URL&gt; --authors authors.txt --revision &lt;SVN_REV_NO&gt;</code></li>\n</ul>\n\n<p>Now you can list the branches, tags and push them easily.</p>\n\n<pre><code>$ git remote add origin https://github.com/pankaj0323/JDProjects.git\n$ git branch -a\n MyDevBranch\n* master\n remotes/svn/MyDevBranch\n remotes/svn/trunk\n$ git tag\n MyDevBranch-1.0\n$ git push origin master MyDevBranch MyDevBranch-1.0\n</code></pre>\n\n<p>Imagine you have 20 branches and tags, obviously svn2git will save you a lot of time and that\'s why I like it better than native commands. It\'s a nice wrapper around native <code>git svn clone</code> command. </p>\n\n<p>For a complete example, refer my <a href="http://www.journaldev.com/10618/svn-to-git-migration-complete-tutorial" rel="noreferrer">blog entry</a>.</p>\n'}, {'answer_id': 37684168, 'author': 'PShetty', 'author_id': 2160694, 'author_profile': 'https://Stackoverflow.com/users/2160694', 'pm_score': 0, 'selected': False, 'text': '<p>Converting svn submodule/folder \'MyModule\' into git with history without tags nor branches.</p>\n\n<ul>\n<li>git svn clone --no-metadata\n--trunk=SomeFolder1/SomeFolder2/SomeFolder3/MyModule <a href="http://svnhost:port/repo_root_folder/MyModule_temp" rel="nofollow">http://svnhost:port/repo_root_folder/MyModule_temp</a> -A\nC:\\cheetah\\svn\\authors-transform.txt</li>\n<li>git clone MyModule_temp MyModule</li>\n<li>cd MyModule</li>\n<li>git flow init</li>\n<li>git remote set-url origin\n<a href="https://userid@stashhost/stash/scm/xyzxyz/MyModule.git" rel="nofollow">https://userid@stashhost/stash/scm/xyzxyz/MyModule.git</a></li>\n<li>git push -u origin master</li>\n<li>git push -u origin develop</li>\n</ul>\n\n<p>To retain svn ignore list use the above comments after step 1</p>\n'}, {'answer_id': 41449157, 'author': 'Pedro Vicente', 'author_id': 4739800, 'author_profile': 'https://Stackoverflow.com/users/4739800', 'pm_score': 0, 'selected': False, 'text': '<p>I used the following script to read a text file that has a list of all my SVN repositories and convert them to Git, and later use <code>git clone --bare</code> to convert to a bare Git repository:</p>\n\n<pre><code>#!/bin/bash\nfile="list.txt"\nwhile IFS= read -r repo_name\ndo\n printf \'%s\\n\' "$repo_name"\n sudo git svn clone --shared --preserve-empty-dirs --authors-file=users.txt file:///programs/svn/$repo_name\n sudo git clone --bare /programs/git/$repo_name $repo_name.git\n sudo chown -R www-data:www-data $repo_name.git\n sudo rm -rf $repo_name\ndone &lt;"$file"\n</code></pre>\n\n<p>list.txt has the format:</p>\n\n<pre><code>repo1_name\nrepo2_name\n</code></pre>\n\n<p>And users.txt has the format:</p>\n\n<blockquote>\n <p><code>(no author) = Prince Rogers &lt;[email protected]&gt;</code></p>\n</blockquote>\n\n<p>www-data is the Apache web server user, and permission is needed to push changes over HTTP.</p>\n'}, {'answer_id': 48636876, 'author': 'cljk', 'author_id': 1574012, 'author_profile': 'https://Stackoverflow.com/users/1574012', 'pm_score': 2, 'selected': False, 'text': '<p>I´m on a windows machine and made a small Batch to transfer a SVN repo with history (but without branches) to a GIT repo by just calling</p>\n\n<p><code>transfer.bat http://svn.my.address/svn/myrepo/trunk https://git.my.address/orga/myrepo</code></p>\n\n<p>Perhaps anybody can use it. It creates a TMP-folder checks out the SVN repo there with git and adds the new origin and pushes it... and deletes the folder again.</p>\n\n<pre><code>@echo off \nSET FROM=%1 \nSET TO=%2 \nSET TMP=tmp_%random%\n\necho from: %FROM% \necho to: %TO% \necho tmp: %TMP%\n\npause\n\ngit svn clone --no-metadata --authors-file=users.txt %FROM% %TMP% \ncd %TMP% \ngit remote add origin %TO% \ngit push --set-upstream origin master\n\n\ncd .. \necho delete %TMP% ... \npause\n\nrmdir /s /q %TMP%\n</code></pre>\n\n<p>You still need the users.txt with your user-mappings like</p>\n\n<pre><code>User1 = User One &lt;[email protected]&gt;\n</code></pre>\n'}, {'answer_id': 48732137, 'author': 'Anand Tripathi', 'author_id': 5230702, 'author_profile': 'https://Stackoverflow.com/users/5230702', 'pm_score': -1, 'selected': False, 'text': '<h1>For this, I have used <strong>svn2git</strong> library with the following procedure:</h1>\n\n<blockquote>\n <p>sudo apt-get install git-core git-svn ruby<br>\n sudo gem install svn2git<br>\n svn log --quiet | grep -E "r[0-9]+ \\| .+ \\|" | cut -d\'|\' -f2 | sed \'s/ //g\' | sort | uniq > authors.txt (this command is for mapping the authors)</p>\n</blockquote>\n\n<p>Above step should be performed in the folder that you are going to convert from svn to git.</p>\n\n<blockquote>\n <p>Add one mapping per line in authors.txt like this</p>\n</blockquote>\n\n<pre><code>anand = Anand Tripathi &lt;email_id&gt;\ntrip = Tripathi Anand &lt;email_id&gt;\n</code></pre>\n\n<p>Create a folder for a new git repository and execute the command below having the path of authors.txt</p>\n\n<pre><code>svn2git &lt;svn_repo_path&gt; --nobranches --notags --notrunk --no-minimize-url --username &lt;user_name&gt; --verbose --authors &lt;author.txt_path&gt;\n\nIf no trunk and no tag and branch is present then have to execute the above command else if root is trunk then mention rootistrunk or trunk is present then --trunk &lt;trunk_name&gt;\n</code></pre>\n\n<blockquote>\n <p>git remote add origin <br>\n git push --all origin <br>\n git push --tags origin</p>\n</blockquote>\n'}, {'answer_id': 63570098, 'author': 'dgates82', 'author_id': 2209181, 'author_profile': 'https://Stackoverflow.com/users/2209181', 'pm_score': 1, 'selected': False, 'text': "<p>First, credit to the answer from @cmcginty. It was a great starting point for me, and much of what I'll post here borrowed heavily from it. However, the repos that I was moving have years of history which led to a few issues following that answer to the letter (hundreds of branches and tags that would need to be manually moved for one; read more later).</p>\n<p>So after hours of searching and trial and error I was able to put together a script which allowed me to easily move several projects from SVN to GIT, and I've decided to share my findings here in case anyone else is in my shoes.</p>\n<p>&lt;tl;dr&gt; Let's get started</p>\n<hr />\n<p>First, create an 'Authors' file which will translate basic svn users to more complex git users. The easiest way to do this is using a command to extract all users from the svn repo you are going to move.</p>\n<pre><code>svn log -q | awk -F '|' '/^r/ {sub(&quot;^ &quot;, &quot;&quot;, $2); sub(&quot; $&quot;, &quot;&quot;, $2); print $2&quot; = &quot;$2&quot; &lt;&quot;$2&quot;&gt;&quot;}' | sort -u &gt; authors-transform.txt\n</code></pre>\n<p>This will produce a file called authors-transform.txt with a line for each user that has made a change in the svn repo it was ran from.</p>\n<pre><code>someuser = someuser &lt;someuser&gt;\n</code></pre>\n<p>Update to include full name and email for git</p>\n<pre><code>someuser = Some User &lt;[email protected]&gt;\n</code></pre>\n<p>Now start the clone using your authors file</p>\n<pre><code>git svn clone --stdlayout --no-metadata -r854:HEAD --authors-file=authors-transform.txt https://somesvnserver/somerepo/ temp\n</code></pre>\n<ul>\n<li>--stdlayout indicates that the svn repo follows the standard /trunk /branches /tags layout</li>\n<li>--no-metadata tells git not to stamp metadata relating to the svn commits on each git commit. If this is not a one-way conversion remove this tag</li>\n<li>-r854:HEAD only fetches history from revision 854 up. This is where I hit my first snag; the repo I was converting had a 'corrupted' commit at revision 853 so it would not clone. Using this parameter allows you to only clone part of the history.</li>\n<li>temp is the name of the directory that will be created to initialize\nthe new git repo</li>\n</ul>\n<p>This step can take awhile, particularly on a large or old repo (roughly 18 hours for one of ours). You can also use that -r switch to only take a small history to see the clone, and fetch the rest later.</p>\n<p>Move to the new directory</p>\n<pre><code>cd temp\n</code></pre>\n<p>Fetch any missing history if you only pulled partial in clone</p>\n<pre><code>git svn fetch\n</code></pre>\n<p>Tags are created as branches during cloning. If you only have a few you can convert them one at a time.</p>\n<pre><code>git 1.0.0 origin/tags/1.0.0\n</code></pre>\n<p>However, this is tedious if you have hundreds of tags, so the following script worked for me.</p>\n<pre><code>for brname in `git branch -r | grep tags | awk '{gsub(/^[^\\/]+\\//,&quot;&quot;,$1); print $1}'`; do echo $brname; tname=${brname:5}; echo $tname; git tag $tname origin/tags/$tname; done\n</code></pre>\n<p>You also need to checkout all branches you want to keep</p>\n<pre><code>git checkout -b branchname origin/branches/branchname\n</code></pre>\n<p>And if you have a lot of branches as well, this script may help</p>\n<pre><code>for brname in `git branch -r | grep -v master | grep -v HEAD | grep -v trunk | grep -v tags | awk '{gsub(/^[^\\/]+\\//,&quot;&quot;,$1); print $1}'`; do echo $brname; git checkout -b $brname origin/$brname; done\n</code></pre>\n<p>This will ignore the trunk branch, as it will already be checked out as master and save a step later deleting the duplicate branch, as well as ignoring the /tags that we already converted.</p>\n<p>Now is a good time to take a look at the new repo and make sure you have a <strong>local</strong> branch or tag for anything you want to keep as remote branches will be dropped in a moment.</p>\n<p>Ok, now lets clone everything we've checked out to a clean repo (named temp2 here)</p>\n<pre><code>cd ..\ngit clone temp temp2\ncd temp2\n</code></pre>\n<p>Now we'll need to checkout all of the branches one more time before pushing them to their final remote, so follow your favorite method from above.</p>\n<p>If you're following gitflow you can rename your working branch to develop.</p>\n<pre><code>git checkout -b WORKING\ngit branch -m develop\ngit push origin --delete WORKING\ngit push origin -u develop\n</code></pre>\n<p>Now, if everything looks good, you're ready to push to your git repository</p>\n<pre><code>git remote set-url origin https://somebitbucketserver/somerepo.git\ngit push -u origin --all\ngit push origin --tags\n</code></pre>\n<p>I did run into one final issue which was that Control Freak initially blocked me from pushing tags that I didn't create, so if your team uses Control Freak you may need to disable or adjust that setting for your initial push.</p>\n"}, {'answer_id': 68242281, 'author': 'Bharathiraja', 'author_id': 2648257, 'author_profile': 'https://Stackoverflow.com/users/2648257', 'pm_score': 0, 'selected': False, 'text': "<p>All in One - shell script for <code>SVN</code> to <code>GIT</code> Migration. Mention the <code>GIT</code> and <code>SVN</code> details with placeholder <code>&lt;&gt;</code></p>\n<pre><code>#!/bin/bash\n\n######## Project name \nPROJECT_NAME=&quot;Helloworld&quot;\nEMAIL=&quot;example mail&quot;\n\n#Credientials Repo\nGIT_USER='&lt;git username&gt;'\nGIT_PWD='&lt;git password&gt;'\nSVN_USER='&lt;svn username&gt;'\nSVN_PWD='&lt;svn password&gt;'\n\n######## SVN repository to be migrated # Dont use https - error will be thrown\nBASE_SVN=&quot;&lt;SVN URL&gt;/Helloworld&quot;\n\n#Organization inside BASE_SVN\nBRANCHES=&quot;branches&quot;\nTAGS=&quot;tags&quot;\nTRUNK=&quot;trunk&quot;\n\n#Credientials\ngit config --global user.name '&lt;git username&gt;'\ngit config --global user.password '&lt;git password&gt;'\ngit config --global credential.helper 'cache --timeout=3600'\n\n######## GIT repository to migrate - Ensure already project created in Git\nGIT_URL=https://$GIT_USER:$GIT_PWD@&lt;GIT URL&gt;/Helloworld.git\n\n###########################\n#### Don't need to change from here\n###########################\n\n#Geral Configuration\nABSOLUTE_PATH=$(pwd)\nTMP=$ABSOLUTE_PATH/$PROJECT_NAME\n\n#Branchs Configuration\nSVN_BRANCHES=$BASE_SVN/$BRANCHES\nSVN_TAGS=$BASE_SVN/$TAGS\nSVN_TRUNK=$BASE_SVN/$TRUNK\n\nAUTHORS=$PROJECT_NAME&quot;-authors.txt&quot;\n\necho '[LOG] Starting migration of '$SVN_TRUNK\necho '[LOG] Using: '$(git --version)\necho '[LOG] Using: '$(svn --version | grep svn,)\n\nmkdir $TMP\necho\necho '[DIR] cd' $TMP\ncd $TMP\n\necho\necho '[LOG] Getting authors'\nsvn --username $SVN_USER --password $SVN_PWD log -q $BASE_SVN | awk -F '|' '/^r/ {sub(&quot;^ &quot;, &quot;&quot;, $2); sub(&quot; $&quot;, &quot;&quot;, $2); print $2&quot; = &quot;$2&quot; &lt;&quot;$2&quot;@&quot;$EMAIL&quot;&gt;&quot;}' | sort -u &gt;&gt; $AUTHORS\n\necho\necho '[RUN] git svn clone --authors-file='$AUTHORS' --trunk='$TRUNK' --branches='$BRANCHES' --tags='$TAGS $BASE_SVN $TMP\ngit svn clone --authors-file=$AUTHORS --trunk=$TRUNK --branches=$BRANCHES --tags=$TAGS $BASE_SVN $TMP\n\n#Not working so no need to mention it\n#--stdlayout $PROJECT_NAME\necho\necho '[RUN] svn ls '$SVN_BRANCHES\nsvn ls $SVN_BRANCHES\n\necho \necho 'git branch -a'\ngit branch -a\n\necho\necho '[LOG] Getting first revision'\nFIRST_REVISION=$( svn log -r 1:HEAD --limit 1 $BASE_SVN | awk -F '|' '/^r/ {sub(&quot;^ &quot;, &quot;&quot;, $1); sub(&quot; $&quot;, &quot;&quot;, $1); print $1}' )\n\necho\necho '[RUN] git svn fetch -'$FIRST_REVISION':HEAD'\ngit svn fetch -$FIRST_REVISION:HEAD\n\n#Branches and Tags \necho\necho '[RUN] svn ls '$SVN_BRANCHES\nfor BRANCH in $(svn ls $SVN_BRANCHES); do\n echo git branch ${BRANCH%/} remotes/svn/${BRANCH%/}\n git branch ${BRANCH%/} remotes/svn/${BRANCH%/}\ndone\n\ngit for-each-ref --format=&quot;%(refname:short) %(objectname)&quot; refs/remotes/origin/tags | grep -v &quot;@&quot; | cut -d / -f 3- |\nwhile read ref\ndo\n echo git tag -a $ref -m 'import tag from svn'\n git tag -a $ref -m 'import tag from svn'\ndone\n\ngit for-each-ref --format=&quot;%(refname:short)&quot; refs/remotes/origin/tags | cut -d / -f 1- |\nwhile read ref\ndo\n git branch -rd $ref\ndone\n \necho\necho 'git tag'\ngit tag\n\necho\necho 'git show-ref --tags'\ngit show-ref --tags\n\necho\necho '[RUN] git remote add origin '$GIT_URL\ngit remote add origin $GIT_URL\n\necho\necho '[RUN] git push'\ngit push origin --all --force\ngit push origin --tags\n\n#echo git branch -d -r trunk\n#git branch -d -r trunk\n\ngit config --global credential.helper cache\necho 'Successful.'\n</code></pre>\n<ul>\n<li>When you run above script, it will fetch branches and tags details from SVN and put it under <code>.git</code> folder.</li>\n<li>Crosscheck whether all branches are there in the <code>SVN</code> that should be available under this <code>.git/refs/heads</code> folder.</li>\n<li>If some branches are missing which was there in <code>SVN</code> then do manually copy branches files from <code>.git/refs/remotes/origin/&lt;branches&gt;</code> to <code>.git/refs/heads</code></li>\n<li>Only copy branches (including <code>master</code>) and ignore if any <code>tags</code> or <code>trunk</code>.</li>\n<li>Now run the script again. You could see all <code>branches</code> and <code>tags</code> in git repositories.</li>\n</ul>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79165', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14690/']
79,197
<p>What's a simple way to combine <strong>feed</strong> and <strong>feed2</strong>? I want the items from <strong>feed2</strong> to be added to <strong>feed</strong>. Also I want to avoid duplicates as <strong>feed</strong> might already have items when a question is tagged with both WPF and Silverlight.</p> <pre><code>Uri feedUri = new Uri("http://stackoverflow.com/feeds/tag/silverlight"); XmlReader reader = XmlReader.Create(feedUri.AbsoluteUri); SyndicationFeed feed = SyndicationFeed.Load(reader); Uri feed2Uri = new Uri("http://stackoverflow.com/feeds/tag/wpf"); XmlReader reader2 = XmlReader.Create(feed2Uri.AbsoluteUri); SyndicationFeed feed2 = SyndicationFeed.Load(reader2); </code></pre>
[{'answer_id': 79372, 'author': 'David Thibault', 'author_id': 5903, 'author_profile': 'https://Stackoverflow.com/users/5903', 'pm_score': 0, 'selected': False, 'text': '<p>If it\'s solely for stackoverflow, you can use this :<br>\n<a href="https://stackoverflow.com/feeds/tag/silverlight%20wpf">https://stackoverflow.com/feeds/tag/silverlight%20wpf</a><br>\nThis <strong>will</strong> do an union of the two tags.</p>\n\n<p>For a more general solution, I don\'t know. You\'d probably have to manually iterate the elements of the two feeds and join them together. You can compare the &lt;id> elements of &lt;entry>s to see if they are duplicates.</p>\n'}, {'answer_id': 79376, 'author': 'Frater', 'author_id': 14746, 'author_profile': 'https://Stackoverflow.com/users/14746', 'pm_score': 1, 'selected': False, 'text': "<p>Well, one possibility is to create a new syndication feed that is a clone of the first feed, and then simply iterate through each post on the second one, check the first for its existence, and add it if it doesn't exist.</p>\n\n<p>Something along the lines of:</p>\n\n<pre><code>SyndicationFeed newFeed = feed.clone;\nforeach(SyndicationItem item in feed2.items)\n{\n if (!newFeed.contains(item))\n newFeed.items.Add(item);\n}\n</code></pre>\n\n<p>might be able to do it. It looks like 'items' is a simple enumberable list of syndication items, so theres not reason you can't simply add them.</p>\n"}, {'answer_id': 86322, 'author': 'Michael Brown', 'author_id': 14359, 'author_profile': 'https://Stackoverflow.com/users/14359', 'pm_score': 5, 'selected': True, 'text': '<p>You can use LINQ to simplify the code to join two lists (don\'t forget to put System.Linq in your usings and if necessary reference System.Core in your project) Here\'s a Main that does the union and prints them to console (with proper cleanup of the Reader).</p>\n\n<pre><code>using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Xml;\nusing System.ServiceModel.Syndication;\n\nnamespace FeedUnion\n{\n class Program\n {\n static void Main(string[] args)\n {\n Uri feedUri = new Uri("http://stackoverflow.com/feeds/tag/silverlight"); \n SyndicationFeed feed;\n SyndicationFeed feed2;\n using(XmlReader reader = XmlReader.Create(feedUri.AbsoluteUri))\n {\n feed= SyndicationFeed.Load(reader); \n }\n Uri feed2Uri = new Uri("http://stackoverflow.com/feeds/tag/wpf"); \n using (XmlReader reader2 = XmlReader.Create(feed2Uri.AbsoluteUri))\n {\n feed2 = SyndicationFeed.Load(reader2);\n }\n SyndicationFeed feed3 = new SyndicationFeed(feed.Items.Union(feed2.Items));\n StringBuilder builder = new StringBuilder();\n using (XmlWriter writer = XmlWriter.Create(builder))\n {\n feed3.SaveAsRss20(writer);\n System.Console.Write(builder.ToString());\n System.Console.Read();\n }\n }\n }\n}\n</code></pre>\n'}, {'answer_id': 8916265, 'author': 'rasx', 'author_id': 22944, 'author_profile': 'https://Stackoverflow.com/users/22944', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve turned today\'s accepted answer into a unit test just to explore this slightly:</p>\n\n<pre><code> [TestMethod]\n public void ShouldCombineRssFeeds()\n {\n //reference: http://stackoverflow.com/questions/79197/combining-two-syndicationfeeds\n\n SyndicationFeed feed;\n SyndicationFeed feed2;\n\n var feedUri = new Uri("http://stackoverflow.com/feeds/tag/silverlight");\n using(var reader = XmlReader.Create(feedUri.AbsoluteUri))\n {\n feed = SyndicationFeed.Load(reader);\n }\n\n Assert.IsTrue(feed.Items.Count() &gt; 0, "The expected feed items are not here.");\n\n var feed2Uri = new Uri("http://stackoverflow.com/feeds/tag/wpf");\n using(var reader2 = XmlReader.Create(feed2Uri.AbsoluteUri))\n {\n feed2 = SyndicationFeed.Load(reader2);\n }\n\n Assert.IsTrue(feed2.Items.Count() &gt; 0, "The expected feed items are not here.");\n\n var feedsCombined = new SyndicationFeed(feed.Items.Union(feed2.Items));\n\n Assert.IsTrue(\n feedsCombined.Items.Count() == feed.Items.Count() + feed2.Items.Count(),\n "The expected number of combined feed items are not here.");\n\n var builder = new StringBuilder();\n using(var writer = XmlWriter.Create(builder))\n {\n feedsCombined.SaveAsRss20(writer);\n writer.Flush();\n writer.Close();\n }\n\n var xmlString = builder.ToString();\n\n Assert.IsTrue(new Func&lt;bool&gt;(\n () =&gt;\n {\n var test = false;\n\n var xDoc = XDocument.Parse(xmlString);\n var count = xDoc.Root.Element("channel").Elements("item").Count();\n test = (count == feedsCombined.Items.Count());\n\n return test;\n }\n ).Invoke(), "The expected number of RSS items are not here.");\n }\n</code></pre>\n'}, {'answer_id': 17917480, 'author': 'Manjit', 'author_id': 2629183, 'author_profile': 'https://Stackoverflow.com/users/2629183', 'pm_score': 0, 'selected': False, 'text': '<pre><code> //Executed and Tested :) \n using (XmlReader reader = XmlReader.Create(strFeed))\n {\n rssData = SyndicationFeed.Load(reader);\n model.BlogFeed = rssData; ;\n }\n using (XmlReader reader = XmlReader.Create(strFeed1))\n {\n rssData1 = SyndicationFeed.Load(reader);\n model.BlogFeed = rssData1;\n }\n\n SyndicationFeed feed3 = new SyndicationFeed(rssData.Items.Union(rssData1.Items));\n model.BlogFeed = feed3; \n return View(model);\n</code></pre>\n'}, {'answer_id': 35239636, 'author': 'Pherekles', 'author_id': 4565121, 'author_profile': 'https://Stackoverflow.com/users/4565121', 'pm_score': 0, 'selected': False, 'text': "<p>This worked fine for me:</p>\n\n<pre><code>// create temporary List of SyndicationItem's\nList&lt;SyndicationItem&gt; tempItems = new List&lt;SyndicationItem&gt;();\n\n// add all feed items to the list\ntempItems.AddRange(feed.Items);\ntempItems.AddRange(feed2.Items);\n\n// remove duplicates with Linq 'Distinct()'-method depending on yourattributes\n\n// add list without duplicates to 'feed2'\nfeed2.Items = tempItems\n</code></pre>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79197', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1133/']
79,210
<p>What is the best C++ IDE for a *nix envirnoment? I have heard the C/C++ module of Eclipse is decent as well as Notepad++ but beyond these two I have no real idea. Any thoughts or comments?</p>
[{'answer_id': 79214, 'author': 'Vinko Vrsalovic', 'author_id': 5190, 'author_profile': 'https://Stackoverflow.com/users/5190', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.kdevelop.org" rel="nofollow noreferrer">KDevelop</a> is nice, especially if you run KDE. It supports many languages, as an added bonus. I\'ve found its embedded terminal really useful.</p>\n'}, {'answer_id': 79223, 'author': 'user14563', 'author_id': 14563, 'author_profile': 'https://Stackoverflow.com/users/14563', 'pm_score': 0, 'selected': False, 'text': "<p>I can't really vouch for the Eclipse module, but that might be attributed to the fact that I'm on Windows and have nearly no idea what I'm doing. </p>\n\n<p>Can't go wrong with your favorite text editor though.</p>\n"}, {'answer_id': 79225, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>I just use Emacs.</p>\n'}, {'answer_id': 79236, 'author': 'Jerub', 'author_id': 14648, 'author_profile': 'https://Stackoverflow.com/users/14648', 'pm_score': 4, 'selected': False, 'text': '<p>As a programmer who has been writing code under linux for many years, I simply cannot seem to move away from using Vim for writing code.</p>\n\n<p>Once you learn it, and learn some of its more advanced features (Code Folding, how to use ctags, how to work with multiple buffers effectively, etc) moving to another editor is very hard - as everything else seems to be missing features that you\'re used to.</p>\n\n<p>The only other editor with a superset of vim\'s features is emacs. I highly recommend learning one or the other - and if you have questions, don\'t hesitate to ask here or in #emacs or #vim on irc.freenode.net - there\'s a very large and helpful community that will help you learn what extensions or commands best suit the software editing problems that you\'re facing.</p>\n\n<p>[Edit: A comment noted that "vim isn\'t an IDE", I agree. I don\'t like the IDE moniker because it means a gui with a project manager and a bunch of drop down boxes. I like to use the terminology "<strong>Good Tools</strong>". See <a href="http://www.sauria.com/blog/2008/07/20/ides-and-dynamic-languages/" rel="noreferrer">Ted Leung\'s</a> writings on the matter]</p>\n'}, {'answer_id': 79237, 'author': 'Gili', 'author_id': 14731, 'author_profile': 'https://Stackoverflow.com/users/14731', 'pm_score': 2, 'selected': False, 'text': '<p>Netbeans has gotten some pretty good reviews for its C++ support: <a href="http://www.netbeans.org/features/cpp/" rel="nofollow noreferrer">http://www.netbeans.org/features/cpp/</a></p>\n\n<p>I\'ve never used Netbeans or Eclipse for C++ development, but it\'s worth looking at.</p>\n'}, {'answer_id': 79263, 'author': 'RJP Computing', 'author_id': 14734, 'author_profile': 'https://Stackoverflow.com/users/14734', 'pm_score': 2, 'selected': False, 'text': '<p>I really like <a href="http://codelite.org" rel="nofollow noreferrer">CodeLite</a>. Check out it\'s <a href="http://codelite.org/Main/ReadMore" rel="nofollow noreferrer">feature page</a>.</p>\n'}, {'answer_id': 79274, 'author': 'Ben Collins', 'author_id': 3279, 'author_profile': 'https://Stackoverflow.com/users/3279', 'pm_score': 3, 'selected': False, 'text': '<p>Emacs is a fantastic, stay-out-of-my-way-but-be-able-to-do-everything kind of IDE. See this other related question: <a href="https://stackoverflow.com/questions/63421/using-emacs-as-an-ide">Using Emacs as an IDE</a></p>\n'}, {'answer_id': 79298, 'author': 'KPexEA', 'author_id': 13676, 'author_profile': 'https://Stackoverflow.com/users/13676', 'pm_score': 3, 'selected': False, 'text': '<p>I would recommend <a href="http://www.codeblocks.org/" rel="noreferrer">CodeBlocks</a>.</p>\n\n<p>Highlights:</p>\n\n<ul>\n<li>Open Source! GPLv3, no hidden costs.</li>\n<li>Cross-platform. Runs on Linux, Mac, Windows (uses wxWidgets).</li>\n<li>Written in C++. No interpreted languages or proprietary libs needed.</li>\n<li>Extensible through plugins</li>\n</ul>\n\n<p>Compiler:</p>\n\n<ul>\n<li>Multiple compiler support:\n\n<ul>\n<li>GCC (MingW / GNU GCC)</li>\n<li>MSVC++</li>\n<li>Digital Mars</li>\n<li>Borland C++ 5.5</li>\n<li>Open Watcom</li>\n<li>...and more</li>\n</ul></li>\n</ul>\n'}, {'answer_id': 79354, 'author': 'neuroguy123', 'author_id': 12529, 'author_profile': 'https://Stackoverflow.com/users/12529', 'pm_score': 1, 'selected': False, 'text': '<p>I asked this question before to experience Linux users and they always say Vim and automake. I use Vim as my default editor in Linux and after a while it becomes intuitive. I learned it by working through some small examples while learning C++ so I could learn both at the same time.</p>\n'}, {'answer_id': 79358, 'author': 'brasskazoo', 'author_id': 6340, 'author_profile': 'https://Stackoverflow.com/users/6340', 'pm_score': 6, 'selected': True, 'text': '<p>On Ubuntu, some the IDEs that are available in the repositories are:</p>\n\n<ul>\n<li><a href="http://www.kdevelop.org/" rel="noreferrer">Kdevelop</a></li>\n<li><a href="http://geany.uvena.de/" rel="noreferrer">Geany</a></li>\n<li><a href="http://anjuta.sf.net/" rel="noreferrer">Anjuta</a></li>\n</ul>\n\n<p>There is also: </p>\n\n<ul>\n<li><a href="http://eclipse.org" rel="noreferrer">Eclipse</a> (Recommended you don\'t install from repositories, due to issues with file/folder permissions) </li>\n<li><a href="http://www.codeblocks.org/" rel="noreferrer">Code::blocks</a></li>\n</ul>\n\n<p>And of course, everyone\'s favourite text-based editors:</p>\n\n<ul>\n<li>vi/vim</li>\n<li>emacs</li>\n</ul>\n\n<p>Its true that vim and emacs are very powerful tools, but the learning curve is very steep.. </p>\n\n<p>I really don\'t like <strong>Eclipse</strong> that much, I find it buggy and a bit too clunky.<br>\nI\'ve started using <strong>Geany</strong> as a bare-bones but functional and <em>usable</em> IDE. It has a basic code-completion feature, and is a nice, clean [Gnome] interface.<br>\n<strong>Anjuta</strong> I tried for a day, didn\'t like it at all. I didn\'t find it as useful as Geany.</p>\n\n<p><strong>Kdevelop</strong> and <strong>code::blocks</strong> get a bunch of good reviews, but I haven\'t tried them. I use gnome, and I\'m yet to see a KDE app that looks good in gnome (sorry, I\'m sure its a great program).</p>\n\n<p>If only bloodshed dev-c++ was released under linux. That is a fantastic (but windows-only) program. You could always run it under Wine ;)</p>\n\n<p>To a degree, it comes down to personal preference. My advice is to investigate Kdevelop, Geany and code::blocks as a starting point. </p>\n'}, {'answer_id': 79650, 'author': 'f4nt', 'author_id': 14838, 'author_profile': 'https://Stackoverflow.com/users/14838', 'pm_score': 2, 'selected': False, 'text': '<p>Personally, I agree with the kDevelop crowd as well. Eclipse felt a bit bulky and mildly unstable. Something about kDeveloper just always feel right.</p>\n'}, {'answer_id': 79757, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Eclipse isn't bad, but you have to do things Eclipse's way. Eclipse has some built in ideas on directory layout. For a new project, Eclipse is a reasonable choice. Importing an existing project into Eclipse may require some restructuring.</p>\n\n<p>I used to use Eclipse under QNX for C++. The QNX people actually developed the C++ capability, so QNX would have an IDE.</p>\n"}, {'answer_id': 79776, 'author': 'HidekiAI', 'author_id': 7234, 'author_profile': 'https://Stackoverflow.com/users/7234', 'pm_score': 3, 'selected': False, 'text': '<p>My vote is KDevelop (I wish I had more points so I can "vote up", so I could just agree with others indirectly than comment).</p>\n\n<p>I\'ve been using Eclipse for about couple years now for personal use, convincing myself that "since IBM donated it, it must be good", but then I\'ve discovered KDevelop and never turned back. Because I\'m quite spoiled with Microsoft Visual Studio for professional use, thus KDevelop felt the most comfortable to me. </p>\n\n<p>I want to enjoy programming as a hobby, not spend time looking up what <kbd>ctrl</kbd>-<kbd>k</kbd>-<kbd>k</kbd> and <kbd>ctrl</kbd>-<kbd>k</kbd>-<kbd>b</kbd> does. Like others has mentioned, whatever "feels right" to them is the best IDE. For me, KDevelop feels the most comfortable because I can concentrate on coding (I could probably remap the keys to other IDE\'s to make it feel like VS, but as mentioned, I rather invest my time coding, which is more fun).</p>\n'}, {'answer_id': 79872, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>If you're coming from Windows &amp; Visual Studio, you might find Code::Blocks meets your expectations.</p>\n\n<p>That was my experience; I tried a few others first, but they all seemed to expect me to do a lengthy tutorial before I could start doing anything interesting - and with a dozen IDEs to try, that could take days.</p>\n\n<p>With Code::Blocks there were no hoops to jump through, and very little <em>mandatory cruft</em> to learn before I could be productive. I still prefer Visual Studio, but Code::Blocks can open my Visual Studio projects, and it doesn't seem to want me to waste any time, so it's the winningmost *nix IDE for me.</p>\n"}, {'answer_id': 80312, 'author': 'itsadok', 'author_id': 7581, 'author_profile': 'https://Stackoverflow.com/users/7581', 'pm_score': 1, 'selected': False, 'text': '<p>At my old job we used <a href="http://www.slickedit.com" rel="nofollow noreferrer">SlickEdit</a> for C++ development under Debian. It\'s cross-platform and quite powerful.</p>\n\n<p>It\'s not free, though.</p>\n'}, {'answer_id': 80528, 'author': 'Rob', 'author_id': 9236, 'author_profile': 'https://Stackoverflow.com/users/9236', 'pm_score': 2, 'selected': False, 'text': "<p>I use the NetBeans C++ plugin and it's superb. I come from a Visual Studio background and the Netbeans project management is very similar. I tried KDevelop but found it a little flaky (this was 12 months ago, so it is probably better now).</p>\n\n<p>I also struggled with dependencies using KDevelop - i.e. where a program requires a raft of libs to be built first - but Netbeans made this simple.</p>\n\n<p>The only complaint is that being a Java app, it isn't particularly fast - very noticeable when running under VMWare.</p>\n"}, {'answer_id': 80577, 'author': 'wolfie2x', 'author_id': 15156, 'author_profile': 'https://Stackoverflow.com/users/15156', 'pm_score': 2, 'selected': False, 'text': "<p>I was a VisualStudio + VA-X user before I switched to ubuntu, and needed good auto completion and function navigation features in any IDE. </p>\n\n<p>I have tried Netbeans,Eclipse CDT,CodeBlocks,Geany,Anjuta, KDevelop and finally settled for KDevelop since that was the closest I could get to VS+VA-X. </p>\n\n<p>Eclipse &amp; NetBeans are too heavy &amp; sluggish for my taste. Most of the other IDEs have buggy/incomplete/dumb auto completion &amp; other features; or they want to take control of your code and needs to be imported into projects; or they put 101 files in your source folder. Only KDevelop allowed me to have a simple link to my src folder and let me work. auto completion is not brilliant, but better than the others.</p>\n\n<p>KDevelop doesn't blend well with my Gnome, but I can live with it ;)</p>\n"}, {'answer_id': 80585, 'author': 'slashmais', 'author_id': 15161, 'author_profile': 'https://Stackoverflow.com/users/15161', 'pm_score': 2, 'selected': False, 'text': '<p>Ultimate++ [<a href="http://www.ultimatepp.org/index.html]" rel="nofollow noreferrer">http://www.ultimatepp.org/index.html]</a></p>\n\n<p>[edit]<br />\nIt does have it\'s own C++ class libs (as Hernan points out), but nothing stops you from using any other class libs like the SDL, or you can roll your own. You can even use boost if you like, but I must say I find some of the supplied classes &amp; techniques to be more useful.<br /><br />What I appreciate most is it\'s brilliant integration with the debugger and very complete context-sensitive editor. It uses the standard compiler &amp; debugger (gcc, g++, gdb) on Linux and the MS compiler/debugger on that platform.<br /><br />The only (very small) gripe I have is the home-made names for projects (called Nest\'s &amp; so forth). That is unnecessary and may even be off-putting to serious developers, but they are only names &amp; I find I can easily ignore it.</p>\n'}, {'answer_id': 80841, 'author': 'ext', 'author_id': 15244, 'author_profile': 'https://Stackoverflow.com/users/15244', 'pm_score': 0, 'selected': False, 'text': '<p>Emacs works for simple things but I use Eclipse for any larger project.</p>\n'}, {'answer_id': 80879, 'author': 'user14437', 'author_id': 14437, 'author_profile': 'https://Stackoverflow.com/users/14437', 'pm_score': 2, 'selected': False, 'text': "<p>Simply put, Netbeans. You have to try it out. It's so good. It's much better than Eclipse with the CDT plugin.</p>\n"}, {'answer_id': 3540774, 'author': 'tstenner', 'author_id': 73299, 'author_profile': 'https://Stackoverflow.com/users/73299', 'pm_score': 3, 'selected': False, 'text': '<p>I\'m surprised noone has mentioned <a href="http://qt.nokia.com/products/developer-tools" rel="noreferrer">Qt Creator</a>, as it\'s available in most repositories, quite small in size and yet does most things I need very well.</p>\n'}, {'answer_id': 3540830, 'author': 'UncleZeiv', 'author_id': 60531, 'author_profile': 'https://Stackoverflow.com/users/60531', 'pm_score': 1, 'selected': False, 'text': '<p>The problem with most IDEs is that they want to have a certain degree of control on how the project is organized, and this could be a problem if you have to work on that project with other people. In my experience this leads to two series of related problems:</p>\n\n<ul>\n<li><p>If you start a project in a particular IDE, they will layout for you a particular directory structure, file organization, file naming convention, build system, etc. Of course most of these options are customizable, but it\'s not always possible to adhere to specific conventions which you might be required to follow. Projects with a complex build system might be difficult to implement from within the IDE. Moreover, the project might not be suitable for external, independent modification; so for instance, if you are planning to write an opensource application, <em>avoid making the IDE a dependency for the project</em>.</p></li>\n<li><p>If you import a project started elsewhere, chances are it won\'t be very easy to use all the features provided by the IDE. You will have to figure out how to hook the build system, the debugger (as the binaries might not be where expected), etc. This is especially true for large and complex projects.</p></li>\n</ul>\n\n<p>The reason why these ares not a problem under Windows is that Visual Studio is a <em>de-facto standard</em>. Under *nix there\'s a tendency not to impose particular tools/editors when developing a project collaboratively, and this is why these "cross-IDE communication" problems arise.</p>\n\n<p>As a final note, if you learn, say, kdevelop or netbeans, you might have problems if one day you have to work on a machine where installing those is problematic (e.g. you might not have a Java runtime available and you might not be allowed to install it). If you learn (say) Vim + plugins, you are way safer: you can keep your configuration as a .zip file on your webserver and be pretty sure that Vim will always be available everywhere.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79210', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14717/']
79,215
<p>For example, if I have a page located in Views/Home/Index.aspx and a JavaScript file located in Views/Home/Index.js, how do you reference this on the aspx page?</p> <p>The example below doesn't work even though the compiler says the path is correct</p> <pre><code>&lt;script src="Index.js" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>The exact same issue has been posted here in more detail: <a href="http://forums.asp.net/p/1319380/2619991.aspx" rel="nofollow noreferrer">http://forums.asp.net/p/1319380/2619991.aspx</a></p> <p>If this is not currently possible, will it be in the future? If not, how is everyone managing their javascript resources for large Asp.net MVC projects? Do you just create a folder structure in the Content folder that mirrors your View folder structure? YUCK!</p>
[{'answer_id': 79246, 'author': 'Chris Pietschmann', 'author_id': 7831, 'author_profile': 'https://Stackoverflow.com/users/7831', 'pm_score': 2, 'selected': False, 'text': '<p>You can use the VirtualPathUtility.ToAbsolute method like below to convert the app relative url of the .js file to an absolute one that can be written to the page:</p>\n\n<pre><code>&lt;script type="text/javascript" src="&lt;%=VirtualPathUtility.ToAbsolute("~/Views/Home/Index.js") %&gt;"&gt;&lt;/script&gt;\n</code></pre>\n'}, {'answer_id': 79267, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 1, 'selected': False, 'text': "<p>You should have separated folder structure for scripts. For example JavaScript folder under application root. Storing js files with views is not only affects you with path resolving issues but also affects security and permissions thins. Also it's much more easier later to embed JS files as assembly resources if you will decide to deploy some of your application parts separately in future when they are stored in dedicated subfolder. </p>\n"}, {'answer_id': 79772, 'author': 'Vyrotek', 'author_id': 10941, 'author_profile': 'https://Stackoverflow.com/users/10941', 'pm_score': 2, 'selected': True, 'text': '<p>For shared javascript resources using the Content folder makes sense. The issue was I was specifically trying to solve was aspx page specific javascript that would never be reused. </p>\n\n<p>I think what I will just have to do is put the aspx page specific javascript right onto the page itself and keep the shared js resources in the Content folder.</p>\n'}, {'answer_id': 80638, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Here\'s a nice extension method for HtmlHelper:</p>\n\n<pre><code>public static class JavaScriptExtensions\n{\n public static string JavaScript(this HtmlHelper html, string source)\n {\n TagBuilder tagBuilder = new TagBuilder("script");\n tagBuilder.Attributes.Add("type", "text/javascript");\n tagBuilder.Attributes.Add("src", VirtualPathUtility.ToAbsolute(source));\n return tagBuilder.ToString(TagRenderMode.Normal);\n }\n}\n</code></pre>\n\n<p>Use it like this:</p>\n\n<pre><code>&lt;%=Html.JavaScript("~/Content/MicrosoftAjax.js")%&gt;\n</code></pre>\n'}, {'answer_id': 8094695, 'author': 'Pablo Montilla', 'author_id': 83169, 'author_profile': 'https://Stackoverflow.com/users/83169', 'pm_score': 0, 'selected': False, 'text': "<p>If you re-route your pages to a custom RouteHandler, you can check for existence of files before handling the RequestContext to the MvcHandler class.</p>\n\n<p>Example (not complete):</p>\n\n<pre><code>public class RouteHandler : IRouteHandler\n{\n public IHttpHandler \n GetHttpHandler(RequestContext requestContext)\n {\n var request = requestContext.HttpContext.Request;\n\n // Here you should probably make the 'Views' directory appear in the correct place.\n var path = request.MapPath(request.Path); \n if(File.Exists(path)) {\n // This is internal, you probably should make your own version.\n return new StaticFileHandler(requestContext);\n }\n else {\n return new MvcHandler(requestContext);\n }\n }\n}\n</code></pre>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79215', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10941/']
79,229
<p>In your experience, how often should Oracle database statistics be run? Our team of developers recently discovered that statistics hadn't been run our production box in over 2 1/2 months. That sounds like a long time to me, but I'm not a DBA.</p>
[{'answer_id': 79425, 'author': 'Jonathan Rupp', 'author_id': 12502, 'author_profile': 'https://Stackoverflow.com/users/12502', 'pm_score': 4, 'selected': False, 'text': '<p>Whenever the data changes "significantly".</p>\n\n<p>If a table goes from 1 row to 200 rows, that\'s a significant change. When a table goes from 100,000 rows to 150,000 rows, that\'s not a terribly significant change. When a table goes from 1000 rows all with identical values in commonly-queried column X to 1000 rows with nearly unique values in column X, that\'s a significant change.</p>\n\n<p>Statistics store information about item counts and relative frequencies -- things that will let it "guess" at how many rows will match a given criteria. When it guesses wrong, the optimizer can pick a <strong>very</strong> suboptimal query plan.</p>\n'}, {'answer_id': 79539, 'author': 'David Medinets', 'author_id': 219658, 'author_profile': 'https://Stackoverflow.com/users/219658', 'pm_score': 3, 'selected': False, 'text': '<p>What Oracle version are you using? Check this page which refers to Oracle 10:</p>\n\n<p><a href="http://www.acs.ilstu.edu/docs/Oracle/server.101/b10752/stats.htm" rel="noreferrer">http://www.acs.ilstu.edu/docs/Oracle/server.101/b10752/stats.htm</a></p>\n\n<p>It says:</p>\n\n<blockquote>\n <p>The recommended approach to gathering statistics is to allow Oracle to automatically gather the statistics. Oracle gathers statistics on all database objects automatically and maintains those statistics in a regularly-scheduled maintenance job.</p>\n</blockquote>\n'}, {'answer_id': 79560, 'author': 'Joe Skora', 'author_id': 14057, 'author_profile': 'https://Stackoverflow.com/users/14057', 'pm_score': 2, 'selected': False, 'text': '<p>When I was managing a large multi-user planning system backed by Oracle, our DBA had a weekly job that gathered statistics. Also, when we rolled out a significant change that could affect or be affected by statistics, we would force the job to run out of cycle to get things caught up.</p>\n'}, {'answer_id': 87175, 'author': 'Justin Cave', 'author_id': 10397, 'author_profile': 'https://Stackoverflow.com/users/10397', 'pm_score': 1, 'selected': False, 'text': '<p>Make sure to balance the risk that fresh statistics cause undesirable changes to query plans against the risk that stale statistics can themselves cause query plans to change. </p>\n\n<p>Imagine you have a bug database with a table ISSUE and a column CREATE_DATE where the values in the column increase more or less monotonically. Now, assume that there is a histogram on this column that tells Oracle that the values for this column are uniformly distributed between January 1, 2008 and September 17, 2008. This makes it possible for the optimizer to reasonably estimate the number of rows that would be returned if you were looking for all issues created last week (i.e. September 7 - 13). If the application continues to be used and the statistics are never updated, though, this histogram will be less and less accurate. So the optimizer will expect queries for "issues created last week" to be less and less accurate over time and may eventually cause Oracle to change the query plan negatively. </p>\n'}, {'answer_id': 90349, 'author': 'user11318', 'author_id': 11318, 'author_profile': 'https://Stackoverflow.com/users/11318', 'pm_score': 5, 'selected': True, 'text': "<p>At my last job we ran statistics once a week. If I remember correctly, we scheduled them on a Thursday night, and on Friday the DBAs were very careful to monitor the longest running queries for anything unexpected. (Friday was picked because it was often just after a code release, and tended to be a fairly low traffic day.) When they saw a bad query they would find a better query plan and save that one so it wouldn't change again unexpectedly. (Oracle has tools to do this for you automatically, you tell it the query to optimize and it does.)</p>\n\n<p>Many organizations avoid running statistics out of fear of bad query plans popping up unexpectedly. But this usually means that their query plans get worse and worse over time. And when they do run statistics then they encounter a number of problems. The resulting scramble to fix those issues confirms their fears about the dangers of running statistics. But if they ran statistics regularly, used the monitoring tools as they are supposed to, and fixed issues as they came up then they would have fewer headaches, and they wouldn't encounter them all at once.</p>\n"}, {'answer_id': 623588, 'author': 'David Aldridge', 'author_id': 6742, 'author_profile': 'https://Stackoverflow.com/users/6742', 'pm_score': 0, 'selected': False, 'text': '<p>In the case of a data warehouse-type system you can consider collecting no statistics at all, and relying on dynamic sampling (setting optimizer_dynamic_sampling to level 2 or above).</p>\n'}, {'answer_id': 630725, 'author': 'MichaelN', 'author_id': 75756, 'author_profile': 'https://Stackoverflow.com/users/75756', 'pm_score': 2, 'selected': False, 'text': '<p>With 10g and higher version of oracle, up to date statistics on tables and indexes are needed by the optimizer to make "good" execution plan decision. How often you collect statistics is a tricky call. It depends on your application, schema, data rate and business practice. Some third party apps which are written to be backward compatible with older version of oracle do not perform well with the new optimizer. Those application require that tables have no stats so that the db resorts back to rule base execution plan. But on the average oracle recommends that stats be collected on tables with stale statistics. You can set tables to be monitor and check their state and have them analyze if/when stale. Often that is enough, sometime it is not. It really depend on your database. For my database we have a set of OLTP tables that need nightly stats collection to maintain performance. Other tables are analyze once a week. On our large dw database, we analyze as needed as the tables are too large for regular analysis without affecting overall db load and performance. So the correct answer is, it depends on the application, data change and business needs.</p>\n'}, {'answer_id': 16741489, 'author': 'grokster', 'author_id': 502441, 'author_profile': 'https://Stackoverflow.com/users/502441', 'pm_score': 4, 'selected': False, 'text': "<p>Since Oracle 11g statistics are gathered automatically by default.</p>\n\n<p>Two Scheduler windows are predefined upon installation of Oracle Database:</p>\n\n<ul>\n<li>WEEKNIGHT_WINDOW starts at 10 p.m. and ends at 6 a.m. every Monday\nthrough Friday. </li>\n<li>WEEKEND_WINDOW covers whole days Saturday and Sunday.</li>\n</ul>\n\n<p>When statistics were last gathered?</p>\n\n<pre><code>SELECT owner, table_name, last_analyzed FROM all_tables ORDER BY last_analyzed DESC NULLS LAST; --Tables.\nSELECT owner, index_name, last_analyzed FROM all_indexes ORDER BY last_analyzed DESC NULLS LAST; -- Indexes.\n</code></pre>\n\n<p>Status of automated statistics gathering?</p>\n\n<pre><code>SELECT * FROM dba_autotask_client WHERE client_name = 'auto optimizer stats collection';\n</code></pre>\n\n<p>Windows Groups?</p>\n\n<pre><code>SELECT window_group_name, window_name FROM dba_scheduler_wingroup_members;\n</code></pre>\n\n<p>Window Schedules?</p>\n\n<pre><code>SELECT window_name, start_time, duration FROM dba_autotask_schedule;\n</code></pre>\n\n<p>Manually gather Database Statistics in this Schema: </p>\n\n<pre><code>EXEC dbms_stats.gather_schema_stats(ownname=&gt;NULL, cascade=&gt;TRUE); -- cascade=&gt;TRUE means include Table Indexes too.\n</code></pre>\n\n<p>Manually gather Database Statistics in all Schemas!</p>\n\n<pre><code>-- Probably need to CONNECT / AS SYSDBA\nEXEC dbms_stats.gather_database_stats;\n</code></pre>\n"}, {'answer_id': 25973507, 'author': 'Chion', 'author_id': 4065146, 'author_profile': 'https://Stackoverflow.com/users/4065146', 'pm_score': 0, 'selected': False, 'text': '<p>Generally it\'s not recommended to gather statistics so frequent on the whole database unless you have a strong justification for that, such as a bulk insert or big data change happen frequently on the database.\ngathering statistics on the database in this frequency MAY change the queries execution plan to a new poor execution plans, the thing may cost you much time trying to tune every query affected by the new poor plans, this is why you should test the impact of gathering new statistics on a test database, or in case you don\'t have the time or the man power for that, at least you should keep a fallback plan by backing up the original statics before you gather new ones, so in case you gather a new statistics and then the queries didn\'t perform as expected, you can easily restore back the original statistics.</p>\n\n<p>There is a very useful script can help you backup original statistics and gather new ones and provide you with SQL command you can use to restore back the original statics in case the thing didn\'t go as expected after gathering new statistics. You can find the script in this link:\n<a href="http://dba-tips.blogspot.com/2014/09/script-to-ease-gathering-statistics-on.html" rel="nofollow">http://dba-tips.blogspot.com/2014/09/script-to-ease-gathering-statistics-on.html</a></p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79229', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
79,241
<p>When working with tables in Oracle, how do you know when you are setting up a good index versus a bad index?</p>
[{'answer_id': 79257, 'author': 'Matt Rogish', 'author_id': 2590, 'author_profile': 'https://Stackoverflow.com/users/2590', 'pm_score': 2, 'selected': False, 'text': '<p>Here\'s a great SQL Server article:\n<a href="http://www.sql-server-performance.com/tips/optimizing_indexes_general_p1.aspx" rel="nofollow noreferrer">http://www.sql-server-performance.com/tips/optimizing_indexes_general_p1.aspx</a></p>\n\n<p>Although the mechanics won\'t work on Oracle, the tips are very apropos (minus the thing on clustered indexes, which don\'t quite work the same way in Oracle).</p>\n'}, {'answer_id': 79311, 'author': 'Frater', 'author_id': 14746, 'author_profile': 'https://Stackoverflow.com/users/14746', 'pm_score': 6, 'selected': True, 'text': '<p>This depends on what you mean by \'good\' and \'bad\'. Basically you need to realise that every index you add will increase performance on any search by that column (so adding an index to the \'lastname\' column of a person table will increase performance on queries that have "where lastname = " in them) but decrease write performance across the whole table.</p>\n\n<p>The reason for this is when you add or update a row, it must add-to or update both the table itself and every index that row is a member of. So if you have five indexes on a table, each addition must write to six places - five indexes and the table - and an update may be touching up to six places in the worst case.</p>\n\n<p>Index creation is a balancing act then between query speed and write speed. In some cases, such as a datamart that is only loaded with data once a week in an overnight job but queried thousands of times daily, it makes a great deal of sense to overload with indexes and speed the queries up as much as possible. In the case of online transaction processing systems however, you want to try and find a balance between them.</p>\n\n<p>So in short, add indexes to columns that are used a lot in select queries, but try to avoid adding too many and so add the most-used columns first.</p>\n\n<p>After that its a matter of load testing to see how the performance reacts under production conditions, and a lot of tweaking to find an aceeptable balance.</p>\n'}, {'answer_id': 79318, 'author': 'Christopher Dolan', 'author_id': 9418, 'author_profile': 'https://Stackoverflow.com/users/9418', 'pm_score': -1, 'selected': False, 'text': '<p>A good index is something that you can rely on to be unique for a specific table row.</p>\n\n<p>One commonly used index scheme is the use of numbers which increment by 1 for each row in the table. Every row will end up having a different number index.</p>\n'}, {'answer_id': 79366, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': "<p>Fields that are diverse, highly specific, or unique make good indexes. Such as dates and timestamps, unique incrementing numbers (commonly used as primary keys), person's names, license plate numbers, etc...</p>\n\n<p>A counterexample would be gender - there are only two common values, so the index doesn't really help reduce the number of rows that must be scanned.</p>\n\n<p>Full-length descriptive free-form strings make poor indexes, as whoever is performing the query rarely knows the exact value of the string.</p>\n\n<p>Linearly-ordered data (such as timestamps or dates) are commonly used as a clustered index, which forces the rows to be stored in index order, and allows in-order access, greatly speeding range queries (e.g. 'give me all the sales orders between October and December'). In such a case the DB engine can simply seek to the first record specified by the range and start reading sequentially until it hits the last one.</p>\n"}, {'answer_id': 83678, 'author': 'SquareCog', 'author_id': 15962, 'author_profile': 'https://Stackoverflow.com/users/15962', 'pm_score': 2, 'selected': False, 'text': '<p>@Infamous Cow -- you must be thinking of primary keys, not indexes.</p>\n\n<p>@Xenph Yan --\nSomething others have not touched on is choosing what <em>kind</em> of index to create. Some databases don\'t really give you much of a choice, but some have a large variety of possible indexes. B-trees are the <em>default</em> but not always the best kind of index. Choosing the right structure depends on the kind of usage you expect to have. What kind of queries do you need to support most? Are you in a read-mostly or write-mostly environment? Are your writes dominated by updates or appends? Etc, etc.</p>\n\n<p>A description of the different types of indexes and their pros and cons is available here: <a href="https://web.archive.org/web/20080701193711/http://20bits.com/2008/05/13/interview-questions-database-indexes/" rel="nofollow noreferrer">http://20bits.com/2008/05/13/interview-questions-database-indexes/</a> . </p>\n'}, {'answer_id': 166669, 'author': 'WW.', 'author_id': 14663, 'author_profile': 'https://Stackoverflow.com/users/14663', 'pm_score': 0, 'selected': False, 'text': '<p>Some rules of thumb if you are trying to improve a particular query.</p>\n\n<p>For a particular table (where you think Oracle should start) try indexing each of the columns used in the WHERE clause. Put columns with equality first, followed by columns with a range or like.</p>\n\n<p>For example:</p>\n\n<pre><code>WHERE CompanyCode = ? AND Amount BETWEEN 100 AND 200\n</code></pre>\n\n<p>If columns are very large in size (e.g. you are storing some XML or something) you may be better off leaving them out of the index. This will make the index smaller to scan, assuming you have to go to the table row to satisfy the select list anyway.</p>\n\n<p>Alternatively, if all the values in the SELECT and WHERE clauses are in the index Oracle will not need to access the table row. So sometimes it is a good idea to put the selected values last in the index and avoid a table access all together.</p>\n\n<p>You could write a book about the best ways to index - look for author Jonathan Lewis.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79241', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
79,244
<p>How to make sure that all derived C++/CLI classes will override the ICloneable::Clone() method of the base class?</p> <p>Do you think I should worry about this? Or this is not a responsibility of the base class' writer?</p> <p><strong>Amendment:</strong> Sorry, I forgot to mention that the base class is a non-abstract class.</p>
[{'answer_id': 79262, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 1, 'selected': False, 'text': '<p>Declare the Clone() method as abstract. This should work even when the parent class does have a concrete implementation.</p>\n\n<p>Of course, the risk when enforcing such things is that the writer of the derived class will become annoyed, say "I\'m not going to use Clone anyway" and does something like a bytewise copy, or even a "return this", to get rid of the errors.</p>\n'}, {'answer_id': 79324, 'author': 'Milan Babuškov', 'author_id': 14690, 'author_profile': 'https://Stackoverflow.com/users/14690', 'pm_score': 2, 'selected': False, 'text': '<p>Declare it pure virtual in the base class.<br></p>\n\n<p>class Base<br> \n{<br>\n...<br>\nvitual void Clone() = 0;<br>\n};</p>\n'}, {'answer_id': 79327, 'author': 'Philip Rieck', 'author_id': 12643, 'author_profile': 'https://Stackoverflow.com/users/12643', 'pm_score': 2, 'selected': False, 'text': '<p>Well, I can\'t say if this is the responsibility of the base class or not, and won\'t get into the perils of inheritance based contracts here.</p>\n\n<p>In any case, you <em>can</em> force some class to override a method - "Clone()" for example, by making it a <em>pure virtual</em> member of an abstract class</p>\n\n<pre><code>public ref class ClonableBase abstract\n{\n public:\n virtual void Clone() = 0;\n}\n</code></pre>\n\n<p>note the "abstract" and the "=0;". The abstract allows the class to contain pure virtual members without warning, and the =0; means that this method is pure virtual - that is, it doesn\'t contain a body. Note that you can not instantiate an abstract class.</p>\n\n<p>Now you can</p>\n\n<pre><code>public ref class ClonableChild : public ClonableBase\n{\n public:\n virtual void Clone();\n}\n\nvoid ConableChild::Clone()\n{\n //some stuff here\n}\n</code></pre>\n\n<p>If you do NOT have the Clone override in ClonableChild, you get a compiler error.</p>\n'}, {'answer_id': 79331, 'author': 'Jon', 'author_id': 12261, 'author_profile': 'https://Stackoverflow.com/users/12261', 'pm_score': -1, 'selected': False, 'text': "<p>Thomas is correct but one way you would make that class abstract is to define a pure virtual method.</p>\n\n<p>This is done by saying:</p>\n\n<p>virtual void Clone() = 0;</p>\n\n<p>Unless the derived class implements Clone they won't be able to instantiate it so they'll have little choice if they want their class to be useful.</p>\n"}, {'answer_id': 79437, 'author': 'metao', 'author_id': 11484, 'author_profile': 'https://Stackoverflow.com/users/11484', 'pm_score': 1, 'selected': False, 'text': '<pre><code>class Base\n{\n...\nvirtual void Clone() = 0;\n};\n</code></pre>\n\n<p>is correct.</p>\n\n<p>If you want some default behaviour for Clone, try:</p>\n\n<pre><code>class Base\n{\n...\nvirtual void Clone()\n{ \n ...\n doClone();\n ...\n};\n\n...\n\nprivate:\nvirtual void doClone() = 0;\n};\n</code></pre>\n'}, {'answer_id': 79945, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 0, 'selected': False, 'text': "<blockquote>\n <p><strong>Amendment:</strong> Sorry, I forgot to mention that the base class is a non-abstract class.</p>\n</blockquote>\n\n<p>In this new light, I'm pretty sure that you do not want to force anyone to override Clone() at all. For example, if my derived class does not add any fields it probably does not need its own specialized Clone() method.</p>\n"}, {'answer_id': 80068, 'author': 'Eric W', 'author_id': 14972, 'author_profile': 'https://Stackoverflow.com/users/14972', 'pm_score': 1, 'selected': False, 'text': '<p>If the base class is non-abstract, then there is no way to force it to be overridden at compile time. The best you can probably do is something like:</p>\n\n<pre><code>virtual void Clone()\n{\n throw gcnew NotSupportedException();\n}\n</code></pre>\n\n<p>With this, derived classes would have to override the method or your application will encounter a NotSupportedException. This at least would make it immediately obvious during testing that something was incorrect. It would give you something to look for so that you know when you encounter a class that did not correctly override Clone. Depending on how much control you have over derived classes, this could be important for robustness.</p>\n'}, {'answer_id': 80108, 'author': 'metamal', 'author_id': 14385, 'author_profile': 'https://Stackoverflow.com/users/14385', 'pm_score': 0, 'selected': False, 'text': '<p>After some pondering I found this solution:</p>\n\n<pre><code>Object^ BaseClass::Clone()\n{\n if(this-&gt;GetType() != BaseClass::typeid)\n {\n throw gcnew System::NotImplementedException("The Clone() method is not implemented for " + this-&gt;GetType()-&gt;ToString() + "!");\n }\n\n BaseClass^ base = gcnew BaseClass();\n ... // Copy the fields here\n return base;\n}\n</code></pre>\n\n<p>It throws NotImplementedException if you attempt to Clone an instance of a derived class that hasn\'t overridden the Clone() method of the base class.</p>\n'}, {'answer_id': 82127, 'author': 'ugasoft', 'author_id': 10120, 'author_profile': 'https://Stackoverflow.com/users/10120', 'pm_score': 0, 'selected': False, 'text': '<p>read <a href="http://www.gotw.ca/gotw/071.htm" rel="nofollow noreferrer">this</a> by herb sutter. It\'s exactly what you are asking</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79244', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14385/']
79,248
<p>What are the characteristics of a multitasking operating system?<br> What makes it multitasking?<br> Are there non-multitasking operating systems?</p>
[{'answer_id': 79268, 'author': 'Brian R. Bondy', 'author_id': 3153, 'author_profile': 'https://Stackoverflow.com/users/3153', 'pm_score': 2, 'selected': False, 'text': "<p>A multi tasking operating systems is:</p>\n\n<p>An operating system that gives you the perception of 2 or more tasks/jobs/processes running at the same time. It does this by dividing system resources amongst these tasks/jobs/processes. And switching between the tasks/jobs/processes while they are executing very fast over and over again.</p>\n\n<p>Yes there are non multi tasking operating systems, example: commodore 64's OS (Commodore BASIC 2.0). Probably some custom made software for some companies. Perhaps like an ATM machine, or movie theater stub ticket system.</p>\n"}, {'answer_id': 79271, 'author': 'André Chalella', 'author_id': 4850, 'author_profile': 'https://Stackoverflow.com/users/4850', 'pm_score': 1, 'selected': False, 'text': '<p>A multitasking OS is able to manage various processes side-by-side. One particular ability is the sharing of CPU time among the processes.</p>\n\n<p>Yes, there are plenty of non-multitasking OSs. Back in time, they were the rule: MSDOS, for example.</p>\n'}, {'answer_id': 79283, 'author': 'Chris Upchurch', 'author_id': 2600, 'author_profile': 'https://Stackoverflow.com/users/2600', 'pm_score': 5, 'selected': True, 'text': '<blockquote>\n <p>What are the characteristics of a multitasking operating system? What makes it multitasking?</p>\n</blockquote>\n\n<p>Multitasking operating systems allow more than one program to run at a time. They can support either preemptive multitasking, where the OS doles out time to applications (virtually all modern OSes) or cooperative multitasking, where the OS waits for the program to give back control (Windows 3.x, Mac OS 9 and earlier).</p>\n\n<blockquote>\n <p>Are there non-multitasking operating systems?</p>\n</blockquote>\n\n<p>Any OS that only allows one thing to be done at a time (DOS for instance).</p>\n'}, {'answer_id': 79290, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m not sure if you\'re supposed to ask your homework questions here... ;)</p>\n\n<p>A multitasking OS allows you to run multiple processes (tasks) "simultaneously". They do not actually run at the same time, of course, since there is only one CPU. What happens is that one process runs for a while, then the OS breaks in (through an interrupt), stores away the state (context) of the current process, restores the context of another, and allows that other process to run for a while, etcetera.</p>\n\n<p>MS-DOS is an example of a non-multitasking OS: as long as you\'re playing Commander Keen, no other tasks can run on your computer (including the DOS shell itself).</p>\n'}, {'answer_id': 79299, 'author': 'Ben Collins', 'author_id': 3279, 'author_profile': 'https://Stackoverflow.com/users/3279', 'pm_score': 1, 'selected': False, 'text': '<p>From the dinosaur OS book ("Applied operating System Concepts"):</p>\n\n<p><strong>Time sharing,</strong> or <strong>multitasking</strong>, is a logical extension of multiprogramming. The CPU executes multiple jobs by switching among them, but the switches occur so frequently that the users can interact with each program while it is running.</p>\n'}, {'answer_id': 79315, 'author': 'Vinko Vrsalovic', 'author_id': 5190, 'author_profile': 'https://Stackoverflow.com/users/5190', 'pm_score': 0, 'selected': False, 'text': '<p>A (preemptive) multitasking OS is able to run more than one process simultaneously and has control over which process is using the CPU and other resources at each time, as opposed to a cooperative multitasking OS where the processes had to voluntarily relinquish the CPU, leading to hangs and crashes. </p>\n\n<p>Usually, modern multitasking OSs also provide memory isolation between processes and support different security levels, allowing OS code to do things user code cannot.</p>\n'}, {'answer_id': 79337, 'author': 'Jörg W Mittag', 'author_id': 2988, 'author_profile': 'https://Stackoverflow.com/users/2988', 'pm_score': 0, 'selected': False, 'text': "<p>There's a popular non-multitasking OS that's not been listed yet: PalmOS.</p>\n"}, {'answer_id': 79357, 'author': 'Chris Pietschmann', 'author_id': 7831, 'author_profile': 'https://Stackoverflow.com/users/7831', 'pm_score': 0, 'selected': False, 'text': '<p>A Multi-Tasking Operating System would be an OS that allows for the simultaneous execution of multiple (more than 1) processes. Operating Systems that you are used to, like Unix, Windows and OSX are multi-tasking operating systems.</p>\n\n<p>An example of a non-multi-tasking operating system would be MS-DOS. Although you could get multiple processes to run simultaneously under MS-DOS, with the help of Windows 3.1 or Windows 9x, the OS itself was non-multi-tasking.</p>\n\n<p>For more information regarding Computer Multi-Tasking you may want to check out the wikipedia page: <a href="http://en.wikipedia.org/wiki/Computer_multitasking" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Computer_multitasking</a></p>\n'}, {'answer_id': 79363, 'author': 'Benoit', 'author_id': 10703, 'author_profile': 'https://Stackoverflow.com/users/10703', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://en.wikipedia.org/wiki/Computer_multitasking" rel="nofollow noreferrer">Wikipedia</a> has a pretty good lowdown on multitasking.</p>\n'}, {'answer_id': 3474020, 'author': 'kunjam aggarwal', 'author_id': 417480, 'author_profile': 'https://Stackoverflow.com/users/417480', 'pm_score': 0, 'selected': False, 'text': '<p>A multi-tasking o/s is an o/s that allows a user to simultaneously run various tasks at the same time. Actually it is not so because there is only one cpu. The concept behind this is time sharing. The operating system divides cpu time among various tasks, but this time is very small (nanoseconds) that the user feels that all programs or tasks are running simultaneously.</p>\n'}, {'answer_id': 3501511, 'author': 'vivek', 'author_id': 422738, 'author_profile': 'https://Stackoverflow.com/users/422738', 'pm_score': 0, 'selected': False, 'text': "<p>It's just an illusion for the user that parallel working is done, but not exactly like this.</p>\n"}, {'answer_id': 3610651, 'author': 'ashley', 'author_id': 436098, 'author_profile': 'https://Stackoverflow.com/users/436098', 'pm_score': 1, 'selected': False, 'text': '<p><strong>Timesharing/multiasking</strong> is a logical extension of multiprogramming.A multi-tasking os allows multiple jobs to be executed simultaneously by switching amoung them.Usually CPU process only one task at a time but the switcthing is so fast that it looks like CPU is executing multiple processes at a time.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79248', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10703/']
79,258
<p>Is there a tool that will find for me all the css classes that I am referencing in my HTML that don't actually exist?</p> <p>ie. if I have &lt;ul class="topnav" /&gt; in my HTML and the topnav class doesn't exist in any of the referenced CSS files.</p> <p>This is similar to <a href="https://stackoverflow.com/questions/33242/how-can-i-find-unused-images-and-css-styles-in-a-website">SO#33242</a>, which asks how to find unused CSS styles. This isn't a duplicate, as that question asks which CSS classes are not used. This is the opposite problem.</p>
[{'answer_id': 79306, 'author': 'Milan Babuškov', 'author_id': 14690, 'author_profile': 'https://Stackoverflow.com/users/14690', 'pm_score': 1, 'selected': False, 'text': '<p>Error Console in Firefox. Although, it gives <strong>all</strong> CSS errors, so you have to read through it.</p>\n'}, {'answer_id': 79321, 'author': 'Swati', 'author_id': 12682, 'author_profile': 'https://Stackoverflow.com/users/12682', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://www.jetbrains.com/idea/features/html_css_editor.html" rel="nofollow noreferrer" title="IntelliJ Idea">IntelliJ Idea</a> tool does that as well. </p>\n'}, {'answer_id': 79433, 'author': 'mislav', 'author_id': 11687, 'author_profile': 'https://Stackoverflow.com/users/11687', 'pm_score': 3, 'selected': True, 'text': '<p>You can put this JavaScript in the page that can perform this task for you:</p>\n\n<pre><code>function forItems(a, f) {\n for (var i = 0; i &lt; a.length; i++) f(a.item(i))\n}\n\nfunction classExists(className) {\n var pattern = new RegExp(\'\\\\.\' + className + \'\\\\b\'), found = false\n\n try {\n forItems(document.styleSheets, function(ss) {\n // decompose only screen stylesheets\n if (!ss.media.length || /\\b(all|screen)\\b/.test(ss.media.mediaText))\n forItems(ss.cssRules, function(r) {\n // ignore rules other than style rules\n if (r.type == CSSRule.STYLE_RULE &amp;&amp; r.selectorText.match(pattern)) {\n found = true\n throw "found"\n }\n })\n })\n } catch(e) {}\n\n\n return found\n}\n</code></pre>\n'}, {'answer_id': 97654, 'author': 'Buzz', 'author_id': 13113, 'author_profile': 'https://Stackoverflow.com/users/13113', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://www.sitepoint.com/dustmeselectors/" rel="nofollow noreferrer">This Firefox extension</a> is does exactly what you want.</p>\n\n<p>It locates all unused selectors. </p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79258', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4640/']
79,264
<p>Is there a program or API I can code against to extract individual files from a Windows Vista Complete PC Backup image?</p> <p>I like the idea of having a complete image to restore from, but hate the idea that I have to make two backups, one for restoring individual files, and one for restoring my computer in the event of a catastrophic failure.</p>
[{'answer_id': 79306, 'author': 'Milan Babuškov', 'author_id': 14690, 'author_profile': 'https://Stackoverflow.com/users/14690', 'pm_score': 1, 'selected': False, 'text': '<p>Error Console in Firefox. Although, it gives <strong>all</strong> CSS errors, so you have to read through it.</p>\n'}, {'answer_id': 79321, 'author': 'Swati', 'author_id': 12682, 'author_profile': 'https://Stackoverflow.com/users/12682', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://www.jetbrains.com/idea/features/html_css_editor.html" rel="nofollow noreferrer" title="IntelliJ Idea">IntelliJ Idea</a> tool does that as well. </p>\n'}, {'answer_id': 79433, 'author': 'mislav', 'author_id': 11687, 'author_profile': 'https://Stackoverflow.com/users/11687', 'pm_score': 3, 'selected': True, 'text': '<p>You can put this JavaScript in the page that can perform this task for you:</p>\n\n<pre><code>function forItems(a, f) {\n for (var i = 0; i &lt; a.length; i++) f(a.item(i))\n}\n\nfunction classExists(className) {\n var pattern = new RegExp(\'\\\\.\' + className + \'\\\\b\'), found = false\n\n try {\n forItems(document.styleSheets, function(ss) {\n // decompose only screen stylesheets\n if (!ss.media.length || /\\b(all|screen)\\b/.test(ss.media.mediaText))\n forItems(ss.cssRules, function(r) {\n // ignore rules other than style rules\n if (r.type == CSSRule.STYLE_RULE &amp;&amp; r.selectorText.match(pattern)) {\n found = true\n throw "found"\n }\n })\n })\n } catch(e) {}\n\n\n return found\n}\n</code></pre>\n'}, {'answer_id': 97654, 'author': 'Buzz', 'author_id': 13113, 'author_profile': 'https://Stackoverflow.com/users/13113', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://www.sitepoint.com/dustmeselectors/" rel="nofollow noreferrer">This Firefox extension</a> is does exactly what you want.</p>\n\n<p>It locates all unused selectors. </p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79264', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2581/']
79,266
<p>When attempting to understand how a SQL statement is executing, it is sometimes recommended to look at the explain plan. What is the process one should go through in interpreting (making sense) of an explain plan? What should stand out as, "Oh, this is working splendidly?" versus "Oh no, that's not right."</p>
[{'answer_id': 79294, 'author': 'Steven A. Lowe', 'author_id': 9345, 'author_profile': 'https://Stackoverflow.com/users/9345', 'pm_score': 1, 'selected': False, 'text': '<p>look at the percentage of time spent in each subsection of the plan, and consider what the engine is doing. for example, if it is scanning a table, consider putting an index on the field(s) that is is scanning for</p>\n'}, {'answer_id': 79296, 'author': 'Tom Leys', 'author_id': 11440, 'author_profile': 'https://Stackoverflow.com/users/11440', 'pm_score': 2, 'selected': False, 'text': '<p>The output of the explain tells you how long each step has taken. The first thing is to find the steps that have taken a long time and understand what they mean. Things like a sequential scan tell you that you need better indexes - it is mostly a matter of research into your particular database and experience.</p>\n'}, {'answer_id': 79300, 'author': 'convex hull', 'author_id': 10747, 'author_profile': 'https://Stackoverflow.com/users/10747', 'pm_score': 2, 'selected': False, 'text': '<p>One "Oh no, that\'s not right" is often in the form of a <strong>table scan</strong>. Table scans don\'t utilize any special indexes and can contribute to purging of every useful in memory caches. In postgreSQL, for example, you will find it looks like this.</p>\n\n<pre><code>Seq Scan on my_table (cost=0.00..15558.92 rows=620092 width=78)\n</code></pre>\n\n<p>Sometimes table scans are ideal over, say, using an index to query the rows. However, this is one of those red-flag patterns that you seem to be looking for.</p>\n'}, {'answer_id': 79309, 'author': 'Jonathan Rupp', 'author_id': 12502, 'author_profile': 'https://Stackoverflow.com/users/12502', 'pm_score': 2, 'selected': False, 'text': '<p>Basically, you take a look at each operation and see if the operations "make sense" given your knowledge of how it should be able to work.</p>\n\n<p>For example, if you\'re joining two tables, A and B on their respective columns C and D (A.C=B.D), and your plan shows a clustered index scan (SQL Server term -- not sure of the oracle term) on table A, then a nested loop join to a series of clustered index seeks on table B, you might think there was a problem. In that scenario, you might expect the engine to do a pair of index scans (over the indexes on the joined columns) followed by a merge join. Further investigation might reveal bad statistics making the optimizer choose that join pattern, or an index that doesn\'t actually exist.</p>\n'}, {'answer_id': 79326, 'author': 'dpollock', 'author_id': 7884, 'author_profile': 'https://Stackoverflow.com/users/7884', 'pm_score': 1, 'selected': False, 'text': '<p>I mainly look for index or table scans. This usually tells me I\'m missing an index on an important column that\'s in the where statement or join statement.</p>\n\n<p>From <a href="http://www.sql-server-performance.com/tips/query_execution_plan_analysis_p1.aspx" rel="nofollow noreferrer">http://www.sql-server-performance.com/tips/query_execution_plan_analysis_p1.aspx</a>:</p>\n\n<blockquote>\n <p>If you see any of the following in an\n execution plan, you should consider\n them warning signs and investigate\n them for potential performance\n problems. Each of them are less than\n ideal from a performance perspective.</p>\n\n<pre><code>* Index or table scans: May indicate a need for better or additional indexes.\n* Bookmark Lookups: Consider changing the current clustered index,\n consider using a covering index, limit\n the number of columns in the SELECT\n statement.\n* Filter: Remove any functions in the WHERE clause, don\'t include wiews\n in your Transact-SQL code, may need\n additional indexes.\n* Sort: Does the data really need to be sorted? Can an index be used to\n avoid sorting? Can sorting be done at\n the client more efficiently? \n</code></pre>\n \n <p>It is not always possible to avoid\n these, but the more you can avoid\n them, the faster query performance\n will be.</p>\n</blockquote>\n'}, {'answer_id': 79725, 'author': 'Mark Nold', 'author_id': 4134, 'author_profile': 'https://Stackoverflow.com/users/4134', 'pm_score': 3, 'selected': False, 'text': '<p>The two examples below show a FULL scan and a FAST scan using an INDEX.</p>\n\n<p>It\'s best to concentrate on your Cost and Cardinality. Looking at the examples the use of the index reduces the Cost of running the query.</p>\n\n<p>It\'s a bit more complicated (and i don\'t have a 100% handle on it) but basically the Cost is a function of CPU and IO cost, and the Cardinality is the number of rows Oracle expects to parse. Reducing both of these is a good thing.</p>\n\n<p>Don\'t forget that the Cost of a query can be influenced by your query and the Oracle optimiser model (eg: COST, CHOOSE etc) and how often you run your statistics.</p>\n\n<p><strong>Example 1:</strong></p>\n\n<p><a href="http://docs.google.com/a/shanghainetwork.org/File?id=dd8xj6nh_7fj3cr8dx_b">SCAN http://docs.google.com/a/shanghainetwork.org/File?id=dd8xj6nh_7fj3cr8dx_b</a></p>\n\n<p><strong>Example 2 using Indexes:</strong></p>\n\n<p><a href="http://docs.google.com/a/fukuoka-now.com/File?id=dd8xj6nh_9fhsqvxcp_b">INDEX http://docs.google.com/a/fukuoka-now.com/File?id=dd8xj6nh_9fhsqvxcp_b</a></p>\n\n<p>And as already suggested, watch out for TABLE SCAN. You can generally avoid these.</p>\n'}, {'answer_id': 80342, 'author': 'decibel', 'author_id': 11116, 'author_profile': 'https://Stackoverflow.com/users/11116', 'pm_score': 2, 'selected': False, 'text': "<p>Looking for things like sequential scans can be somewhat useful, but the reality is in the numbers... except when the numbers are just estimates! What is usually <strong>far</strong> more useful than looking at a query <em>plan</em> is looking at the actual <em>execution</em>. In Postgres, this is the difference between EXPLAIN and EXPLAIN ANALYZE. EXPLAIN ANALYZE actually executes the query, and gets real timing information for every node. That lets you see what's <em>actually</em> happening, instead of what the planner <em>thinks</em> will happen. Many times you'll find that a sequential scan isn't an issue at all, instead it's something else in the query.</p>\n\n<p>The other key is identifying what the actual expensive step is. Many graphical tools will use different sized arrows to indicate how much different parts of the plan cost. In that case, just look for steps that have thin arrows coming in and a thick arrow leaving. If you're not using a GUI you'll need to eyeball the numbers and look for where they suddenly get much larger. With a little practice it becomes fairly easy to pick out the problem areas.</p>\n"}, {'answer_id': 81802, 'author': 'AJ.', 'author_id': 7211, 'author_profile': 'https://Stackoverflow.com/users/7211', 'pm_score': -1, 'selected': False, 'text': '<h2>Rules of Thumb</h2>\n<p>(you probably want to read up on the details too:</p>\n<ul>\n<li><a href="http://download.oracle.com/docs/cd/B28359_01/server.111/b28274/ex_plan.htm#PFGRF009" rel="nofollow noreferrer">Oracle Docs</a></li>\n<li><a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:231814117467" rel="nofollow noreferrer">ASKTOM</a></li>\n<li><a href="http://www.sql-server-performance.com/tips/query_execution_plan_analysis_p1.aspx" rel="nofollow noreferrer">SQL Server Docs</a><br />\n)</li>\n</ul>\n<h3>Bad</h3>\n<p>Table Scans of Several Large Tables</p>\n<h3>Good</h3>\n<p>Using a unique index<br />\nIndex includes all required fields</p>\n<h3>Most Common Win</h3>\n<p>In about 90% of performance problems I have seen, the easiest win is to break up a query with lots (4 or more) of tables into 2 smaller queries and a temporary table.</p>\n'}, {'answer_id': 98580, 'author': 'EvilTeach', 'author_id': 7734, 'author_profile': 'https://Stackoverflow.com/users/7734', 'pm_score': 2, 'selected': False, 'text': '<p>Really for issues like these, the best thing to do is <a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:231814117467" rel="nofollow noreferrer">ASKTOM</a>. In particular his answer to that question contains links to the online Oracle doc, where a lot of the those sorts of rules are explained.</p>\n\n<p>One thing to keep in mind, is that explain plans are really best guesses.</p>\n\n<p>It would be a good idea to learn to use sqlplus, and experiment with the AUTOTRACE command. With some hard numbers, you can generally make better decisions.</p>\n\n<p>But you should ASKTOM. He knows all about it :)</p>\n'}, {'answer_id': 101140, 'author': 'Tony Andrews', 'author_id': 18747, 'author_profile': 'https://Stackoverflow.com/users/18747', 'pm_score': 4, 'selected': False, 'text': '<p>This subject is too big to answer in a question like this. You should take some time to read <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/toc.htm" rel="noreferrer">Oracle\'s Performance Tuning Guide</a></p>\n'}, {'answer_id': 157340, 'author': 'David Aldridge', 'author_id': 6742, 'author_profile': 'https://Stackoverflow.com/users/6742', 'pm_score': 7, 'selected': True, 'text': '<p>I shudder whenever I see comments that full tablescans are bad and index access is good. Full table scans, index range scans, fast full index scans, nested loops, merge join, hash joins etc. are simply access mechanisms that must be understood by the analyst and combined with a knowledge of the database structure and the purpose of a query in order to reach any meaningful conclusion.</p>\n\n<p>A full scan is simply the most efficient way of reading a large proportion of the blocks of a data segment (a table or a table (sub)partition), and, while it often can indicate a performance problem, that is only in the context of whether it is an efficient mechanism for achieving the goals of the query. Speaking as a data warehouse and BI guy, my number one warning flag for performance is an index based access method and a nested loop.</p>\n\n<p>So, for the mechanism of how to read an explain plan the Oracle documentation is a good guide: <a href="http://download.oracle.com/docs/cd/B28359_01/server.111/b28274/ex_plan.htm#PFGRF009" rel="noreferrer">http://download.oracle.com/docs/cd/B28359_01/server.111/b28274/ex_plan.htm#PFGRF009</a></p>\n\n<p>Have a good read through the Performance Tuning Guide also.</p>\n\n<p>Also have a google for "cardinality feedback", a technique in which an explain plan can be used to compare the estimations of cardinality at various stages in a query with the actual cardinalities experienced during the execution. Wolfgang Breitling is the author of the method, I believe.</p>\n\n<p>So, bottom line: understand the access mechanisms. Understand the database. Understand the intention of the query. Avoid rules of thumb.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79266', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
79,275
<p>I have a form like this:</p> <pre><code>&lt;form name="mine"&gt; &lt;input type=text name=one&gt; &lt;input type=text name=two&gt; &lt;input type=text name=three&gt; &lt;/form&gt; </code></pre> <p>When user types a value in 'one', I sometimes want to skip the field 'two', depending on what he typed. For example, if user types '123' and uses Tab to move to next field, I want to skip it and go to field three.</p> <p>I tried to use <code>OnBlur</code> and <code>OnEnter</code>, without success. </p> <p><strong>Try 1:</strong></p> <pre><code>&lt;form name="mine"&gt; &lt;input type=text name=one onBlur="if (document.mine.one.value='123') document.three.focus();&gt; &lt;input type=text name=two&gt; &lt;input type=text name=three&gt; &lt;/form&gt; </code></pre> <p><strong>Try 2:</strong></p> <pre><code>&lt;form name="mine"&gt; &lt;input type=text name=one&gt; &lt;input type=text name=two onEnter="if (document.mine.one.value='123') document.three.focus();&gt; &lt;input type=text name=three&gt; &lt;/form&gt; </code></pre> <p>but none of these works. Looks like the browser doesn't allow you to mess with focus while the focus is changing. </p> <p>BTW, all this tried with Firefox on Linux.</p>
[{'answer_id': 79317, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 3, 'selected': True, 'text': '<p>Try to attach tabindex attribute to your elements and then programmaticaly (in javaScript change it):</p>\n\n<pre><code>&lt;INPUT tabindex="3" type="submit" name="mySubmit"&gt;\n</code></pre>\n'}, {'answer_id': 79323, 'author': '17 of 26', 'author_id': 2284, 'author_profile': 'https://Stackoverflow.com/users/2284', 'pm_score': 1, 'selected': False, 'text': '<p>You could use the <a href="http://www.w3schools.com/jsref/jsref_onfocus.asp" rel="nofollow noreferrer">onfocus</a> event on field two, which will be called when it receives focus. At that point, field 1\'s value should be updated and you can perform your check then.</p>\n'}, {'answer_id': 79335, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 1, 'selected': False, 'text': "<p>If you used the method you describe, and they worked, the focus would also change when the user clicks on the field, instead of tabbing to it. I can guarantee you that this would result in a frustrated user. (Why exactly it doesn't work is beyond me.)</p>\n\n<p>Instead, as said before, change the tabindex of the appropriate fields as soon as the content of field one changes.</p>\n"}, {'answer_id': 79345, 'author': 'John Boker', 'author_id': 2847, 'author_profile': 'https://Stackoverflow.com/users/2847', 'pm_score': 0, 'selected': False, 'text': '<pre><code>&lt;form name="mine"&gt;\n &lt;input type="text" name="one" onkeypress="if (mine.one.value == \'123\') mine.three.focus();" /&gt;\n &lt;input type="text" name="two"&gt;\n &lt;input type="text" name="three"&gt;\n&lt;/form&gt;\n</code></pre>\n'}, {'answer_id': 79347, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Try <code>onkeypress</code> instead of <code>onblur</code>. Also, on the <code>onfocus</code> of field two is where you should be sending to three. I'm assuming you don't want them typing in two if one is 123 so you can just check that on two's <code>onfocus</code> and send on to three.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79275', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14690/']
79,292
<p>Can databases (MySQL in particular, any SQL--MS, Oracle, Postgres--in general) do mass updates, and figure out on their own what the new value should be? Say for example I've got a database with information about a bunch of computers, and all of these computers have drives of various sizes--anywhere from 20 to 250 GB. Then one day we upgrade every single computer by adding a 120 GB hard drive. Is there a way to say something like</p> <pre><code>update computers set total_disk_space = (whatever that row's current total_disk_space is plus 120) </code></pre>
[{'answer_id': 79305, 'author': 'Tom Leys', 'author_id': 11440, 'author_profile': 'https://Stackoverflow.com/users/11440', 'pm_score': 2, 'selected': False, 'text': '<p>Yeah:</p>\n\n<pre><code>update computers set total_disk_space = total_disk_space + 120;\n</code></pre>\n'}, {'answer_id': 79313, 'author': 'Stephen Wrighton', 'author_id': 7516, 'author_profile': 'https://Stackoverflow.com/users/7516', 'pm_score': 3, 'selected': False, 'text': "<p>For the entire Table then:</p>\n\n<pre><code>Update Computers \nSet Total_Disk_Space = Total_Disk_Space + 120;\n</code></pre>\n\n<p>If, you only want to update certain ones, then you'd need filters, for example:</p>\n\n<pre><code>Update Computers\nSet Total_Disk_Space = Total_Disk_Space + 120\nWhere PurchaseDate BETWEEN '1/1/2008' AND GETDATE();\n</code></pre>\n"}, {'answer_id': 79329, 'author': 'Matt Haley', 'author_id': 14142, 'author_profile': 'https://Stackoverflow.com/users/14142', 'pm_score': 2, 'selected': False, 'text': "<p>In your example, if total_disk_space is an INT you can use:</p>\n\n<pre><code>UPDATE computers\nSET total_disk_space = total_disk_space + 120;\n</code></pre>\n\n<p>I you're storing character data, then it will be far more interesting.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79292', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14701/']
79,322
<p>The documentation with the module itself is pretty thin, and just tends to point to MOP.</p>
[{'answer_id': 79569, 'author': 'Dave Rolsky', 'author_id': 9832, 'author_profile': 'https://Stackoverflow.com/users/9832', 'pm_score': 6, 'selected': True, 'text': '<p>First you should read through the <a href="http://metacpan.org/pod/Moose::Manual" rel="nofollow noreferrer">Manual</a> if you haven\'t already. Then you can go on to read the <a href="http://metacpan.org/pod/Moose::Cookbook" rel="nofollow noreferrer">Cookbook</a>.</p>\n\n<p>I think the docs are actually pretty good these days, as long as you read the right ones. You <em>really</em> shouldn\'t bother looking at most of the docs for any class name starting with "<code>Moose::Meta</code>" unless you\'re interested in Moose\'s introspection features. I\'ve tried to make this more obvious in the Moose.pm docs, which as of 0.57 tell you to read the <a href="http://metacpan.org/pod/Moose::Manual" rel="nofollow noreferrer">Manual</a> and <a href="http://metacpan.org/pod/Moose::Cookbook" rel="nofollow noreferrer">Cookbook</a> first.</p>\n\n<p>If you\'re coming from a background of doing Perl 5 OO "the old school way", I\'d also suggest taking a look at the <a href="http://metacpan.org/pod/Moose::Manual::Unsweetened" rel="nofollow noreferrer"><code>Moose::Manual::Unsweetened</code></a> document, which compares Moose to equivalent Perl 5 "by hand" code.</p>\n'}, {'answer_id': 80051, 'author': 'Eric Wilhelm', 'author_id': 11580, 'author_profile': 'https://Stackoverflow.com/users/11580', 'pm_score': 3, 'selected': False, 'text': "<p>Once you read the docs Dave mentioned, if you have some insight on how it could have been more approachable or gotten you off on the right foot (or simply been easier to find), perhaps you would like to contribute that to the documentation. The developers cannot really read the introductory documentation from a new user's point of view. So file a bug report (with a patch maybe) against the documentation and/or discuss it on the mailing list or irc channel. That will help the next person in your shoes.</p>\n"}, {'answer_id': 85093, 'author': 'draegtun', 'author_id': 12195, 'author_profile': 'https://Stackoverflow.com/users/12195', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://moose.perl.org" rel="noreferrer">http://moose.perl.org</a> is a good central resource for all things Moose</p>\n'}, {'answer_id': 1634300, 'author': 'Ether', 'author_id': 40468, 'author_profile': 'https://Stackoverflow.com/users/40468', 'pm_score': 2, 'selected': False, 'text': '<p>I found this <a href="http://users.ox.ac.uk/~oliver/data/files/moose-quick-ref.pdf" rel="nofollow noreferrer">Moose Quick Reference sheet</a> invaluable. I\'m always forgetting in which manual section to look up a particular feature.</p>\n'}, {'answer_id': 26519192, 'author': 'Dan Chrostowski', 'author_id': 4077025, 'author_profile': 'https://Stackoverflow.com/users/4077025', 'pm_score': 0, 'selected': False, 'text': '<p>I too am just starting to move on to Moose. Since the term <em>good</em> can be rather subjective, I\'ll just detail what I found was good in these resources. The resources may be more or less helpful depending on your skills/experience in Perl.</p>\n\n<p>I started off at this <a href="http://www.perlmonks.org/?node_id=702738" rel="nofollow" title="Perl Monks">Perl Monks page</a>. And moved straight into the <a href="http://search.cpan.org/perldoc?Moose%3A%3ACookbook" rel="nofollow">Moose::Cookbok</a> link listed at the bottom. There, the author included several more links to pods demonstrating Moose syntax and object-oriented programs. The ordering was put together well; starting with simple and basic OOP with Moose at the top, progressing to more complex examples as you go down the page. The pods are well written, aren\'t overly wordy, and explain each chunk of the code clearly.</p>\n\n<p>I\'m sure once you\'re done with the Cookbook, you could check out whatever else was listed at the Perl Monks page. I\'m still going through the examples in the Cookbook, so I haven\'t checked all the resources listed at Perl Monks, but I\'m sure they\'re good. </p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79322', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11289/']
79,350
<p>I am looking to have 4 Virtual servers(various linux flavors) running on a Windows server 2003 R2 64 bit edition server located at a datacenter. I can also purchase a 2008 server or 32 bit 2k3 if needed. They would each have their own ip address for networking so that they could be publicly accessed. I do not know much about VPS software but have worked with it before.</p>
[{'answer_id': 79378, 'author': 'Joshua', 'author_id': 14768, 'author_profile': 'https://Stackoverflow.com/users/14768', 'pm_score': 0, 'selected': False, 'text': '<p>Unfortunately, the only way you are going to get decent performance is by using Linux as the host and Windows as the guest. The signed driver requirement on x64 essentially prevents any open source implementation from having reasonable performance.</p>\n'}, {'answer_id': 79522, 'author': 'LizB', 'author_id': 13616, 'author_profile': 'https://Stackoverflow.com/users/13616', 'pm_score': 0, 'selected': False, 'text': "<p>If you're going to run 4 virtual servers all of which are going to be linux flavours why wouldn't you run the host in a linux as well?</p>\n\n<p>If for what ever reason you have to use a Windows box, I would say grab 2003 32bit the signed drivers are really only a problem on 2008, but even in 2003 I can't really recommend 64bit unless there is a pressing requirement (like Exchange 2007)</p>\n"}, {'answer_id': 82389, 'author': 'Mike Dimmick', 'author_id': 6970, 'author_profile': 'https://Stackoverflow.com/users/6970', 'pm_score': 3, 'selected': True, 'text': '<p><a href="http://technet.microsoft.com/en-gb/bb738033.aspx" rel="nofollow noreferrer">Virtual Server 2005 R2 SP1</a> is free (registration required) and supports x64 hosts. It does not support x64 guests.</p>\n\n<p>Windows Server 2008 includes Hyper-V, Microsoft\'s new virtualization technology, which supports x64 guests and multiple virtual processors. There are editions without Hyper-V as well, for marginally less money, to satisfy the anti-trust authorities. The Hyper-V <a href="http://support.microsoft.com/?kbid=950050" rel="nofollow noreferrer">update</a> has to be downloaded as it was completed after the rest of Windows Server 2008 was released.</p>\n\n<p><a href="http://www.vmware.com/products/server/" rel="nofollow noreferrer">VMware Server</a> is also free. It supports (experimentally) up to 2 virtual CPUs.</p>\n\n<p>To get best performance you need drivers and patches in the virtual machine which work well with the virtualization environment. In Virtual Server these are called Additions, in Hyper-V they are Integration Components, and for VMware, VMware Tools. Because of the nature of kernel binary compatibility (there are no guarantees), only specific distributions are generally supported.</p>\n\n<ul>\n<li><a href="http://technet.microsoft.com/en-us/virtualserver/bb676671.aspx" rel="nofollow noreferrer">Download Virtual Server Additions for Linux</a></li>\n<li><a href="https://connect.microsoft.com/SelfNomination.aspx?ProgramID=1863&amp;pageType=1&amp;SiteID=495" rel="nofollow noreferrer">Download Hyper-V Linux Integration Components</a></li>\n</ul>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79350', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
79,352
<p>I have a method that can return either a single object or a collection of objects. I want to be able to run object.collect on the result of that method whether or not it is a single object or a collection already. How can i do this?</p> <pre><code>profiles = ProfileResource.search(params) output = profiles.collect do | profile | profile.to_hash end </code></pre> <p>If profiles is a single object, I get a NoMethodError exception when I try to execute collect on that object.</p>
[{'answer_id': 79416, 'author': 'Matt Haley', 'author_id': 14142, 'author_profile': 'https://Stackoverflow.com/users/14142', 'pm_score': 1, 'selected': False, 'text': '<pre><code>profiles = [ProfileResource.search(params)].flatten\noutput = profiles.collect do |profile|\n profile.to_hash\nend\n</code></pre>\n'}, {'answer_id': 79427, 'author': 'ctcherry', 'author_id': 10322, 'author_profile': 'https://Stackoverflow.com/users/10322', 'pm_score': 0, 'selected': False, 'text': '<p>In the <code>search</code> method of the <code>ProfileResource</code> class, always return a collection of objects (usually an Array), even if it contains only one object.</p>\n'}, {'answer_id': 79457, 'author': 'Mike Tunnicliffe', 'author_id': 13956, 'author_profile': 'https://Stackoverflow.com/users/13956', 'pm_score': 4, 'selected': True, 'text': '<p>Careful with the flatten approach, if search() returned nested arrays then unexpected behaviour might result.</p>\n\n<pre><code>profiles = ProfileResource.search(params)\nprofiles = [profiles] if !profiles.respond_to?(:collect)\noutput = profiles.collect do |profile|\n profile.to_hash\nend\n</code></pre>\n'}, {'answer_id': 79502, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': "<p>Here's a one Liner:</p>\n\n<pre><code>[*ProfileResource.search(params)].collect { |profile| profile.to_hash }\n</code></pre>\n\n<p>The trick is the splat (*) that turns both individual elements and enumerables into arguments lists (in this case to the new array operator)</p>\n"}, {'answer_id': 79506, 'author': 'Zakaria', 'author_id': 3370, 'author_profile': 'https://Stackoverflow.com/users/3370', 'pm_score': 0, 'selected': False, 'text': '<p>If the collection is an Array you could use this technique</p>\n\n<pre><code>profiles = [*ProfileResource.search(params)]\noutput = profiles.collect do | profile |\n profile.to_hash\nend\n</code></pre>\n\n<p>That would guaranteed your profiles is always an array.</p>\n'}, {'answer_id': 79512, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<pre><code>profiles = ProfileResource.search(params)\noutput = Array(profiles).collect do |profile|\n profile.to_hash\nend\n</code></pre>\n'}, {'answer_id': 79581, 'author': 'patrickyoung', 'author_id': 3701, 'author_profile': 'https://Stackoverflow.com/users/3701', 'pm_score': 0, 'selected': False, 'text': '<p>You could first check to see if the object responds to the "collect" method by using "pofiles.respond_to?". </p>\n\n<p>From <a href="http://www.ruby-doc.org/docs/ProgrammingRuby/" rel="nofollow noreferrer">Programming Ruby</a></p>\n\n<blockquote>\n <p>obj.respond_to?(\n aSymbol, includePriv=false ) -> true\n or false </p>\n \n <p>Returns true if obj responds to the\n given method. Private methods are\n included in the search only if the\n optional second parameter evaluates to\n true.</p>\n</blockquote>\n'}, {'answer_id': 81655, 'author': 'Farrel', 'author_id': 7889, 'author_profile': 'https://Stackoverflow.com/users/7889', 'pm_score': 0, 'selected': False, 'text': '<p>You can use the Kernel#Array method as well.</p>\n\n<pre><code>profiles = Array(ProfileResource.search(params))\noutput = profiles.collect do | profile |\n profile.to_hash\nend\n</code></pre>\n'}, {'answer_id': 103471, 'author': 'fatgeekuk', 'author_id': 17518, 'author_profile': 'https://Stackoverflow.com/users/17518', 'pm_score': 0, 'selected': False, 'text': '<p>Another way is to realise that Enumerable requires that you supply an each method.</p>\n\n<p>So. you COULD mix in Enumerable to your class and give it a dummy each that works....</p>\n\n<pre>\nclass YourClass\n include Enumerable\n\n ... really important and earth shattering stuff ...\n\n def each\n yield(self) if block_given?\n end\nend\n</pre>\n\n<p>This way, if you get back a single item on its own from the search, the enumerable methods will still work as expected.</p>\n\n<p>This way has the advantage that all the support for it is inside your class, not outside where it has to be duplicated many many times.</p>\n\n<p>Of course, the better way is to change the implementation of search such that it returns an array irrespective of how many items is being returned.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79352', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1486/']
79,356
<p>If I were to want to create a nice looking widget to stay running in the background with a small memory footprint, where would I start building the windows application. It's goal is to keep an updated list of items off of a web service. Similar to an RSS reader.</p> <p>note: The data layer will be connecting through REST, which I already have a C# dll, that I assume will not affect the footprint too much.</p> <p>Obviously i would like to use a nice WPF project, but the ~60,000k initial size is too big.</p> <p>*C# Forms application is about ~20,000k</p> <p>*C++ Forms ~16,000k</p> <p>*CLR or MFC much smaller, under 5</p> <p>Is there a way to strip down the WPF or Forms? and if im stuck using CLR or MFC what would be the easiest way to make it pretty. (my experience with MFC is making very award forms)</p> <p><em>Update: Clarification</em> The above sizes, are the memory being used as the process is ran, not the executable. </p>
[{'answer_id': 79729, 'author': 'Leon Bambrick', 'author_id': 49, 'author_profile': 'https://Stackoverflow.com/users/49', 'pm_score': 0, 'selected': False, 'text': '<p>If you "already have a C# dll" you\'re intending to use then there must be .net already installed on the target machine.</p>\n\n<p>In that case, a C# win forms app need not be anywhere near 20 meg. The smallest hello world type win form would be 7 kilobytes.</p>\n'}, {'answer_id': 79775, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 0, 'selected': False, 'text': "<p>If it must really be as small as possible, use plain C and talk to the Windows API directly.</p>\n\n<p>However, since you're going to have the CLR loaded anyway because of the .NET dll, I would opt for something less painful and simply use C# for the UI as well.</p>\n"}, {'answer_id': 79859, 'author': 'Leon Bambrick', 'author_id': 49, 'author_profile': 'https://Stackoverflow.com/users/49', 'pm_score': 3, 'selected': True, 'text': '<p>re:</p>\n\n<blockquote>\n <p>Update: Clarification The above sizes,\n are the memory being used as the\n process is ran, not the executable.</p>\n</blockquote>\n\n<p>Okay, when you run a tiny C# Win Forms app, the smallest amount of RAM that is reserved for it is around 2 meg, maybe 4 meg. This is just a working set that it creates. It\'s not actively using all of this memory, or anything like it. It just reserves that much space up front so it doesn\'t have to do long/slow/expensive requests for more memory later as needed.</p>\n\n<p>Reserving a smaller size upfront is likely to be a false optimization.</p>\n\n<p>(You can reduce the working set with a pinvoke call if it really matters. see <a href="http://www.pinvoke.net/default.aspx/kernel32.SetProcessWorkingSetSize" rel="nofollow noreferrer">pinvoke for \'set process working set size\'</a> )</p>\n'}, {'answer_id': 1511332, 'author': 'markti', 'author_id': 79749, 'author_profile': 'https://Stackoverflow.com/users/79749', 'pm_score': 0, 'selected': False, 'text': '<p>Why not use Silverlight? Here is an <a href="http://blogs.msdn.com/gavingear/archive/2007/06/07/how-to-create-an-ink-enabled-sidebar-gadget-using-silverlight.aspx" rel="nofollow noreferrer">article</a> that talks about doing just that.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79356', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14753/']
79,360
<p>I've drawn an ellipse in the XZ plane, and set my perspective slightly up on the Y-axis and back on the Z, looking at the center of ellipse from a 45-degree angle, using gluPerspective() to set my viewing frustrum.</p> <p><a href="http://www.flickr.com/photos/rampion/2863703051/" rel="nofollow noreferrer" title="ellipse by rampion, on Flickr"><img src="https://farm4.static.flickr.com/3153/2863703051_a768ed86a9_m.jpg" width="240" height="187" alt="ellipse" /></a></p> <p>Unrotated, the major axis of the ellipse spans the width of my viewport. When I rotate 90-degrees about my line-of-sight, the major axis of the ellipse now spans the height of my viewport, thus deforming the ellipse (in this case, making it appear less eccentric).</p> <p><a href="http://www.flickr.com/photos/rampion/2863703073/" rel="nofollow noreferrer" title="rotated ellipse by rampion, on Flickr"><img src="https://farm4.static.flickr.com/3187/2863703073_24c6549d4b_m.jpg" width="240" height="187" alt="rotated ellipse" /></a></p> <p>What do I need to do to prevent this deformation (or at least account for it), so rotation about the line-of-sight preserves the perceived major axis of the ellipse (in this case, causing it to go beyond the viewport)?</p>
[{'answer_id': 79449, 'author': 'shea241', 'author_id': 14656, 'author_profile': 'https://Stackoverflow.com/users/14656', 'pm_score': 4, 'selected': True, 'text': "<p>It looks like you're using 1.0 as the aspect when you call gluPerspective(). You should use width/height. For example, if your viewport is 640x480, you would use 1.33333 as the aspect argument.</p>\n"}, {'answer_id': 79459, 'author': 'Martin', 'author_id': 2581, 'author_profile': 'https://Stackoverflow.com/users/2581', 'pm_score': 2, 'selected': False, 'text': '<p>According to the OpenGL Spec:</p>\n\n<pre><code>void gluPerspective( GLdouble fovy,\n GLdouble aspect,\n GLdouble zNear,\n GLdouble zFar )\n</code></pre>\n\n<p>Aspect should be a function of your window width and height. Specifically width divided by height (but watch out for division by zero).</p>\n\n<p>Perhaps you are using 1 as the aspect which is not accurate unless your window is a square.</p>\n'}, {'answer_id': 79483, 'author': 'Jeff Hill', 'author_id': 14742, 'author_profile': 'https://Stackoverflow.com/users/14742', 'pm_score': 1, 'selected': False, 'text': '<p>It looks like the aspect parameter on your gluPerspective call need tweaking. See <a href="http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/perspective.html" rel="nofollow noreferrer">The Man Page</a>. If your window were physically square, the aspect ratio would be 1 and your problem would go away. However, your window is rectangular, so the viewing frustum needs to be non-square.</p>\n\n<p>Set the aspect ratio to window_width / window_height, and your ellipse should look correct. Note that you\'ll need to update this whenever the window resizes; if you\'re using GLUT set a <a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/glutReshapeFunc.3.html" rel="nofollow noreferrer">glutReshapeFunc</a> and recalculate the projection matrix in there.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79360', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9859/']
79,367
<p>I have a query:</p> <pre><code>SELECT * FROM Items WHERE column LIKE '%foo%' OR column LIKE '%bar%' </code></pre> <p>How do I order the results?</p> <p>Let's say I have rows that match 'foo' and rows that match 'bar' but I also have a row with 'foobar'.</p> <p>How do I order the returned rows so that the first results are the ones that matched more LIKEs? </p>
[{'answer_id': 79375, 'author': 'Milan Babuškov', 'author_id': 14690, 'author_profile': 'https://Stackoverflow.com/users/14690', 'pm_score': 0, 'selected': False, 'text': '<p>Which DBMS?</p>\n\n<p>It can be done via CTE or Union for example, but if you are using, for example, MySQL, then you can forget about it.</p>\n'}, {'answer_id': 79393, 'author': 'Vinko Vrsalovic', 'author_id': 5190, 'author_profile': 'https://Stackoverflow.com/users/5190', 'pm_score': 2, 'selected': False, 'text': "<p>Case or the kind of conditional construct your RDBMS supports is a way to do it</p>\n\n<pre><code>select *, case when col like '%foo%' and col like '%bar%' then 2 end \nelse 1 end as ordcol \nfrom items \nwhere col like '%foo%' or col like '%bar%' order by ordcol\n</code></pre>\n"}, {'answer_id': 79395, 'author': 'Booji Boy', 'author_id': 1433, 'author_profile': 'https://Stackoverflow.com/users/1433', 'pm_score': 0, 'selected': False, 'text': "<p>Try this code:</p>\n\n<pre><code>SELECT * FROM Items WHERE column LIKE '%foo%' OR column LIKE '%bar%'\norder by (select count(*) from items i where i.column= item.column) DESC \n</code></pre>\n\n<p>You could also group by <code>column</code> and <code>count(*)</code> then <code>ORDER</code>, if you don't care about the details. </p>\n"}, {'answer_id': 79418, 'author': 'Mike Tunnicliffe', 'author_id': 13956, 'author_profile': 'https://Stackoverflow.com/users/13956', 'pm_score': 0, 'selected': False, 'text': "<p>You might want to give this a go:</p>\n\n<pre><code>SELECT *\nFROM Items\nWHERE column LIKE '%foo%' OR column LIKE '%bar%'\nORDER BY CASE WHEN column LIKE '%foo%' AND column LIKE '%bar%' THEN 1 ELSE 0 END DESC\n</code></pre>\n\n<p>Note: this is drycoded and probably not very portable.</p>\n"}, {'answer_id': 79422, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 1, 'selected': False, 'text': '<p>You could use a <code>UNION</code>:</p>\n\n<pre><code>SELECT * FROM Items WHERE column LIKE \'%foo%\' AND column LIKE \'%bar%\'\nUNION\nSELECT * FROM Items WHERE column LIKE \'%foo%\' AND NOT (column LIKE \'%bar%\')\nUNION\nSELECT * FROM Items WHERE column LIKE \'%bar%\' AND NOT (column LIKE \'%foo%\');\n</code></pre>\n\n<p>But this may be bad performance-wise. Worse, I\'m guessing that you want to use this to construct a search engine that gives the most meaningful results first, and then the number of words does not remain limited to 2.</p>\n\n<p>In that case, you could create a <code>score</code> column which contains the number of matches. Something like this:</p>\n\n<pre><code>SELECT\n *,\n (IF(column LIKE \'%bar%\', 1, 0) + IF(column LIKE \'%foo%\', 1, 0)) AS score\nFROM Items\nWHERE column LIKE \'%foo%\' OR column LIKE \'%bar%\'\nORDER BY score DESC;\n</code></pre>\n\n<p>My SQL is a bit rusty, but something like this should be possible in at least MySQL 5.0. See also the manual for the <code>IF</code> function:\n<a href="http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html</a></p>\n'}, {'answer_id': 79430, 'author': 'nicudotro', 'author_id': 14635, 'author_profile': 'https://Stackoverflow.com/users/14635', 'pm_score': 2, 'selected': False, 'text': "<pre><code>SELECT * FROM Items WHERE column LIKE '%foo%' OR column LIKE '%bar%' \nORDER BY \n(IF(column LIKE '%foo%',1,0) + IF(column LIKE '%bar%',1,0)) \nDESC\n</code></pre>\n\n<p>The syntax for if is </p>\n\n<p><code>IF ( condition, true_value, false_value )</code></p>\n"}, {'answer_id': 79473, 'author': 'Jolyon', 'author_id': 11740, 'author_profile': 'https://Stackoverflow.com/users/11740', 'pm_score': 0, 'selected': False, 'text': "<p>2 Queries: </p>\n\n<pre><code>SELECT * FROM Items WHERE column LIKE '%foo%' AND column LIKE '%bar%';<br/>\nSELECT * FROM Items WHERE (column LIKE '%foo%' AND column NOT LIKE '%bar%') OR (column NOT LIKE '%foo%' AND LIKE '%bar%')</code></pre>\n\n<p>(No XOR in SQL)</p>\n"}, {'answer_id': 79497, 'author': 'Mark Nold', 'author_id': 4134, 'author_profile': 'https://Stackoverflow.com/users/4134', 'pm_score': 0, 'selected': False, 'text': '<p>Not all RDBMS support IF (or DECODE in Oracle) statements. If not you could use a subquery to define table "a" and search for all employee\'s named JO SMITH or a combination.</p>\n\n<pre><code>SELECT \n a.employee_id,\n a.surname,\n sum(a.counter)\nFROM\n\n (SELECT\n employee_id,\n surname,\n 1 as counter\n FROM\n MyTable\n WHERE\n surname like \'%SMITH%\'\n\n UNION ALL\n\n SELECT\n employee_id,\n surname,\n 1 as counter\n FROM\n MyTable\n WHERE\n surname like \'%JO%\'\n ) a\n\nGROUP BY \n a.employee_id,\n a.surname\nORDER BY 3,1,2\n</code></pre>\n\n<p>Make sure you use UNION ALL otherwise it will not work. Also you may way to use UPPER() to make your search non-case sensitive.</p>\n'}, {'answer_id': 79598, 'author': 'Matt', 'author_id': 4154, 'author_profile': 'https://Stackoverflow.com/users/4154', 'pm_score': 0, 'selected': False, 'text': '<p>As your query is currently written, the WHERE clause will not give you any information that can be used to sort your results. I like <a href="https://stackoverflow.com/questions/79367/sql-text-searching-and-ordering#79380">Brian\'s idea</a>; add a constant column and UNION the queries and you could even get everything in one result set. For example:</p>\n\n<pre><code>SELECT 1 as rank, * FROM Items WHERE column LIKE \'%foo%\' AND column LIKE \'%bar%\'\nUNION\nSELECT 2 as rank, * FROM Items WHERE column LIKE \'%foo%\' AND column NOT LIKE \'%bar%\'\nUNION\nSELECT 2 as rank, * FROM Items WHERE column LIKE \'%bar%\' AND column NOT LIKE \'%foo%\'\nORDER BY rank\n</code></pre>\n\n<p>However, this would only give you something like this:</p>\n\n<ul>\n<li>The unordered set of all rows that match foo and match bar</li>\n<li>followed by (the unordered set of) all rows that match foo or bar, but not both (although you could break this up into two separate groups using a different constant in the last SELECT statement).</li>\n</ul>\n\n<p>Which might be just what you\'re looking for, but it wouldn\'t tell you which rows matched foo three times, or sort them ahead of rows that only contained one instance of foo. Also all those LIKEs can get expensive. If what you\'re really looking to do is sort results based on relevance (however you define that) you might be better off using a full text index. If you\'re using MS SQL Server, it has a built-in service that will do this, and there are also third-party products that will do the same.</p>\n\n<p>EDIT: After looking at all the other answers (there were only <em>two</em> when I started mine - I\'m obviously going to have to learn to think faster ;-) ) it\'s obvious that there are several ways to go about this, depending on exactly what you\'re trying to accomplish. I would advise you to test and compare solutions based on how they perform <strong>on your system</strong>. I\'m not a performance/tuning expert, but functions tend to slow things down, especially if you\'re sorting on the result of a function. The LIKE operator isn\'t necessarily spry, either. As a developer, it seems natural to use familiar constructs like "IF" and "CASE", but queries that use more of a set-based approach usually have better performance in a RDMS. Again, YMMV, so it\'s best to test if you\'re at all concerned about performance.</p>\n'}, {'answer_id': 81772, 'author': 'Andy Irving', 'author_id': 8553, 'author_profile': 'https://Stackoverflow.com/users/8553', 'pm_score': 1, 'selected': False, 'text': "<pre><code>SELECT * FROM Items\nWHERE col LIKE '%foo%'\n OR col LIKE '%bar%'\nORDER BY CASE WHEN col LIKE '%foo%' THEN 1\n WHEN col LIKE '%bar%' THEN 2\n END\n</code></pre>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79367', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
79,381
<p>I am wanting to access a website from a different port than 80 or 8080. Is this possible? I just want to view the website but through a different port. I do not have a router. I know this can be done because I have a browser that accessing websites through different ports, Called XB Browser by Xero Bank.</p> <hr> <p>Thanks for the answers. So, if I setup a proxy on one computer, I could have it go from my computer, to another computer that then returns the website to me. Would this bypass logging software?</p>
[{'answer_id': 79387, 'author': 'John Boker', 'author_id': 2847, 'author_profile': 'https://Stackoverflow.com/users/2847', 'pm_score': 0, 'selected': False, 'text': "<p>when viewing a website it gets assigned a random port, it will always come from port 80 (usually always, unless the server admin has changed the port) there's no way for someone to change that port unless you have control of the server.</p>\n"}, {'answer_id': 79390, 'author': 'Milan Babuškov', 'author_id': 14690, 'author_profile': 'https://Stackoverflow.com/users/14690', 'pm_score': 0, 'selected': False, 'text': '<p>If website server is listening to a different port, then yes, simply use <a href="http://address:port/" rel="nofollow noreferrer">http://address:port/</a></p>\n\n<p>If server is not listening to a different port, then obviously you cannot.</p>\n'}, {'answer_id': 79391, 'author': 'Xenph Yan', 'author_id': 264, 'author_profile': 'https://Stackoverflow.com/users/264', 'pm_score': 2, 'selected': False, 'text': '<p>No, as the server decides what port it is run on. Perhaps you could install a proxy, which would redirect the port, but in the end the connection would be made on port 80 from your machine.</p>\n'}, {'answer_id': 79398, 'author': 'Bullines', 'author_id': 27870, 'author_profile': 'https://Stackoverflow.com/users/27870', 'pm_score': 0, 'selected': False, 'text': "<p>Unless you're browsing through a proxy, the web servers hosting the sites you want to access must be configured to listen to a port other than 80 or 8080.</p>\n"}, {'answer_id': 79408, 'author': 'stimms', 'author_id': 361, 'author_profile': 'https://Stackoverflow.com/users/361', 'pm_score': 2, 'selected': False, 'text': "<p>You can run the web server on any port. 80 is just convention as are 8080 (web server on unprivileged port) and 443 (web server + ssl). However if you're looking to see some web site by pointing your browser to a different port you're probably out of luck. Unless the web server is being run on that port explicitly you'll just get an error message. </p>\n"}, {'answer_id': 79409, 'author': 'cori', 'author_id': 8151, 'author_profile': 'https://Stackoverflow.com/users/8151', 'pm_score': 0, 'selected': False, 'text': "<p>Perhaps this is obvious, but FWIW this will only work if the web server is serving requests for that website on the alternate port. It's not at all uncommon for a webserver to only serve a site on port 80.</p>\n"}, {'answer_id': 79412, 'author': 'Gero', 'author_id': 13116, 'author_profile': 'https://Stackoverflow.com/users/13116', 'pm_score': 0, 'selected': False, 'text': '<p>You can only access a website throught the port that is bind with the http server.\nExample: i hava a web server and it is listening for connections on port 123, the you only can get my pages connecting to my 123 port.</p>\n'}, {'answer_id': 79417, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 5, 'selected': True, 'text': "<p>If your question is about IIS(or other server) configuration - yes, it's possible. All you need is to create ports mapping under your Default Site or Virtual Directory and assign specific ports to the site you need. For example it is sometimes very useful for web services, when default port is assigned to some UI front-end and you want to assign service to the same address but with different port.</p>\n"}, {'answer_id': 79439, 'author': 'Dan Harper', 'author_id': 14530, 'author_profile': 'https://Stackoverflow.com/users/14530', 'pm_score': 1, 'selected': False, 'text': '<p>It depends.</p>\n\n<p>The web server on the other end will be set to a certain port, usually 80 and will only accept requests on that specific port. Something along the chain will need to be talking to port 80 to the website.</p>\n\n<p>If you control the website, then you can change the port, or get it to accept requests on multiple ports.</p>\n\n<p>If the website is already talking on a different port, you can just use the colon syntax to reference another port (eg: <a href="http://server.com:1234" rel="nofollow noreferrer">http://server.com:1234</a> for port 1234).</p>\n\n<p>If you want to use a different port on your client end, but you want to talk to port 80 at the web server end, you\'ll need to route traffic from port x to port 80. A common way to get this up and running is to use Port Fowarding. ssh can do this for you, see <a href="http://www.securityfocus.com/infocus/1816" rel="nofollow noreferrer">here</a> for a Unix/technical overview or <a href="http://www.cs.uu.nl/technical/services/ssh/putty/puttyfw.html" rel="nofollow noreferrer">here</a> if you\'re on Windows.</p>\n\n<p>Hope that helps.</p>\n'}, {'answer_id': 79446, 'author': 'jtimberman', 'author_id': 7672, 'author_profile': 'https://Stackoverflow.com/users/7672', 'pm_score': 0, 'selected': False, 'text': '<p>To clarify earlier answers, the HTTP protocol is \'registered\' with port 80, and HTTP over SSL (aka HTTPS) is registered with port 443. </p>\n\n<p>Well known port numbers are <a href="http://www.iana.org/assignments/port-numbers" rel="nofollow noreferrer">documented by IANA</a>. </p>\n\n<p>If you mean "bypass logging software" on the web server, no. It will see the traffic coming from you through the proxy system\'s IP address, at least. If you\'re trying to circumvent controls put into place by your IT department, then you need to rethink this. If your IT department blocks traffic to port 80, 8080 or 443 anywhere outbound, there is a reason. Ask your IT director. If you need access to these ports outbound from your local workstation to do your job, make your case with them.</p>\n\n<p>Installing a proxy server, or using a free proxy service, may be a violation of company policies and could put your employment at risk.</p>\n'}, {'answer_id': 79464, 'author': 'etchasketch', 'author_id': 14640, 'author_profile': 'https://Stackoverflow.com/users/14640', 'pm_score': 3, 'selected': False, 'text': '<p>You can use ssh to forward ports onto somewhere else.</p>\n\n<p>If you have two computers, one you browse from, and one which is free to access websites, and is not logged (ie. you own it and it\'s sitting at home), then you can set up a tunnel between them to forward http traffic over.</p>\n\n<p>For example, I connect to my home computer from work using ssh, with port forwarding, like this:</p>\n\n<pre><code>ssh -L 22222:&lt;target_website&gt;:80 &lt;home_computer&gt;\n</code></pre>\n\n<p>Then I can point my browser to</p>\n\n<pre><code>http://localhost:22222/\n</code></pre>\n\n<p>And this request will be forwarded over ssh. Since the work computer is first contacting the home computer, and then contacting the target website, it will be hard to log.</p>\n\n<p>However, this is all getting into \'how to bypass web proxies\' and the like, and I suggest you create a new question asking what exactly you want to do.</p>\n\n<p>Ie. "How do I bypass web proxies to avoid my traffic being logged?"</p>\n'}, {'answer_id': 4631197, 'author': 'Joe', 'author_id': 567598, 'author_profile': 'https://Stackoverflow.com/users/567598', 'pm_score': 4, 'selected': False, 'text': '<p>A simple way is to got to <a href="http://websitename.com:174" rel="noreferrer">http://websitename.com:174</a>, and you will be entering through a different port.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79381', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14769/']
79,389
<p>In a multitasking operating system context, sometimes you hear the term round-robin scheduling. What does it refer to?<br> What other kind of scheduling is there?</p>
[{'answer_id': 79426, 'author': 'Swati', 'author_id': 12682, 'author_profile': 'https://Stackoverflow.com/users/12682', 'pm_score': 6, 'selected': True, 'text': '<p><strong>Round Robin Scheduling</strong></p>\n\n<p>If you are a host in a party of 100 guests, round-robin scheduling would mean that you spend 1 minute (a fixed amount) per guest. You go through each guest one-by-one, and after 100 minutes, you would have spent 1 minute with each guest. More on <a href="http://en.wikipedia.org/wiki/Round-robin_scheduling" rel="noreferrer" title="Round-robin scheduling">Wikipedia</a>.</p>\n\n<p>There are many other types of scheduling, such as priority-based (i.e. most important people first), first-come-first-serve, earliest-deadline-first (i.e. person leaving earliest first), etc. You can start off by googling for scheduling algorithms or check out <a href="http://en.wikipedia.org/wiki/Scheduling_algorithm" rel="noreferrer" title="scheduling algorithms">scheduling at Wikipedia</a></p>\n'}, {'answer_id': 79431, 'author': 'mbowcock', 'author_id': 8758, 'author_profile': 'https://Stackoverflow.com/users/8758', 'pm_score': 0, 'selected': False, 'text': '<p>Round robin is a simple scheduling algorithm where time is divided evenly among jobs without priority.</p>\n\n<p>For example - if you have 5 processes running - each process will be allowed to run for 1/5 a unit of time before another process is allowed to run. Round robin is typically easy to implement in an OS.</p>\n'}, {'answer_id': 83324, 'author': 'Tall Jeff', 'author_id': 1553, 'author_profile': 'https://Stackoverflow.com/users/1553', 'pm_score': 2, 'selected': False, 'text': "<p>The answers here and even the Wikipedia article describe round-robin scheduling to inherently include periodic timeslicing. While this is very common, I believe that Round-Robin scheduling and timeslicing are <strong><em>not</em></strong> exactly the same thing. Certainly, for timeslicing to make sense, round-robin schedling is implied when rotating to each task, however you can do round-robin scheduling without having timeslicing. That is, each task at the same priority in the round-robin rotation can be allowed to run until they reach a resource block condition and only then having the next task in the rotation run. In other words, when equal priority tasks exist, the reschedling points are <strong><em>not</em></strong> time pre-emptive.</p>\n\n<p>The above idea is actually realized specifically in the case of Wind River's VxWorks kernel. Within their priority scheme, tasks of each priority run round robin but do not timeslice without specifically enabling that feature in the kernel. The reason for this flexibility is to avoid the overhead of timeslicing tasks that are already known to run into a block within a well bounded time.</p>\n\n<p>Therefore, while timeslicing based scheduling implies round-robin scheduling, round-robin scheduling does not require equal time based timeslicing.</p>\n"}, {'answer_id': 84198, 'author': 'unwieldy', 'author_id': 14963, 'author_profile': 'https://Stackoverflow.com/users/14963', 'pm_score': 3, 'selected': False, 'text': '<p>Timeslicing is inherent to any round-robin scheduling system in practice, AFAIK.</p>\n\n<p>I disagree with InSciTek Jeff\'s implication that the following <em>is</em> round-robin scheduling:</p>\n\n<blockquote>\n <p>That is, each task at the same priority in the round-robin rotation can be allowed to run until they reach a resource blocking condition before yeilding to the next task in the rotation.</p>\n</blockquote>\n\n<p>I do not see how this could be considered round-robin. This is actually preemptive scheduling. However, it is possible to have a scheduling algorithm which has elements of both round-robin and preemptive scheduling, which VxWorks does if round-robin scheduling and preemption are both enabled (round-robin is disabled by default). The way to enable round-robin scheduling is to provide a non-zero value in <em>kernelTimeSlice</em>.</p>\n\n<p>I do agree with this statement:</p>\n\n<blockquote>\n <p>Therefore, while timeslicing based scheduling implies round-robin scheduling, round-robin scheduling does not require equal time based timeslicing.</p>\n</blockquote>\n\n<p>You are right that it doesn\'t require equal time. Preemption can muck with that. And actually in VxWorks, if a task is preempted during round-robin scheduling, when the task gets control again it will execute for the rest of the time it was allocated. </p>\n\n<p>Edit directed at InSciTek Jeff (I don\'t have comment privileges)\nYes, I was referring to task locking/interrupt disabling, although I obviously didn\'t express that very well. You preempted me (ha!) with your second comment. I hope to debate the more salient point, that you believe round-robin scheduling can exist without time slicing. Or did you just mean equal time based time slicing? I disagree with the former, but agree with the latter. I am eager to learn. Thanks.</p>\n\n<p>Edit2 directed at Jeff:</p>\n\n<blockquote>\n <p>Round-robin can exist without timeslicing. That is exactly what happens in VxWorks when kernelTimeSlice is disabled (zero).</p>\n</blockquote>\n\n<p>I disagree with this statement. See <a href="http://www.slac.stanford.edu/exp/glast/flight/sw/vxdocs/vxworks/guide/c-basic.html" rel="noreferrer">this document</a> section 2.2.3 with the heading Round-Robin Scheduling.</p>\n\n<blockquote>\n <p>Round-robin scheduling uses time\n slicing to achieve fair allocation of\n the CPU to all tasks with the same\n priority. Each task, in a group of\n tasks with the same priority, executes\n for a defined interval or time slice.\n Round-robin scheduling is enabled by\n calling kernelTimeSlice( ), which\n takes a parameter for a time slice, or\n interval. [...] If round-robin\n scheduling is enabled, and preemption\n is enabled for the executing task, the\n system tick handler increments the\n task\'s time-slice count.</p>\n</blockquote>\n\n<p>Timeslicing is inherent in round-robin scheduling. Otherwise you are relying on a task to give up CPU control, which round-robin scheduling is intended to solve.</p>\n'}, {'answer_id': 2605673, 'author': 'Ashish', 'author_id': 312573, 'author_profile': 'https://Stackoverflow.com/users/312573', 'pm_score': 0, 'selected': False, 'text': '<p>Actaully, you are getting confused with Preemptive scheduling and Round robin. Infact RR is part of Preemptive scheduling.</p>\n'}, {'answer_id': 2891729, 'author': 'dbasnett', 'author_id': 66532, 'author_profile': 'https://Stackoverflow.com/users/66532', 'pm_score': 1, 'selected': False, 'text': '<p>An opinion. It seems that we are intertwining two mechanisms into one. Assuming only the OP\'s original assertion "In a multitasking operating system context" then </p>\n\n<p>1 - A round robin scheduler always schedules the next item in a circular queue.</p>\n\n<p>2 - How the scheduler regains control to perform the scheduling is separate and unrelated.</p>\n\n<p>I don\'t disagree that the most prevalent method for 2 is time-slicing / yield waiting for resource, but as has been noted there are others. If I am not mistaken the first Mac\'s didn\'t utilize time-slicing, they used voluntary yield / yield waiting for resource (20+ year old brain cells can be wrong sometimes;).</p>\n'}, {'answer_id': 42277060, 'author': 'tanmay sakpal', 'author_id': 7575639, 'author_profile': 'https://Stackoverflow.com/users/7575639', 'pm_score': 0, 'selected': False, 'text': '<p>Round Robin scheduling is based on time sharing also known as quantum (max time given by CPU to any process in one go). There are multiple processes(which require different time to complete aka burst time) in a queue and CPU has to process them all so it keeps switching between processes to give every process equal time based on the quantum value. This type of scheduling is known as Round Robin scheduling.\nCheckout this simple video to understand round robin scheduling easily: <a href="https://www.youtube.com/watch?v=9hw-_qJ55K4" rel="nofollow noreferrer">https://www.youtube.com/watch?v=9hw-_qJ55K4</a></p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79389', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10703/']
79,415
<p>What, at a minimum, should an application health-monitoring system do for you (the developer) and/or your boss (the IT Manager) and/or the operations (on-call) staff?</p> <p>What else should it do above the minimum requirements?</p> <p>Is monitoring the 'infrastructure' applications (ms-exchange, apache, etc.) sufficient or do individual user applications, web sites, and databases also need to be monitored?</p> <p>if the latter, what do you need to know about them?</p> <p>ADDENDUM: thanks for the input, i was really looking for application-level monitoring not infrastructure monitoring, but it is good to know about both</p>
[{'answer_id': 79440, 'author': 'Milan Babuškov', 'author_id': 14690, 'author_profile': 'https://Stackoverflow.com/users/14690', 'pm_score': 1, 'selected': False, 'text': "<p>Minimum: make sure it is running :)</p>\n\n<p>However, some other stuff would be very useful. For example, the CPU load, RAM usage and (in multiuser systems) which user is running what. Also, for applications that access network, a list of network connections for each app. And (if you have access to client computer(s)) it would be cool to be able to see the 'window title' of the app - maybe check each 2-3 minutes if it changed and save it. Also, a list of files open by the application could be very useful, but it is not a must.</p>\n"}, {'answer_id': 79444, 'author': 'David Thibault', 'author_id': 5903, 'author_profile': 'https://Stackoverflow.com/users/5903', 'pm_score': 5, 'selected': True, 'text': '<ul>\n<li>Whether the application is running.</li>\n<li>Unusual cpu/memory/network usage.</li>\n<li>Report any unhandled exceptions.</li>\n<li>Status of various modules (if applicable).</li>\n<li>Status of external components (databases, webservices, fileservers, etc.)</li>\n<li>Number of pending background tasks (if applicable).</li>\n<li>Maybe track usage of the application and report statistics on most/less used functionalities so you know where optimizations are most beneficial.</li>\n</ul>\n'}, {'answer_id': 79448, 'author': 'David Medinets', 'author_id': 219658, 'author_profile': 'https://Stackoverflow.com/users/219658', 'pm_score': 2, 'selected': False, 'text': "<p>The answer is 'it depends'. Why do you need to monitor? How large is your operations staff? Do you need reporting? What is the application environment? Who cares if the application fails? Who cares if an exception happens? Are any of the errors recoverable? I could ask questions like these for a long time.</p>\n"}, {'answer_id': 79458, 'author': 'Steve M', 'author_id': 1693, 'author_profile': 'https://Stackoverflow.com/users/1693', 'pm_score': 1, 'selected': False, 'text': "<p>I think this is fairly simple - monitor so that you can be warned early enough before something goes wrong. That means monitor dependencies and the application itself.</p>\n\n<p>It's really hard to provide specifics if you're not going to give details on the application you're monitoring, so I'd say use that as a general rule.</p>\n"}, {'answer_id': 79469, 'author': 'Nathan Feger', 'author_id': 8563, 'author_profile': 'https://Stackoverflow.com/users/8563', 'pm_score': 2, 'selected': False, 'text': "<p>This is such an open ended question, but I would start with physical measurements. <br />\n1. Are all the machines I think are hosting this site pingable?<br />\n2. Are all the machines which should be serving content actually serving some content? (Ideally this would be hit from an external network.)<br />\n3. Is each expected service on each machine running?<br />\n3a. Have those services run recently?<br />\n4. Does each machine have hard drive space left? (Don't forget the db)<br />\n5. Have these machines been backed up? When was the last time?<br />\n<br />\nOnce one lays out the physical monitoring of the systems, one can address those specific to a system? <br />\n<br />\n1. Can an automated script log in? How long did it take?<br />\n2. How many users are live? Have there been a million fake accounts added?<br />\n...<br />\nThese sorts of questions get more nebulous, and can be very system specific. They also usually can be derived reactively when responding to phsyical measurements. Hard drive fill up, maybe the web server logs got filled up because a bunch of agents created too many fake users. That kind of thing. </p>\n\n<p>While plan A shouldn't necessarily be reactive, it is the way many a site setup a monitoring system.</p>\n"}, {'answer_id': 79479, 'author': 'Ryan P', 'author_id': 1539, 'author_profile': 'https://Stackoverflow.com/users/1539', 'pm_score': 1, 'selected': False, 'text': '<p>At a minimum you want to know that the system is healthy. This is subjective in what defines your system is healthy. Is it computers are up, the needed resources exist, the data is flowing through the system, the data is properly producing results, etc, etc.</p>\n\n<p>In my project we do monitoring of most of this and then some. It really comes down to what is the highest level that you can use to analyze that everything is working. In our case we need to know down to the data output. If you just need to know down to the are these machines up it saves you on trying to show an inexperienced end user what is wrong.</p>\n\n<p>There are also "off the shelf" tools that will do a lot of the hard work for you if you are just looking too hard into data results. I particularly liked <a href="http://www.nagios.org/" rel="nofollow noreferrer">Nagios</a> when I was looking around but we needed more than it could easily show so I wrote our own monitoring system. Basically we also watch for "peculiarities" in the system, memory / cpu spikes, etc...</p>\n'}, {'answer_id': 286328, 'author': 'Steven A. Lowe', 'author_id': 9345, 'author_profile': 'https://Stackoverflow.com/users/9345', 'pm_score': 1, 'selected': False, 'text': '<p>thanks everyone for the input, i was really looking for application-level monitoring not infrastructure monitoring, but it is good to know about both</p>\n\n<p>the difference is:</p>\n\n<ul>\n<li>infrastructure monitoring would be servers plus MS Exchange Server, Apache, IIS, and so forth</li>\n<li>application monitoring would be user machines and the specific programs that they use to do their jobs, and/or servers plus the data-moving/backend applications that they run to keep the data flowing</li>\n</ul>\n\n<p>sometimes it\'s hard to draw the line - an oversimplified definition might be "if your team wrote it, it\'s an application; if you bought it, it\'s infrastructure"</p>\n\n<p>i think in practice it is best to monitor both</p>\n'}, {'answer_id': 3066289, 'author': 'Albert T. Wong', 'author_id': 369819, 'author_profile': 'https://Stackoverflow.com/users/369819', 'pm_score': 1, 'selected': False, 'text': '<p>What you need to do is to break down the business process of the application and then have the software emit events at major business components. In addition, you\'ll need to create end to end synthetic transactions (eg. emulating end users clicking on a website). All that data would be fed into an monitoring tool. In the past, I\'ve done JMX for applications of which flowed into Tivoli Monitoring\'s JMX Adapter and then I\'ve done scripts that implement a "fake user" and then pipe in the results into Tivoli Monitoring\'s Script Adapter. Tivoli Monitoring takes the data and then creates application health and performance charts from that raw data.</p>\n'}, {'answer_id': 3584930, 'author': 'dzida', 'author_id': 359665, 'author_profile': 'https://Stackoverflow.com/users/359665', 'pm_score': 2, 'selected': False, 'text': '<p>Great question.</p>\n\n<p>We\'ve been looking for some application-level monitoring solution for our needs some time ago without any luck. Popular monitoring solution are mostly addressed to monitor infrastrcture and - in my opinion - they are too complicated for a requirements of most of small and mid-sized companies.</p>\n\n<p>We required (mainly) following features:</p>\n\n<ul>\n<li>alerts - we wanted to know about\nincident as fast as possible </li>\n<li>painless management - hosted service wouldbe\nthe best </li>\n<li>visualizations - it\'s good to know what is going on and take some knowledge from the data</li>\n</ul>\n\n<p>Because we didn\'t find suitable solution we started to write our own. Finally we\'ve ended with up-and-running service called <a href="http://alert-grid.com" rel="nofollow noreferrer">AlertGrid</a>. (You can check it for free of course.)</p>\n\n<p>The idea behind it is to provide an easy way to handle custom monitoring scenarios. Integration API is very simple (one function with two required parameters). At the momment we and others are using it for:</p>\n\n<ul>\n<li>monitor scheduled tasks (cron jobs)</li>\n<li>monitor entire application logic execution</li>\n<li>alert on errors in applications</li>\n<li>we are also working on examples of basic infrastructure monitoring using AlertGrid</li>\n</ul>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79415', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9345/']
79,434
<p>I think it's associating my Web Service's CS files with the related ASMX files. But whatever's happening, I can't double-click to open the CS files - I have to "view Code" or it opens in the designer. </p> <p>Anyone know how to turn off this automatic behavior? I just want to edit the code!</p>
[{'answer_id': 79450, 'author': 'Stephen Wrighton', 'author_id': 7516, 'author_profile': 'https://Stackoverflow.com/users/7516', 'pm_score': 0, 'selected': False, 'text': '<p>In the Solution Explorer view, click the "Show All Files" icon. This will put "+" symbol next to each of your files. Click the + and it will expand to show the .CS file which holds the ASMX\'s code. At this point, double click that file instead.</p>\n'}, {'answer_id': 79562, 'author': 'Aaron Cooper', 'author_id': 14822, 'author_profile': 'https://Stackoverflow.com/users/14822', 'pm_score': 0, 'selected': False, 'text': '<p>For some reason VS2005 seems to have this a bit backwards when it comes to webservices. To open a webservice in code view, double-click the .asmx file, not the .asmx.cs file.</p>\n\n<p>I guess it makes a bit of sense, as there\'s nothing to "design" when it comes to a webservice, but it\'s counterintuitive if you\'ve been working with .aspx files.</p>\n'}, {'answer_id': 87196, 'author': 'Rasmus Faber', 'author_id': 5542, 'author_profile': 'https://Stackoverflow.com/users/5542', 'pm_score': 5, 'selected': True, 'text': '<p>Try right-clicking, select "Open with...", mark "CSharp Editor" and select "Set as Default".</p>\n\n<p>That works for avoiding the WinForms Designer.</p>\n'}, {'answer_id': 714418, 'author': 'Brian Ensink', 'author_id': 1254, 'author_profile': 'https://Stackoverflow.com/users/1254', 'pm_score': 3, 'selected': False, 'text': '<p>I found this question when trying to deal with a similar problem. I had a C# class in a file and whenever I double clicked on the file it would try to open in design mode but design mode was meaningless for this class. I just want to see the code.</p>\n\n<p>I found that adding the [System.ComponentModel.DesignerCategory("")] attribute to my class fixed this.</p>\n'}, {'answer_id': 3159967, 'author': 'AMissico', 'author_id': 163921, 'author_profile': 'https://Stackoverflow.com/users/163921', 'pm_score': 0, 'selected': False, 'text': "<p>In my experience, if you find that the wrote editor, that is the non-default editor, is opening when double-clicking on a file within the <strong>Solution Explorer</strong> then something is wrong with the underlying project's <strong>User Options</strong> file (.user) or the solution's <strong>User Options</strong> file (.suo). (I am not sure which, but I suspect the settings are stored in the .suo file.) Deleting the the .suo and all project .user files solved the problem.</p>\n\n<p>I personally, set the <strong>Form Editor</strong> as my default editor for forms at the beginning of a project. After the forms are stable and require less user-interface design changes, I switch the default editor.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79434', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7104/']
79,438
<p>I need to add role based permissions to my Rails application, and am wondering what the best plugins out there are to look into. I am currently using the RESTful authentication plugin to handle user authentication. Why is the plug in you suggest better than the other ones out there?</p>
[{'answer_id': 79452, 'author': 'Matt Rogish', 'author_id': 2590, 'author_profile': 'https://Stackoverflow.com/users/2590', 'pm_score': 3, 'selected': True, 'text': '<p>I use, and really like, role_requirement:\n<a href="http://code.google.com/p/rolerequirement/" rel="nofollow noreferrer">http://code.google.com/p/rolerequirement/</a></p>\n'}, {'answer_id': 80967, 'author': 'Codebeef', 'author_id': 12037, 'author_profile': 'https://Stackoverflow.com/users/12037', 'pm_score': 0, 'selected': False, 'text': '<p>We\'ve put role_requirement into <a href="http://github.com/fudgestudios/bort/tree/master" rel="nofollow noreferrer">Bort</a> too, as it\'s probably the best solution out there at the moment.</p>\n'}, {'answer_id': 93416, 'author': 'liangzan', 'author_id': 11927, 'author_profile': 'https://Stackoverflow.com/users/11927', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m a very satisfied user of ACL</p>\n\n<p><a href="http://agilewebdevelopment.com/plugins/acl_system" rel="nofollow noreferrer">http://agilewebdevelopment.com/plugins/acl_system</a></p>\n\n<p>do try it!</p>\n'}, {'answer_id': 93937, 'author': 'epochwolf', 'author_id': 16204, 'author_profile': 'https://Stackoverflow.com/users/16204', 'pm_score': 0, 'selected': False, 'text': '<p>I recommend <a href="http://blog.gingertech.net/2008/05/21/rails-authorization-plugin/" rel="nofollow noreferrer">Rails Authorization</a> which will work with Restful Authentication quite nicely.</p>\n'}, {'answer_id': 1700210, 'author': 'Ryan', 'author_id': 185050, 'author_profile': 'https://Stackoverflow.com/users/185050', 'pm_score': 2, 'selected': False, 'text': '<p>Ive got to recommended easy_roles. Its super light weight, and doesn\'t require extra tables etc etc.</p>\n\n<p><a href="http://github.com/platform45/easy_roles" rel="nofollow noreferrer">http://github.com/platform45/easy_roles</a></p>\n\n<p><a href="http://gemcutter.org/gems/easy_roles" rel="nofollow noreferrer">http://gemcutter.org/gems/easy_roles</a></p>\n\n<p>But role authentication is definitely site dependent. Different role authorization plugins suit different sites.</p>\n\n<p>If you dont feel easy_roles suits your needs, check out:</p>\n\n<p><a href="http://ruby-toolbox.com/categories/rails_authorization.html" rel="nofollow noreferrer">http://ruby-toolbox.com/categories/rails_authorization.html</a></p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79438', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14787/']
79,445
<p>I'd like to write a simple C# application to monitor the line-in audio and give me the current (well, the rolling average) beats per minute.</p> <p>I've seen <a href="http://www.gamedev.net/page/resources/_/technical/math-and-physics/beat-detection-algorithms-r1952" rel="noreferrer">this gamedev article</a>, and that was absolutely no help. I went through and tried to implement what he was doing but it just wasn't working.</p> <p>I know there have to be tons of solutions for this, because lots of DJ software does it, but I'm not having any luck in finding any open-source library or instructions on doing it myself.</p>
[{'answer_id': 79480, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 3, 'selected': False, 'text': '<p>This is by no means an easy problem. I\'ll try to give you an overview only.</p>\n\n<p>What you could do is something like the following:</p>\n\n<ol>\n<li>Compute the average (root-mean-square) loudness of the signal over blocks of, say, 5 milliseconds. (Having never done this before, I don\'t know what a good block size would be.)</li>\n<li>Take the Fourier transform of the "blocked" signal, using the FFT algorithm.</li>\n<li>Find the component in the transformed signal that has the largest magnitude.</li>\n</ol>\n\n<p>A Fourier transform is basically a way of computing the strength of all frequencies present in the signal. If you do that over the "blocked" signal, the frequency of the beat will hopefully be the strongest one.</p>\n\n<p>Maybe you need to apply a filter first, to focus on specific frequencies (like the bass) that usually contain the most information about the BPM.</p>\n'}, {'answer_id': 79532, 'author': 'Dan Harper', 'author_id': 14530, 'author_profile': 'https://Stackoverflow.com/users/14530', 'pm_score': 3, 'selected': False, 'text': '<p>Not that I have a clue how to implement this, but from an audio engineering perspective you\'d need to filter first. Bass drum hits would be the first to check. A low pass filter that gives you anything under about 200Hz should give you a pretty clear picture of the bass drum. A gate might also be necessary to cleanup any clutter from other instruments with harmonics that low.</p>\n\n<p>The next to check would be snare hits. You\'d have to EQ this one. The "crack" from a snare is around 1.5kHz from memory, but you\'d need to definitely gate this one.</p>\n\n<p>The next challenge would be to work out an algorithm for funky beats. How would you programatically find beat 1? I guess you\'d keep track of previous beats and use a pattern matching something-or-other. So, you\'d probably need a few bars to accurately find the beat. Then there\'s timing issues like 4/4, 3/4, 6/8, wow, I can\'t imagine what would be required to do this accurately! I\'m sure it\'d be worth some serious money to audio hardware/software companies.</p>\n'}, {'answer_id': 81462, 'author': 'Nick Johnson', 'author_id': 12030, 'author_profile': 'https://Stackoverflow.com/users/12030', 'pm_score': 4, 'selected': False, 'text': '<p>There\'s an excellent project called Dancing Monkeys, which procedurally generates DDR dance steps from music. A large part of what it does is based on (necessarily very accurate) beat analysis, and their project paper goes into much detail describing the various beat detection algorithms and their suitability to the task. They include references to the original papers for each of the algorithms. They\'ve also published the matlab code for their solution. I\'m sure that between those you can find what you need.</p>\n\n<p>It\'s all available here: <a href="http://monket.net/dancing-monkeys-v2/Main_Page" rel="noreferrer">http://monket.net/dancing-monkeys-v2/Main_Page</a></p>\n'}, {'answer_id': 81666, 'author': 'Hallgrim', 'author_id': 15454, 'author_profile': 'https://Stackoverflow.com/users/15454', 'pm_score': 5, 'selected': False, 'text': '<p>Calculate a powerspectrum with a sliding window FFT:\nTake 1024 samples: </p>\n\n<pre><code>double[] signal = stream.Take(1024);\n</code></pre>\n\n<p>Feed it to an FFT algorithm: </p>\n\n<pre><code>double[] real = new double[signal.Length];\ndouble[] imag = new double[signal.Length);\nFFT(signal, out real, out imag);\n</code></pre>\n\n<p>You will get a real part and an imaginary part. Do NOT throw away the imaginary part. Do the same to the real part as the imaginary. While it is true that the imaginary part is pi / 2 out of phase with the real, it still contains 50% of the spectrum information.</p>\n\n<p>EDIT:</p>\n\n<p>Calculate the power as opposed to the amplitude so that you have a high number when it is loud and close to zero when it is quiet:</p>\n\n<pre><code>for (i=0; i &lt; real.Length; i++) real[i] = real[i] * real[i];\n</code></pre>\n\n<p>Similarly for the imaginary part.</p>\n\n<pre><code>for (i=0; i &lt; imag.Length; i++) imag[i] = imag[i] * imag[i];\n</code></pre>\n\n<p>Now you have a power spectrum for the last 1024 samples. Where the first part of the spectrum is the low frequencies and the last part of the spectrum is the high \nfrequencies.</p>\n\n<p>If you want to find BPM in popular music you should probably focus on the bass. You can pick up the bass intensity by summing the lower part of the power spectrum. Which numbers to use depends on the sampling frequency:</p>\n\n<pre><code>double bassIntensity = 0;\nfor (i=8; i &lt; 96; i++) bassIntensity += real[i];\n</code></pre>\n\n<p>Now do the same again but move the window 256 samples before you calculate a new spectrum. Now you end up with calculating the bassIntensity for every 256 samples. </p>\n\n<p>This is a good input for your BPM analysis. When the bass is quiet you do not have a beat and when it is loud you have a beat. </p>\n\n<p>Good luck!</p>\n'}, {'answer_id': 668127, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>The easy way to do it is to have the user tap a button in rhythm with the beat, and count the number of taps divided by the time.</p>\n'}, {'answer_id': 4219423, 'author': 'pete', 'author_id': 512711, 'author_profile': 'https://Stackoverflow.com/users/512711', 'pm_score': 1, 'selected': False, 'text': '<p>First of all, what Hallgrim is producing is not the power spectral density function. Statistical periodicities in any signal can be brought out through an autocorrelation function. The fourier transform of the autocorrelation signal is the power spectral density. Dominant peaks in the PSD other than at 0 Hz will correspond to the effective periodicity in the signal (in Hz)... </p>\n'}, {'answer_id': 10342753, 'author': 'eandersson', 'author_id': 408182, 'author_profile': 'https://Stackoverflow.com/users/408182', 'pm_score': 3, 'selected': False, 'text': '<p>I found this library which seem to have a pretty solid implementation for detecting <strong>Beats per Minute</strong>.\n<a href="https://github.com/owoudenberg/soundtouch.net" rel="nofollow noreferrer">https://github.com/owoudenberg/soundtouch.net</a></p>\n<p>It\'s based on <a href="http://www.surina.net/soundtouch/index.html" rel="nofollow noreferrer">http://www.surina.net/soundtouch/index.html</a> which is used in quite a few DJ projects <a href="http://www.surina.net/soundtouch/applications.html" rel="nofollow noreferrer">http://www.surina.net/soundtouch/applications.html</a></p>\n'}, {'answer_id': 28925534, 'author': 'Matt Williams', 'author_id': 3905343, 'author_profile': 'https://Stackoverflow.com/users/3905343', 'pm_score': 0, 'selected': False, 'text': '<p>I\'d recommend checking out the BASS audio library and the BASS.NET wrapper. It has a built in BPMCounter class. </p>\n\n<p>Details for this specific function can be found at\n<a href="http://bass.radio42.com/help/html/0833aa5a-3be9-037c-66f2-9adfd42a8512.htm" rel="nofollow">http://bass.radio42.com/help/html/0833aa5a-3be9-037c-66f2-9adfd42a8512.htm</a>.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79445', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14758/']
79,451
<p>I would like to test out the new SP1 in my development server and then install it for my production server. But I wonder what it had enhance to the ASP.NET portion specifically as that is where my concerns are. </p> <p>I read the docs found in the SP1 Download page but it seens a bit too general to me, not much on the ASP.NE portion. Anyone have any clues on this?</p>
[{'answer_id': 79487, 'author': 'Quintin Robinson', 'author_id': 12707, 'author_profile': 'https://Stackoverflow.com/users/12707', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx</a></p>\n\n<p>There is a section in there on the improvements for web development.. it can be vague as well but has links to videos and further information. I suggest checking it out.</p>\n'}, {'answer_id': 79489, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': 0, 'selected': False, 'text': '<p>Short list:</p>\n\n<p>ASP.NET: Dynamic Data now included in .Net 3.5 and all necessary project templates for VS also available\nASP.NET: History support added. Now we can control AJAX pages behavior on Back/Forward buttons pressed in very simple manner that was shown previously on MS demos\nASP.NET: Script Combining feature added to reduce the number of requests and improving page load time. Before this moment we used custom approach for client scripts combining\nVS2008: Added richer support of JavaScript code formatting and Intellisense, especially for separated .js files</p>\n\n<p>more on blog: <a href="http://dimarzionist.wordpress.com/2008/05/13/full-list-of-changes-in-sp1-beta/" rel="nofollow noreferrer">http://dimarzionist.wordpress.com/2008/05/13/full-list-of-changes-in-sp1-beta/</a></p>\n'}, {'answer_id': 79526, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Please check out this article: <a href="http://www.hanselman.com/blog/PermaLink.aspx?guid=54292847-2b74-4f6d-a380-a65b25993b6c" rel="nofollow noreferrer">Hidden Gems - Not the same old 3.5 SP1 post</a></p>\n\n<p>It details some of the minor improvements in SP1. It also links to Scott Guthrie\'s article on SP1.</p>\n\n<p>In my experience, the upgrade went well. I had one issue with a site with poorly coded AJAX - nothing much at all.</p>\n\n<ul>\n<li>Ron</li>\n</ul>\n'}, {'answer_id': 79579, 'author': 'Quintin Robinson', 'author_id': 12707, 'author_profile': 'https://Stackoverflow.com/users/12707', 'pm_score': 0, 'selected': False, 'text': "<p>To be honest the only real improvement i've seen from SP1 and this is because I haven't been looking for specific improvements is that it will now read your TODO and HACK tasks from all files in a project instead of just the file open. That particular feature is useful though.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79451', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14790/']
79,454
<p>Recently I've been experimenting with TDD while developing a GUI application in Python. I find it very reassuring to have tests that verify the functionality of my code, but it's been tricky to follow some of the recommened practices of TDD. Namely, writing tests first has been hard. And I'm finding it difficult to make my tests readable (due to extensive use of a mocking library).</p> <p>I chose a mocking library called <a href="http://labix.org/mocker" rel="noreferrer">mocker</a>. I use it a lot since much of the code I'm testing makes calls to (a) other methods in my application that depend on system state or (b) ObjC/Cocoa objects that cannot exist without an event loop, etc.</p> <p>Anyway, I've got a lot of tests that look like this:</p> <pre><code>def test_current_window_controller(): def test(config): ac = AppController() m = Mocker() ac.iter_window_controllers = iwc = m.replace(ac.iter_window_controllers) expect(iwc()).result(iter(config)) with m: result = ac.current_window_controller() assert result == (config[0] if config else None) yield test, [] yield test, [0] yield test, [1, 0] </code></pre> <p>Notice that this is actually three tests; all use the same parameterized test function. Here's the code that is being tested:</p> <pre><code>def current_window_controller(self): try: # iter_window_controllers() iterates in z-order starting # with the controller of the top-most window # assumption: the top-most window is the "current" one wc = self.iter_window_controllers().next() except StopIteration: return None return wc </code></pre> <p>One of the things I've noticed with using mocker is that it's easier to write the application code first and then go back and write the tests second, since most of the time I'm mocking many method calls and the syntax to write the mocked calls is much more verbose (thus harder to write) than the application code. It's easier to write the app code and then model the test code off of that.</p> <p>I find that with this testing method (and a bit of discipline) I can easily write code with 100% test coverage.</p> <p>I'm wondering if these tests are good tests? Will I regret doing it this way down the road when I finally discover the secret to writing good tests?</p> <p>Am I violating the core principles of TDD so much that my testing is in vain?</p>
[{'answer_id': 79667, 'author': 'etchasketch', 'author_id': 14640, 'author_profile': 'https://Stackoverflow.com/users/14640', 'pm_score': -1, 'selected': False, 'text': "<p>Unit tests are really useful when you refactor your code (ie. completely rewrite or move a module). As long as you have unit tests before you do the big changes, you'll have confidence that you havent forgotten to move or include something when you finish.</p>\n"}, {'answer_id': 80028, 'author': 'Gishu', 'author_id': 1695, 'author_profile': 'https://Stackoverflow.com/users/1695', 'pm_score': 3, 'selected': False, 'text': '<p><strong>If you are writing your tests after you\'ve written your code and making them pass, you are not doing TDD</strong> (nor are you getting any benefits of Test-First or Test-Driven development.. check out SO questions for definitive books on TDD)</p>\n\n<blockquote>\n <p>One of the things I\'ve noticed with\n using mocker is that it\'s easier to\n write the application code first and\n then go back and write the tests\n second, since most of the time I\'m\n mocking many method calls and the\n syntax to write the mocked calls is\n much more verbose (thus harder to\n write) than the application code. It\'s\n easier to write the app code and then\n model the test code off of that.</p>\n</blockquote>\n\n<p>Of course, its easier because you are just testing that the sky is orange after you made it orange by painting it with a specific kind of brush. \nThis is retrofitting tests (for self-assurance). Mocks are good but you should know how and when to use them - Like the saying goes \'When you have a hammer everything looks like a nail\' It\'s also easy to write a whole load of unreadable and not-as-helpful-as-can-be tests. The time spent understanding what the test is about is time lost that can be used to fix broken ones. </p>\n\n<p>And the point is: </p>\n\n<ul>\n<li>Read <a href="http://martinfowler.com/articles/mocksArentStubs.html#ClassicalAndMockistTesting" rel="nofollow noreferrer">Mocks aren\'t stubs - Martin Fowler</a> if you haven\'t already. Google out some documented instances of good <a href="http://martinfowler.com/eaaDev/ModelViewPresenter.html" rel="nofollow noreferrer">ModelViewPresenter</a> patterned GUIs (Fake/Mock out the UIs if necessary). </li>\n<li>Study your options and choose wisely. I\'ll play the guy with the halo on your left shoulder in white saying \'Don\'t do it.\' Read this question as to <a href="https://stackoverflow.com/questions/59195/how-are-mocks-meant-to-be-used">my reasons</a> - St. Justin is on your right shoulder. I believe he has also something to say:) </li>\n</ul>\n'}, {'answer_id': 82049, 'author': 'Paweł Hajdan', 'author_id': 9403, 'author_profile': 'https://Stackoverflow.com/users/9403', 'pm_score': -1, 'selected': False, 'text': '<p><strong>Please remember that TDD is not a panaceum.</strong> It\'s hard, it\'s supposed to be hard, and it\'s especially hard to write mocking tests "in advance".</p>\n\n<p>So I would say - do what works for you. Even it\'s not "certified TDD". I do basically the same thing.</p>\n\n<p>You may want to provide your own API for GUI that would sit between controller code and GUI library code. That could be easier to mock, or you can even add some testing hooks to it.</p>\n\n<p>Last but not least, your code doesn\'t look too unreadable to me. Code using mocks is generally harder to understand. Fortunately in Python mocking is much easier and cleaner than i n other languages.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79454', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10840/']
79,455
<p>Given this example:</p> <pre><code>&lt;img class="a" /&gt; &lt;img /&gt; &lt;img class="a" /&gt; &lt;img class="a" id="active" /&gt; &lt;img class="a" /&gt; &lt;img class="a" /&gt; &lt;img /&gt; &lt;img class="a" /&gt; </code></pre> <p><em>(I've just used img tags as an example, that's not what it is in my code)</em></p> <p>Using jQuery, how would you select the img tags with class "a" that are adjacent to #active (the middle four, in this example)?</p> <p>You could do it fairly easily by looping over all the following and preceding elements, stopping when the filter condition fails, but I was wondering if jQuery could it natively?</p>
[{'answer_id': 79471, 'author': 'Xenph Yan', 'author_id': 264, 'author_profile': 'https://Stackoverflow.com/users/264', 'pm_score': 2, 'selected': False, 'text': '<p>I believe looping is your best bet. But you could try, each active, and then move before and after until the condition breaks, which if the set is large enough would be faster.</p>\n'}, {'answer_id': 79767, 'author': 'Prestaul', 'author_id': 5628, 'author_profile': 'https://Stackoverflow.com/users/5628', 'pm_score': 0, 'selected': False, 'text': '<p>The tilde (~) is the <a href="http://docs.jquery.com/Selectors/siblings#prevsiblings" rel="nofollow noreferrer">siblings selector</a>:</p>\n\n<pre><code>$(\'#active ~ img.a\').hide();\n</code></pre>\n'}, {'answer_id': 79861, 'author': 'nickf', 'author_id': 9021, 'author_profile': 'https://Stackoverflow.com/users/9021', 'pm_score': 0, 'selected': False, 'text': '<p>@Prestaul</p>\n\n<pre><code>$(\'#active ~ img.a\')\n</code></pre>\n\n<p>would only select the <em>following</em> siblings, and would include the non-consecutive siblings too. Docs: <a href="http://docs.jquery.com/Selectors/siblings#prevsiblings" rel="nofollow noreferrer">http://docs.jquery.com/Selectors/siblings#prevsiblings</a></p>\n'}, {'answer_id': 79978, 'author': 'Andrew Hedges', 'author_id': 11577, 'author_profile': 'https://Stackoverflow.com/users/11577', 'pm_score': 0, 'selected': False, 'text': "<p>This is another way to do it, though the sibling selector answer is pretty cool:</p>\n\n<pre><code>var next = $('#active').next('.a');\nvar prev = $('#active').prev('.a');\n</code></pre>\n\n<p><strong>Edit:</strong> I re-read your requirements and this isn't quite what you want. You could use nextAll and prevAll, but those, too, would not stop at the IMGs without the class name.</p>\n"}, {'answer_id': 80302, 'author': 'nickf', 'author_id': 9021, 'author_profile': 'https://Stackoverflow.com/users/9021', 'pm_score': 3, 'selected': True, 'text': '<p>Here\'s what I came up with in the end.</p>\n\n<pre><code>// here\'s our active element.\nvar $active = $(\'#active\');\n\n// here is the filter we\'ll be testing against.\nvar filter = "img.a";\n\n// $all will be the final jQuery object with all the consecutively matched elements.\n// start it out by populating it with the current object.\nvar $all = $active;\n\nfor ($curr = $active.prev(filter); $curr.length &gt; 0; $curr = $curr.prev(filter)) {\n $all = $all.add($curr);\n}\nfor ($curr = $td.next(filter); $curr.length &gt; 0; $curr = $curr.next(filter)) {\n $all = $all.add($curr);\n}\n</code></pre>\n\n<p>For a follow up question, I could see how this could easily be generalised by making it into a function which takes two arguments: an initial element, and a filter string - can anyone point me in the right direction to find out how to extend the jQuery object to add such a function?</p>\n\n<hr>\n\n<p><strong>Edit</strong>: I\'ve since found that the each() function would do this rather well for some purposes. In my own case it doesn\'t work as cleanly, since I want a single jQuery object for all those elements, but here\'s how you could use each for a different purpose (hiding consecutive ".a" elements, in this example:)</p>\n\n<pre><code>$(\'#active\')\n .nextAll()\n .each(hideConsecutive)\n .end()\n .prevAll()\n .each(hideConsecutive)\n;\nfunction hideConsecutive(index, element) {\n var $e = $(element);\n if (!$e.is(".a")) {\n return false; // this stops the each function.\n } else {\n $e.hide(\'slow\');\n }\n}\n</code></pre>\n\n<p>--</p>\n\n<p>Edit: I\'ve put this together into a plugin now. Take a look at <a href="http://plugins.jquery.com/project/Adjacent" rel="nofollow noreferrer">http://plugins.jquery.com/project/Adjacent</a> if you\'re interested.</p>\n'}, {'answer_id': 763488, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>The below code will add two new functions, nextConsecutive() and prevConsecutive(). They should do what you want.</p>\n\n<p>$.each( ['prev', 'next'], function(unusedIndex, name) {\n $.fn[ name + 'Consecutive' ] = function(matchExpr) {</p>\n\n<pre><code> var $all = \n (name == 'prev')\n ? $(this).prevAll()\n : $(this).nextAll();\n if (!matchExpr)\n return $all;\n\n var $notMatch = $($all).not(matchExpr).filter(':first');\n if ($all.index($notMatch) != -1)\n return $allConsecutive = $all.slice(0, $all.index($notMatch));\n\n return $all;\n};\n</code></pre>\n\n<p>});</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79455', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9021/']
79,461
<p>I have a <code>div</code> with two images and an <code>h1</code>. All of them need to be vertically aligned within the div, next to each other. One of the images needs to be <code>absolute</code> positioned within the <code>div</code>.</p> <p>What is the CSS needed for this to work on all common browsers?</p> <pre class="lang-html prettyprint-override"><code>&lt;div id=&quot;header&quot;&gt; &lt;img src=&quot;..&quot; &gt;&lt;/img&gt; &lt;h1&gt;testing...&lt;/h1&gt; &lt;img src=&quot;...&quot;&gt;&lt;/img&gt; &lt;/div&gt; </code></pre>
[{'answer_id': 79513, 'author': 'dimarzionist', 'author_id': 10778, 'author_profile': 'https://Stackoverflow.com/users/10778', 'pm_score': -1, 'selected': False, 'text': '<pre><code>&lt;div id="header" style="display: table-cell; vertical-align:middle;"&gt;\n</code></pre>\n\n<p>...</p>\n\n<p>or CSS</p>\n\n<pre><code>.someClass\n{\n display: table-cell;\n vertical-align:middle;\n}\n</code></pre>\n\n<p><a href="http://caniuse.com/#search=table-cell" rel="noreferrer"><strong>Browser Coverage</strong></a></p>\n'}, {'answer_id': 79550, 'author': 'Mike Tunnicliffe', 'author_id': 13956, 'author_profile': 'https://Stackoverflow.com/users/13956', 'pm_score': 2, 'selected': False, 'text': '<p>By default h1 is a block element and will render on the line after the first img, and will cause the second img to appear on the line following the block.</p>\n<p>To stop this from occurring you can set the h1 to have inline flow behaviour:</p>\n<pre><code>#header &gt; h1 { display: inline; }\n</code></pre>\n<p>As for absolutely positioning the img <em>inside the div</em>, you need to set the containing div to have a &quot;known size&quot; before this will work properly. In my experience, you also need to change the position attribute away from the default - position: relative works for me:</p>\n<pre><code>#header { position: relative; width: 20em; height: 20em; }\n#img-for-abs-positioning { position: absolute; top: 0; left: 0; }\n</code></pre>\n<p>If you can get that to work, you might want to try progressively removing the height, width, position attributes from div.header to get the minimal required attributes to get the effect you want.</p>\n<p><strong>UPDATE:</strong></p>\n<p>Here is a complete example that works on Firefox 3:</p>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;\n &lt;html&gt;\n &lt;head&gt;\n &lt;title&gt;Example of vertical positioning inside a div&lt;/title&gt;\n &lt;style type="text/css"&gt;\n #header &gt; h1 { display: inline; }\n #header { border: solid 1px red; \n position: relative; }\n #img-for-abs-positioning { position: absolute;\n bottom: -1em; right: 2em; }\n &lt;/style&gt;\n &lt;/head&gt;\n \n &lt;body&gt;\n &lt;div id="header"&gt;\n &lt;img src="#" alt="Image 1" width="40" height="40" /&gt;\n &lt;h1&gt;Header&lt;/h1&gt;\n &lt;img src="#" alt="Image 2" width="40" height="40" \n id="img-for-abs-positioning" /&gt;\n &lt;/div&gt;\n &lt;/body&gt;\n &lt;/html&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}, {'answer_id': 80036, 'author': 'Shog9', 'author_id': 811, 'author_profile': 'https://Stackoverflow.com/users/811', 'pm_score': 4, 'selected': False, 'text': '<blockquote>\n <p>All of them need to be vertically aligned within the div</p>\n</blockquote>\n\n<p>Aligned <em>how</em>? Tops of the images aligned with the top of the text? </p>\n\n<blockquote>\n <p>One of the images needs to be absolute positioned within the div.</p>\n</blockquote>\n\n<p>Absolutely positioned relative to the DIV? Perhaps you could sketch out what you\'re looking for...?</p>\n\n<p><a href="https://stackoverflow.com/questions/79461/vertical-alignment-of-elements-in-a-div#79550">fd has described</a> the steps for absolute positioning, as well as adjusting the display of the <code>H1</code> element such that images will appear inline with it. To that, i\'ll add that you can align the images by use of the <code>vertical-align</code> style:</p>\n\n<pre><code>#header h1 { display: inline; }\n#header img { vertical-align: middle; }\n</code></pre>\n\n<p>...this would put the header and images together, with top edges aligned. Other alignment options exist; <a href="http://www.w3.org/TR/CSS2/visudet.html#propdef-vertical-align" rel="nofollow noreferrer">see the documentation</a>. You might also find it beneficial to drop the DIV and move the images inside the <code>H1</code> element - this provides semantic value to the container, and removes the need to adjust the display of the <code>H1</code>:</p>\n\n<pre><code>&lt;h1 id=header"&gt;\n &lt;img src=".." &gt;&lt;/img&gt;\n testing...\n &lt;img src="..."&gt;&lt;/img&gt;\n&lt;/h1&gt;\n</code></pre>\n'}, {'answer_id': 84616, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 11, 'selected': True, 'text': '<p>Wow, this problem is popular. It\'s based on a misunderstanding in the <code>vertical-align</code> property. This excellent article explains it:</p>\n<p><a href="http://phrogz.net/CSS/vertical-align/index.html" rel="noreferrer">Understanding <code>vertical-align</code>, or &quot;How (Not) To Vertically Center Content&quot;</a> by Gavin Kistner.</p>\n<p><strong><a href="http://howtocenterincss.com/" rel="noreferrer">“How to center in CSS”</a></strong> is a great web tool which helps to find the necessary CSS centering attributes for different situations.</p>\n<hr />\n<p>In a nutshell <sub><sup>(and to prevent link rot)</sup></sub>:</p>\n<ul>\n<li><strong>Inline elements</strong> (and <em>only</em> inline elements) can be vertically aligned in their context via <code>vertical-align: middle</code>. However, the “context” isn’t the whole parent container height, it’s the height of the text line they’re in. <a href="http://jsfiddle.net/jBthq/" rel="noreferrer">jsfiddle example</a></li>\n<li>For block elements, vertical alignment is harder and strongly depends on the specific situation:\n<ul>\n<li>If the inner element can have a <strong>fixed height</strong>, you can make its position <code>absolute</code> and specify its <code>height</code>, <code>margin-top</code> and <code>top</code> position. <a href="http://jsfiddle.net/YFncP/2/" rel="noreferrer">jsfiddle example</a></li>\n<li>If the centered element <strong>consists of a single line</strong> <em>and</em> <strong>its parent height is fixed</strong> you can simply set the container’s <code>line-height</code> to fill its height. This method is quite versatile in my experience. <a href="http://jsfiddle.net/d4zGF/" rel="noreferrer">jsfiddle example</a></li>\n<li>… there are more such special cases.</li>\n</ul>\n</li>\n</ul>\n'}, {'answer_id': 5962720, 'author': 'Romain', 'author_id': 305288, 'author_profile': 'https://Stackoverflow.com/users/305288', 'pm_score': 6, 'selected': False, 'text': '<p>It worked for me:</p>\n\n<pre class="lang-css prettyprint-override"><code>.vcontainer {\n min-height: 10em;\n display: table-cell;\n vertical-align: middle;\n}\n</code></pre>\n'}, {'answer_id': 9967286, 'author': 'Anita Mandal', 'author_id': 1146211, 'author_profile': 'https://Stackoverflow.com/users/1146211', 'pm_score': 4, 'selected': False, 'text': '<p>Use this formula, and it will work always without cracks:</p>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>#outer {height: 400px; overflow: hidden; position: relative;}\n#outer[id] {display: table; position: static;}\n\n#middle {position: absolute; top: 50%;} /* For explorer only*/\n#middle[id] {display: table-cell; vertical-align: middle; width: 100%;}\n\n#inner {position: relative; top: -50%} /* For explorer only */\n/* Optional: #inner[id] {position: static;} */</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="outer"&gt;\n &lt;div id="middle"&gt;\n &lt;div id="inner"&gt;\n any text\n any height\n any content, for example generated from DB\n everything is vertically centered\n &lt;/div&gt;\n &lt;/div&gt;\n&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}, {'answer_id': 10181095, 'author': 'abernier', 'author_id': 133327, 'author_profile': 'https://Stackoverflow.com/users/133327', 'pm_score': 5, 'selected': False, 'text': '<p>A technique from a friend of mine:</p>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>div:before {content:" "; display:inline-block; height:100%; vertical-align:middle;}\ndiv p {display:inline-block;}</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div style="height:100px; border:1px solid;"&gt;\n &lt;p style="border:1px dotted;"&gt;I\'m vertically centered.&lt;/p&gt;\n&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n<p>Demo <a href="http://dabblet.com/gist/2867324" rel="nofollow noreferrer">here</a>.</p>\n'}, {'answer_id': 16357586, 'author': 'user2346571', 'author_id': 2346571, 'author_profile': 'https://Stackoverflow.com/users/2346571', 'pm_score': 7, 'selected': False, 'text': '<p>I used this very simple code:</p>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>div.ext-box { display: table; width:100%;}\ndiv.int-box { display: table-cell; vertical-align: middle; }</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="ext-box"&gt;\n &lt;div class="int-box"&gt;\n &lt;h2&gt;Some txt&lt;/h2&gt;\n &lt;p&gt;bla bla bla&lt;/p&gt;\n &lt;/div&gt;\n&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n<p>Obviously, whether you use a <code>.class</code> or an <code>#id</code>, the result won\'t change.</p>\n'}, {'answer_id': 19131573, 'author': 'Joel Moses', 'author_id': 2837597, 'author_profile': 'https://Stackoverflow.com/users/2837597', 'pm_score': -1, 'selected': False, 'text': '<p>Just this:</p>\n\n<pre class="lang-html prettyprint-override"><code>&lt;div&gt;\n &lt;table style="width: 100%; height: 100%"&gt;\n &lt;tr&gt;\n &lt;td style="width: 100%; height: 100%; vertical-align: middle;"&gt;\n What ever you want vertically-aligned\n &lt;/td&gt;\n &lt;/tr&gt;\n &lt;/table&gt;\n&lt;/div&gt;\n</code></pre>\n\n<p>A one-cell table inside the div handles the vertical-align and is backward compatible back to the Stone Age!</p>\n'}, {'answer_id': 19131774, 'author': 'Joel Moses', 'author_id': 2837597, 'author_profile': 'https://Stackoverflow.com/users/2837597', 'pm_score': 1, 'selected': False, 'text': '<p>Just use a one-cell table inside the div! Just set the cell and table height and with to 100% and you can use the vertical-align.</p>\n\n<p>A one-cell table inside the div handles the vertical-align and is backward compatible back to the Stone Age!</p>\n'}, {'answer_id': 20149753, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': -1, 'selected': False, 'text': '<p>Here is just another (responsive) approach:</p>\n\n<pre><code>html,\n body {\n height: 100%;\n }\n body {\n margin: 0;\n }\n\n .table {\n display: table;\n width: auto;\n table-layout:auto;\n height: 100%;\n }\n .table:nth-child(even) {\n background: #a9edc3;\n }\n .table:nth-child(odd) {\n background: #eda9ce;\n }\n\n .tr {\n display: table-row;\n }\n .td {\n display: table-cell;\n width: 50%;\n vertical-align: middle;\n }\n</code></pre>\n\n<p><a href="http://jsfiddle.net/herrfischerhamburg/JcVxz/" rel="nofollow noreferrer">http://jsfiddle.net/herrfischerhamburg/JcVxz/</a></p>\n'}, {'answer_id': 20920505, 'author': 'pr0gg3r', 'author_id': 1159244, 'author_profile': 'https://Stackoverflow.com/users/1159244', 'pm_score': -1, 'selected': False, 'text': '<pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;\n&lt;html&gt;\n &lt;head&gt;\n &lt;style type="text/css"&gt;\n #style_center { position:relative; top:50%; left:50%; }\n #style_center_absolute { position:absolute; top:50px; left:50px; }\n &lt;!--#style_center { position:relative; top:50%; left:50%; height:50px; margin-top:-25px; }--&gt;\n &lt;/style&gt;\n &lt;/head&gt;\n\n &lt;body&gt;\n &lt;div style="height:200px; width:200px; background:#00FF00"&gt;\n &lt;div id="style_center"&gt;+&lt;/div&gt;\n &lt;/div&gt;\n &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n'}, {'answer_id': 21202703, 'author': 'Shadoweb', 'author_id': 1063653, 'author_profile': 'https://Stackoverflow.com/users/1063653', 'pm_score': 4, 'selected': False, 'text': '<p>Almost all methods needs to specify the height, but often we don\'t have any heights.</p>\n<p>So here is a CSS\xa03 three-line trick that doesn\'t require to know the height.</p>\n<pre><code>.element {\n position: relative;\n top: 50%;\n transform: translateY(-50%);\n}\n</code></pre>\n<p>It\'s supported even in IE9.</p>\n<p>with its vendor prefixes:</p>\n<pre><code>.element {\n position: relative;\n top: 50%;\n -webkit-transform: translateY(-50%);\n -ms-transform: translateY(-50%);\n transform: translateY(-50%);\n}\n</code></pre>\n<p>Source: <em><a href="http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/" rel="nofollow noreferrer">Vertical align anything with just 3 lines of CSS</a></em></p>\n'}, {'answer_id': 24985086, 'author': 'Arsh', 'author_id': 3882353, 'author_profile': 'https://Stackoverflow.com/users/3882353', 'pm_score': 0, 'selected': False, 'text': '<p><strong>I have been using the following solution (with no positioning and no line height) since over a year, it works with <a href="https://en.wikipedia.org/wiki/Internet_Explorer_7" rel="nofollow noreferrer">Internet\xa0Explorer\xa07</a> and <a href="https://en.wikipedia.org/wiki/Internet_Explorer_8" rel="nofollow noreferrer">Internet\xa0Explorer\xa08</a> as well.</strong></p>\n<pre><code>&lt;style&gt;\n.outer {\n font-size: 0;\n width: 400px;\n height: 400px;\n background: orange;\n text-align: center;\n display: inline-block;\n}\n\n.outer .emptyDiv {\n height: 100%;\n background: orange;\n visibility: collapse;\n}\n\n.outer .inner {\n padding: 10px;\n background: red;\n font: bold 12px Arial;\n}\n\n.verticalCenter {\n display: inline-block;\n *display: inline;\n zoom: 1;\n vertical-align: middle;\n}\n&lt;/style&gt;\n\n&lt;div class=&quot;outer&quot;&gt;\n &lt;div class=&quot;emptyDiv verticalCenter&quot;&gt;&lt;/div&gt;\n &lt;div class=&quot;inner verticalCenter&quot;&gt;\n &lt;p&gt;Line 1&lt;/p&gt;\n &lt;p&gt;Line 2&lt;/p&gt;\n &lt;/div&gt;\n&lt;/div&gt;\n</code></pre>\n'}, {'answer_id': 25867805, 'author': 'danigonlinea', 'author_id': 1196978, 'author_profile': 'https://Stackoverflow.com/users/1196978', 'pm_score': 0, 'selected': False, 'text': '<p>This is my personal solution for an <code>i</code> element inside a <code>div</code>.</p>\n<p><a href="http://jsfiddle.net/3FvxA/683/" rel="nofollow noreferrer">JSFiddle Example</a></p>\n<h2>HTML</h2>\n<pre><code>&lt;div class=&quot;circle&quot;&gt;\n &lt;i class=&quot;fa fa-plus icon&quot;&gt;\n&lt;/i&gt;&lt;/div&gt;\n</code></pre>\n<h2>CSS</h2>\n<pre><code>.circle {\n border-radius: 50%;\n color: blue;\n background-color: red;\n height:100px;\n width:100px;\n text-align: center;\n line-height: 100px;\n}\n\n.icon {\n font-size: 50px;\n vertical-align: middle;\n}\n</code></pre>\n'}, {'answer_id': 26356771, 'author': 'VuesomeDev', 'author_id': 1725325, 'author_profile': 'https://Stackoverflow.com/users/1725325', 'pm_score': 5, 'selected': False, 'text': '<p>To position block elements to the center (works in <a href="https://en.wikipedia.org/wiki/Internet_Explorer_9" rel="nofollow noreferrer">Internet\xa0Explorer\xa09</a> and above), it needs a wrapper <code>div</code>:</p>\n<pre><code>.vcontainer {\n position: relative;\n top: 50%;\n transform: translateY(-50%);\n -webkit-transform: translateY(-50%);\n}\n</code></pre>\n'}, {'answer_id': 26364552, 'author': 'joan16v', 'author_id': 1398876, 'author_profile': 'https://Stackoverflow.com/users/1398876', 'pm_score': 4, 'selected': False, 'text': '<p>My trick is to put a table inside the div with one row and one column, set 100% of width and height, and the property <em>vertical-align:middle</em>:</p>\n<pre><code>&lt;div&gt;\n\n &lt;table style=&quot;width:100%; height:100%;&quot;&gt;\n &lt;tr&gt;\n &lt;td style=&quot;vertical-align:middle;&quot;&gt;\n BUTTON TEXT\n &lt;/td&gt;\n &lt;/tr&gt;\n &lt;/table&gt;\n\n&lt;/div&gt;\n</code></pre>\n<p>Fiddle:\n<a href="http://jsfiddle.net/joan16v/sbqjnn9q/" rel="nofollow noreferrer">http://jsfiddle.net/joan16v/sbqjnn9q/</a></p>\n'}, {'answer_id': 31078418, 'author': 'E. Serrano', 'author_id': 1572964, 'author_profile': 'https://Stackoverflow.com/users/1572964', 'pm_score': 8, 'selected': False, 'text': '<p>Now that Flexbox support is increasing, this CSS applied to the containing element would vertically center all contained items (except for those items that specify the alignment themselves, e.g. <a href="https://developer.mozilla.org/docs/Web/CSS/align-self" rel="noreferrer"><code>align-self:start</code></a>)</p>\n<pre class="lang-css prettyprint-override"><code>.container {\n display: flex;\n align-items: center;\n}\n</code></pre>\n<p>Use the prefixed version if you also need to target <a href="https://en.wikipedia.org/wiki/Internet_Explorer_11#Internet_Explorer_10" rel="noreferrer">Internet\xa0Explorer\xa010</a>, and older (&lt; <a href="https://en.wikipedia.org/wiki/Android_version_history#Android_4.4_KitKat_.28API_level_19.29" rel="noreferrer">4.4</a> (KitKat)) Android browsers:</p>\n<pre class="lang-css prettyprint-override"><code>.container {\n display: -ms-flexbox;\n display: -webkit-flex;\n display: flex;\n\n -ms-flex-align: center;\n -webkit-align-items: center;\n -webkit-box-align: center;\n align-items: center;\n}\n</code></pre>\n'}, {'answer_id': 31279382, 'author': 'BernieSF', 'author_id': 1689852, 'author_profile': 'https://Stackoverflow.com/users/1689852', 'pm_score': 0, 'selected': False, 'text': '<p>For me, it worked this way:</p>\n\n<pre><code>&lt;div style="width:70px; height:68px; float:right; display: table-cell; line-height: 68px"&gt;\n &lt;a href="javascript:void(0)" style="margin-left: 4px; line-height: 2" class="btn btn-primary"&gt;Login&lt;/a&gt;\n&lt;/div&gt;\n</code></pre>\n\n<p>The "a" element converted to a button, using Bootstrap classes, and it is now vertically centered inside an outer "div".</p>\n'}, {'answer_id': 34320593, 'author': 'Henk-Martijn', 'author_id': 4069967, 'author_profile': 'https://Stackoverflow.com/users/4069967', 'pm_score': 3, 'selected': False, 'text': '<p>Using CSS to vertical center, you can let the outer containers act like a table, and the content as a table cell. In this format your objects will stay centered. :)</p>\n<p>I nested multiple objects in JSFiddle for an example, but the core idea is like this:</p>\n<p><strong>HTML</strong></p>\n<pre><code>&lt;div class=&quot;circle&quot;&gt;\n &lt;div class=&quot;content&quot;&gt;\n Some text\n &lt;/div&gt;\n&lt;/div&gt;\n</code></pre>\n<p><strong>CSS</strong></p>\n<pre class="lang-css prettyprint-override"><code>.circle {\n /* Act as a table so we can center vertically its child */\n display: table;\n /* Set dimensions */\n height: 200px;\n width: 200px;\n /* Horizontal center text */\n text-align: center;\n /* Create a red circle */\n border-radius: 100%;\n background: red;\n}\n\n.content {\n /* Act as a table cell */\n display: table-cell;\n /* And now we can vertically center! */\n vertical-align: middle;\n /* Some basic markup */\n font-size: 30px;\n font-weight: bold;\n color: white;\n}\n</code></pre>\n<p>The multiple objects example:</p>\n<p><strong>HTML</strong></p>\n<pre><code>&lt;div class=&quot;container&quot;&gt;\n &lt;div class=&quot;content&quot;&gt;\n\n &lt;div class=&quot;centerhoriz&quot;&gt;\n\n &lt;div class=&quot;circle&quot;&gt;\n &lt;div class=&quot;content&quot;&gt;\n Some text\n &lt;/div&gt;&lt;!-- content --&gt;\n &lt;/div&gt;&lt;!-- circle --&gt;\n\n &lt;div class=&quot;square&quot;&gt;\n &lt;div class=&quot;content&quot;&gt;\n &lt;div id=&quot;smallcircle&quot;&gt;&lt;/div&gt;\n &lt;/div&gt;&lt;!-- content --&gt;\n &lt;/div&gt;&lt;!-- square --&gt;\n\n &lt;/div&gt;&lt;!-- center-horiz --&gt;\n\n &lt;/div&gt;&lt;!-- content --&gt;\n&lt;/div&gt;&lt;!-- container --&gt;\n</code></pre>\n<p><strong>CSS</strong></p>\n<pre class="lang-css prettyprint-override"><code>.container {\n display: table;\n height: 500px;\n width: 300px;\n text-align: center;\n background: lightblue;\n}\n\n.centerhoriz {\n display: inline-block;\n}\n\n.circle {\n display: table;\n height: 200px;\n width: 200px;\n text-align: center;\n background: red;\n border-radius: 100%;\n margin: 10px;\n}\n\n.square {\n display: table;\n height: 200px;\n width: 200px;\n text-align: center;\n background: blue;\n margin: 10px;\n}\n\n.content {\n display: table-cell;\n vertical-align: middle;\n font-size: 30px;\n font-weight: bold;\n color: white;\n}\n\n#smallcircle {\n display: inline-block;\n height: 50px;\n width: 50px;\n background: green;\n border-radius: 100%;\n}\n</code></pre>\n<p><strong>Result</strong></p>\n<p><a href="https://i.stack.imgur.com/p1Cyh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p1Cyh.png" alt="Result" /></a></p>\n<p><a href="https://jsfiddle.net/martjemeyer/ybs032uc/1/" rel="nofollow noreferrer">https://jsfiddle.net/martjemeyer/ybs032uc/1/</a></p>\n'}, {'answer_id': 39904652, 'author': 'Dashrath', 'author_id': 1510544, 'author_profile': 'https://Stackoverflow.com/users/1510544', 'pm_score': 2, 'selected': False, 'text': '<p>We may use a CSS function calculation to calculate the size of the element and then position the child element accordingly.</p>\n<p>Example HTML:</p>\n<pre><code>&lt;div class=&quot;box&quot;&gt;\n &lt;span&gt;&lt;a href=&quot;#&quot;&gt;Some Text&lt;/a&gt;&lt;/span&gt;\n&lt;/div&gt;\n</code></pre>\n<p>And CSS:</p>\n<pre class="lang-css prettyprint-override"><code>.box {\n display: block;\n background: #60D3E8;\n position: relative;\n width: 300px;\n height: 200px;\n text-align: center;\n}\n\n.box span {\n font: bold 20px/20px \'source code pro\', sans-serif;\n position: absolute;\n left: 0;\n right: 0;\n top: calc(50% - 10px);\n}\n\na {\n color: white;\n text-decoration: none;\n}\n</code></pre>\n<p>Demo created here: <a href="https://jsfiddle.net/xnjq1t22/" rel="nofollow noreferrer">https://jsfiddle.net/xnjq1t22/</a></p>\n<p>This solution works well with responsive <code>div</code> <code>height</code> and <code>width</code> as well.</p>\n<p>Note: The <em>calc</em> function is not tested for compatiblity with old browsers.</p>\n'}, {'answer_id': 45458436, 'author': 'Shivam', 'author_id': 1592107, 'author_profile': 'https://Stackoverflow.com/users/1592107', 'pm_score': 2, 'selected': False, 'text': '<p>I have found a new workaround to vertically align multiple text-lines in a div using CSS\xa03 (and I am also using bootstrap v3 grid system to beautify the UI), which is as below:</p>\n<pre class="lang-css prettyprint-override"><code>.immediate-parent-of-text-containing-div {\n height: 50px; /* Or any fixed height that suits you. */\n}\n\n.text-containing-div {\n display: inline-grid;\n align-items: center;\n text-align: center;\n height: 100%;\n}\n</code></pre>\n<p>As per my understanding, the immediate parent of text containing element must have some height.</p>\n'}, {'answer_id': 48523051, 'author': 'WasiF', 'author_id': 4574281, 'author_profile': 'https://Stackoverflow.com/users/4574281', 'pm_score': 5, 'selected': False, 'text': '<h2>Vertically and horizontally align element</h2>\n<p>Use either of these. The result would be the same:</p>\n<ol>\n<li>Bootstrap 4</li>\n<li>CSS3</li>\n</ol>\n<p><a href="https://i.stack.imgur.com/MqvVH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MqvVH.png" alt="Enter image description here" /></a></p>\n<h3>1. Bootstrap 4.3+</h3>\n<p>For vertical alignment: <code>d-flex align-items-center</code></p>\n<p>For horizontal alignment: <code>d-flex justify-content-center</code></p>\n<p>For vertical and horizontal alignment: <code>d-flex align-items-center justify-content-center</code></p>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>.container {\n height: 180px;\n width:100%;\n background-color: blueviolet;\n}\n\n.container &gt; div {\n background-color: white;\n padding: 1rem;\n}</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"\nrel="stylesheet"/&gt;\n\n&lt;div class="d-flex align-items-center justify-content-center container"&gt;\n &lt;div&gt;I am in Center&lt;/div&gt;\n&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n<h3>2. CSS\xa03</h3>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>.container {\n height: 180px;\n width:100%;\n background-color: blueviolet;\n}\n\n.container &gt; div {\n background-color: white;\n padding: 1rem;\n}\n\n.center {\n display: flex;\n align-items: center;\n justify-content: center;\n}</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container center"&gt;\n &lt;div&gt;I am in Center&lt;/div&gt;\n&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}, {'answer_id': 51626821, 'author': 'Sameera Prasad Jayasinghe', 'author_id': 5901608, 'author_profile': 'https://Stackoverflow.com/users/5901608', 'pm_score': 7, 'selected': False, 'text': '<pre class="lang-css prettyprint-override"><code> .outer {\n display: flex;\n align-items: center; \n justify-content: center;\n }\n</code></pre>\n'}, {'answer_id': 55066555, 'author': 'Dennis Don', 'author_id': 1367794, 'author_profile': 'https://Stackoverflow.com/users/1367794', 'pm_score': 3, 'selected': False, 'text': '<p>Using display flex, first you need to wrap the container of the item that you want to align:</p>\n<pre><code>&lt;div class=&quot;outdiv&quot;&gt;\n &lt;div class=&quot;indiv&quot;&gt;\n &lt;span&gt;test1&lt;/span&gt;\n &lt;span&gt;test2&lt;/span&gt;\n &lt;/div&gt;\n&lt;/div&gt;\n</code></pre>\n<p>Then apply the following CSS content to wrap <em>div</em> or <em>outdiv</em> in my example:</p>\n<pre class="lang-css prettyprint-override"><code>.outdiv {\n display: flex;\n justify-content: center;\n align-items: center;\n}\n</code></pre>\n'}, {'answer_id': 57117215, 'author': 'Stephen', 'author_id': 558721, 'author_profile': 'https://Stackoverflow.com/users/558721', 'pm_score': 2, 'selected': False, 'text': '<p>My new favorite way to do it is with a CSS grid:</p>\n\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>/* technique */\r\n\r\n.wrapper {\r\n display: inline-grid;\r\n grid-auto-flow: column;\r\n align-items: center;\r\n justify-content: center;\r\n}\r\n\r\n/* visual emphasis */\r\n\r\n.wrapper {\r\n border: 1px solid red;\r\n height: 180px;\r\n width: 400px;\r\n}\r\n\r\nimg {\r\n width: 100px;\r\n height: 80px;\r\n background: #fafafa;\r\n}\r\n\r\nimg:nth-child(2) {\r\n height: 120px;\r\n}</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="wrapper"&gt;\r\n &lt;img src="https://source.unsplash.com/random/100x80/?bear"&gt;\r\n &lt;img src="https://source.unsplash.com/random/100x120/?lion"&gt;\r\n &lt;img src="https://source.unsplash.com/random/100x80/?tiger"&gt;\r\n&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}, {'answer_id': 57247568, 'author': 'akhtarvahid', 'author_id': 6544460, 'author_profile': 'https://Stackoverflow.com/users/6544460', 'pm_score': 4, 'selected': False, 'text': '<h3>Three ways to make a center child div in a parent div</h3>\n<ul>\n<li>Absolute positioning method</li>\n<li>Flexbox method</li>\n<li>Transform/translate method</li>\n</ul>\n<p><a href="https://i.stack.imgur.com/IJ41P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IJ41P.png" alt="Enter image description here" /></a></p>\n<p><a href="https://jsfiddle.net/vahid_634/Lsvcrf1g/4/" rel="nofollow noreferrer">Demo</a></p>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>/* Absolute Positioning Method */\n.parent1 {\n background: darkcyan;\n width: 200px;\n height: 200px;\n position: relative;\n}\n.child1 {\n background: white;\n height: 30px;\n width: 30px;\n position: absolute;\n top: 50%;\n left: 50%;\n margin: -15px;\n}\n\n/* Flexbox Method */\n.parent2 {\n display: flex;\n justify-content: center;\n align-items: center;\n background: darkcyan;\n height: 200px;\n width: 200px;\n}\n.child2 {\n background: white;\n height: 30px;\n width: 30px;\n}\n\n/* Transform/Translate Method */\n.parent3 {\n position: relative;\n height: 200px;\n width: 200px;\n background: darkcyan;\n}\n.child3 {\n background: white;\n height: 30px;\n width: 30px;\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n}</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="parent1"&gt;\n &lt;div class="child1"&gt;&lt;/div&gt;\n&lt;/div&gt;\n&lt;hr /&gt;\n\n&lt;div class="parent2"&gt;\n &lt;div class="child2"&gt;&lt;/div&gt;\n&lt;/div&gt;\n&lt;hr /&gt;\n\n&lt;div class="parent3"&gt;\n &lt;div class="child3"&gt;&lt;/div&gt;\n&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}, {'answer_id': 64780990, 'author': 'HASSAN MD TAREQ', 'author_id': 4802664, 'author_profile': 'https://Stackoverflow.com/users/4802664', 'pm_score': 2, 'selected': False, 'text': '<p>Using only a Bootstrap class:</p>\n<ul>\n<li>div: <code>class=&quot;container d-flex&quot;</code></li>\n<li>element inside div: <code>class=&quot;m-auto&quot;</code></li>\n</ul>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" crossorigin="anonymous"&gt;\n\n&lt;div class="container d-flex mt-5" style="height:110px; background-color: #333;"&gt;\n &lt;h2 class="m-auto"&gt;&lt;a href="https://hovermind.com/"&gt;H➲VER➾M⇡ND&lt;/a&gt;&lt;/h2&gt;\n&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79461', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5232/']
79,466
<p>(sorry I should have been clearer with the code the first time I posted this. Hope this makes sense)</p> <p>File "size_specification.rb"</p> <pre><code>class SizeSpecification def fits? end end </code></pre> <p>File "some_module.rb"</p> <pre><code>require 'size_specification' module SomeModule def self.sizes YAML.load_file(File.dirname(__FILE__) + '/size_specification_data.yml') end end </code></pre> <p>File "size_specification_data.yml</p> <pre><code>--- - !ruby/object:SizeSpecification height: 250 width: 300 </code></pre> <p>Then when I call</p> <pre><code>SomeModule.sizes.first.fits? </code></pre> <p>I get an exception because "sizes" are Object's not SizeSpecification's so they don't have a "fits" function.</p>
[{'answer_id': 80075, 'author': 'robertpostill', 'author_id': 11219, 'author_profile': 'https://Stackoverflow.com/users/11219', 'pm_score': 0, 'selected': False, 'text': "<p>On second reading I'm a little confused, you seem to want to mix the class into module, which is porbably not so advisable. Also is the YAML supposed to load an array of the SizeSpecifications?</p>\n\n<p>It appears to be that you're not mixing the Module into your class. If I run the test in irb then the require throws a LoadError. So I assume you've put two files together, if not dump it.</p>\n\n<p>Normally you'd write the functionality in the module, then mix that into the class. so you may modify your code like this:</p>\n\n<pre><code>class SizeSpecification\n include SomeModule\n def fits? \n end\nend\n</code></pre>\n\n<p>Which will allow you to then say:</p>\n\n<pre><code>SizeSpecification::SomeModule.sizes\n</code></pre>\n\n<p>I think you should also be able to say:</p>\n\n<pre><code>SizeSpecification.sizes\n</code></pre>\n\n<p>However that requires you to take the self off the prefix of the sizes method definition.</p>\n\n<p>Does that help?</p>\n"}, {'answer_id': 94745, 'author': 'anshul', 'author_id': 17674, 'author_profile': 'https://Stackoverflow.com/users/17674', 'pm_score': 1, 'selected': False, 'text': '<p>Are your settings and ruby installation ok? I created those 3 files and wrote what follows in "test.rb"</p>\n\n<pre><code>require \'yaml\'\nrequire "some_module"\n\nSomeModule.sizes.first.fits?\n</code></pre>\n\n<p>Then I ran it.</p>\n\n<pre><code>$ ruby --version\nruby 1.8.6 (2008-06-20 patchlevel 230) [i486-linux]\n$ ruby -w test.rb \n$\n</code></pre>\n\n<p>No errors!</p>\n'}, {'answer_id': 103678, 'author': 'fatgeekuk', 'author_id': 17518, 'author_profile': 'https://Stackoverflow.com/users/17518', 'pm_score': 0, 'selected': False, 'text': "<p>The question code got me a little confused.</p>\n\n<p>In general with Ruby, if that happens it's a good sign that I am trying to do things the wrong way.</p>\n\n<p>It might be better to ask a question related to your actual intended outcome, rather than the specifics of a particular 'attack' on your problem. They we can say 'nonono, don't do that, do THIS' or 'ahhhhh, now I understand what you wanna do'</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79466', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14796/']
79,468
<p>What is the best method to transfer data from sales table to sales history table in sql server 2005. sales history table will be used for reporting.</p>
[{'answer_id': 79668, 'author': 'Ricardo C', 'author_id': 232589, 'author_profile': 'https://Stackoverflow.com/users/232589', 'pm_score': 1, 'selected': False, 'text': '<p>Bulkcopy is fast and it will not use the transaction log. One batch run at the end of the day. </p>\n\n<p>Deleting the copied records from your production server is a different situation that needs to be planed on that server\'s maintenance approach/plans. Your reporting server solution should not interfere with or affect the production server.</p>\n\n<p>Keep in mind that your reporting server is not meant to be a backup of the data but rather a copy made exclusively for reporting purposes.</p>\n\n<p>Also check on the server settings of your reporting server to be on <a href="http://technet.microsoft.com/en-us/library/ms191164.aspx" rel="nofollow noreferrer">Simple recovery model</a>.</p>\n'}, {'answer_id': 79705, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Most solutions will require 2 steps;\n-copy the records from source to target\n-delete records from source.\nIt is essential that your source table have a primary key.</p>\n\n<p>The "best" method depends on a lot of things.<br>\nHow many records? \nIs this a production environment? \nWhat tools do you have?</p>\n'}, {'answer_id': 79786, 'author': 'Nat', 'author_id': 13813, 'author_profile': 'https://Stackoverflow.com/users/13813', 'pm_score': 0, 'selected': False, 'text': '<p>Unless you are moving a large amount of data, a simple stored procedure should do the trick. \nA <a href="http://msdn.microsoft.com/en-us/library/ms187910.aspx" rel="nofollow noreferrer">sql server job</a> can manage the timing of when to call the proc.</p>\n'}, {'answer_id': 79889, 'author': 'jason saldo', 'author_id': 1293, 'author_profile': 'https://Stackoverflow.com/users/1293', 'pm_score': 1, 'selected': False, 'text': '<p>Take a look at SSAS. OLAP is built for reporting and is easy to query with tools like excel pivot tables.</p>\n'}, {'answer_id': 11977761, 'author': 'AtharvaI', 'author_id': 354502, 'author_profile': 'https://Stackoverflow.com/users/354502', 'pm_score': 0, 'selected': False, 'text': '<p>if you just want to move the data to another table, use BulkCopy/BulkInsert. if you want to build reporting I would suggest a BI solution such as MS Analysis Service (OLAP). </p>\n\n<p>It is difficult and in my opinion ugly to maintain two or more history/archive tables in the same database. For a reporting solution you will be considering all the tables for that piece of information anyway. History/Archive tables should only be used if you are going to put the data away and not touch it for a long period of time, ie. archive it away outside the operational DB.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79468', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14752/']
79,474
<p>I've set up Passenger in development (Mac OS X) and it works flawlessly. The only problem came later: now I have a custom <code>GEM_HOME</code> path and ImageMagick binaries installed in <code>"/usr/local"</code>. I can put them in one of the shell rc files that get sourced and this solves the environment variables for processes spawned from the console; but what about Passenger? The same application cannot find my gems when run this way.</p>
[{'answer_id': 79615, 'author': 'Brian Phillips', 'author_id': 7230, 'author_profile': 'https://Stackoverflow.com/users/7230', 'pm_score': 1, 'selected': False, 'text': '<p>I\'ve run into this issue as well. It <a href="http://groups.google.com/group/phusion-passenger/browse_thread/thread/79474d37028f2a03" rel="nofollow noreferrer">appears</a> that Passenger doesn\'t passthrough values set using the <code>SetEnv</code> apache directive - which is unfortunate.</p>\n\n<p>Perhaps it might be possible to set environment variables in your environment.rb or boot.rb (assuming you\'re talking about a Rails app; I\'m not familiar with Rack but presumably it has similar functionality)</p>\n'}, {'answer_id': 80003, 'author': 'manveru', 'author_id': 8367, 'author_profile': 'https://Stackoverflow.com/users/8367', 'pm_score': 2, 'selected': False, 'text': "<p>Before you do any requires (especially before requiring rubygems) you can do:</p>\n\n<pre><code>ENV['GEM_HOME'] = '/foo'\n</code></pre>\n\n<p>This will change the environment variable inside this process.</p>\n"}, {'answer_id': 81255, 'author': 'Ben Scofield', 'author_id': 6478, 'author_profile': 'https://Stackoverflow.com/users/6478', 'pm_score': 5, 'selected': True, 'text': '<p>I know of two solutions. The first (documented <a href="http://www.viget.com/extend/rubyinline-in-shared-rails-environments/" rel="noreferrer">here</a>) is essentially the same as manveru\'s—set the ENV variable directly in your code.</p>\n\n<p>The second is to create a wrapper around the Ruby interpreter that Passenger uses, and is documented <a href="http://blog.rayapps.com/2008/05/21/using-mod_rails-with-rails-applications-on-oracle/" rel="noreferrer">here</a> (look for passenger_with_ruby). The gist is that you create (and point PassengerRuby in your Apache config to) /usr/bin/ruby_with_env, an executable file consisting of:</p>\n\n<pre><code>#!/bin/bash\nexport ENV_VAR=value\n/usr/bin/ruby $*\n</code></pre>\n\n<p>Both work; the former approach is a little less hackish, I think.</p>\n'}, {'answer_id': 363314, 'author': 'Raimonds Simanovskis', 'author_id': 16829, 'author_profile': 'https://Stackoverflow.com/users/16829', 'pm_score': 2, 'selected': False, 'text': '<p>I found out that if you have root priviledges on computer then you can set necessary environment variables in "envvars" file and apachectl will execute this file before starting Apache.</p>\n\n<p>envvars typically is located in the same directory where apachectl is located - on Mac OS X it is located in /usr/sbin. If you cannot find it then look in the source of apachectl script.</p>\n\n<p>After changing envvars file restart Apache with "apachectl -k restart".</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79474', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11687/']
79,476
<p>I've computed the mean &amp; variance of a set of values, and I want to pass along the value that represents the # of std deviations away from mean for each number in the set. Is there a better term for this, or should I just call it num_of_std_devs_from_mean ...</p>
[{'answer_id': 79484, 'author': 'neuroguy123', 'author_id': 12529, 'author_profile': 'https://Stackoverflow.com/users/12529', 'pm_score': 1, 'selected': False, 'text': '<p>That is normalizing your values. You could just refer to it as the normalized value. Maybe norm_val would be more appropriate.</p>\n'}, {'answer_id': 79486, 'author': 'etchasketch', 'author_id': 14640, 'author_profile': 'https://Stackoverflow.com/users/14640', 'pm_score': 2, 'selected': False, 'text': '<p>The standard deviation is usually denoted with the letter σ (sigma). Personally, I think more people will understand what you mean if you do say number of standard deviations.</p>\n\n<p>As for a variable name, as long as you comment the declaration you could shorten it to std_devs.</p>\n'}, {'answer_id': 79492, 'author': 'Kevin Little', 'author_id': 14028, 'author_profile': 'https://Stackoverflow.com/users/14028', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://en.wikipedia.org/wiki/Standard_deviation" rel="nofollow noreferrer">sigma</a> is what you want, I think.</p>\n'}, {'answer_id': 79509, 'author': 'mbowcock', 'author_id': 8758, 'author_profile': 'https://Stackoverflow.com/users/8758', 'pm_score': 0, 'selected': False, 'text': "<p>I've always heard it as number of standard deviations</p>\n"}, {'answer_id': 79549, 'author': 'ckarras', 'author_id': 5688, 'author_profile': 'https://Stackoverflow.com/users/5688', 'pm_score': 4, 'selected': True, 'text': '<p>Some suggestions here:\n<a href="http://en.wikipedia.org/wiki/Standard_score" rel="noreferrer">Standard score</a> (z-value, z-score, normal score)</p>\n\n<p>but "sigma" or "stdev_distance" would probably be clearer</p>\n'}, {'answer_id': 79630, 'author': 'Kevin Haines', 'author_id': 10410, 'author_profile': 'https://Stackoverflow.com/users/10410', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://en.wikipedia.org/wiki/Deviation_(statistics)" rel="nofollow noreferrer">Deviation</a> may be what you\'re after. Deviation is the distance between a data point and the mean.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79476', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14799/']
79,482
<p>I'm trying to replace some bespoke message queues with ActiveMQ, and I need to talk to them (a lot) from Perl. ActiveMQ provides a Stomp interface and Perl has Net::Stomp, so this seems like it should be fine, but it's not.</p> <p>Even if I send a BEGIN command over Stomp, messages sent with SEND are immediately published, and if I ABORT the transaction, nothing happens.</p> <p>I can't find any clear answers suggesting that suggest it's not possible, that is is possible, or that there's a relevant bit of configuration. Also, Stomp doesn't seem to be a great protocol for checking for error responses from the server.</p> <p>Am I out of luck?</p>
[{'answer_id': 81006, 'author': 'James Strachan', 'author_id': 2068211, 'author_profile': 'https://Stackoverflow.com/users/2068211', 'pm_score': 2, 'selected': False, 'text': '<p>BTW the best place to ask Perl/ActiveMQ/Stomp questions is the <a href="http://activemq.apache.org/discussion-forums.html" rel="nofollow noreferrer">ActiveMQ user forum</a> as lots of Perl-Stomp folks hang out there.</p>\n\n<p>The trick with STOMP transactions is to make sure each message you send or each acknowledgement you make includes the transaction ID header. See the <a href="http://stomp.codehaus.org/Transaction+Handling" rel="nofollow noreferrer">transaction handling section of the STOMP protocol</a>. </p>\n\n<p>The reason for this is that with STOMP you could have many transactions taking place at the same time if your client is multi threaded - along with some non-transacted operations.</p>\n'}, {'answer_id': 93611, 'author': 'huguei', 'author_id': 17856, 'author_profile': 'https://Stackoverflow.com/users/17856', 'pm_score': 1, 'selected': False, 'text': '<p>Have a look at <a href="http://search.cpan.org/~huguei/Net-Stomp-Receipt-0.34/lib/Net/Stomp/Receipt.pm" rel="nofollow noreferrer">Net::Stomp::Receipt</a>. It\'s a subclass of Net::Stomp that implements "return receipts" from the Stomp protocol, and allow you to make sure the correct reception of your message, and abort the transaction otherwise.</p>\n'}, {'answer_id': 607425, 'author': 'Phillip Whelan', 'author_id': 25305, 'author_profile': 'https://Stackoverflow.com/users/25305', 'pm_score': 1, 'selected': False, 'text': '<p>You have to wrap the acknowledgements inside a transaction.</p>\n\n<p>In pseudocode (or pseudo STOMP) this would be:</p>\n\n<ul>\n<li>BEGIN [TRANSACTION-ID] -> send to server</li>\n<li>MESSAGE [MESSAGE-ID] (received) &lt;- received from server</li>\n<li>ACK [MESSAGE-ID] [TRANSACTION-ID] -> send to server</li>\n<li>COMMIT [TRANSACTION-ID] -> send to server</li>\n</ul>\n\n<p>I have already gotten this working with the PHP driver (patching the abort call to use the transaction ID when I pass in a frame object to acknowledge).</p>\n\n<p>Unfortunately, after redelivering four messages the client stops. At least this happens to me.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79482', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10478/']
79,490
<p>How can I get a history of uptimes for my debian box? After a reboot, I dont see an option for the uptime command to print a history of uptimes. If it matters, I would like to use these uptimes for graphing a page in php to show my webservers uptime lengths between boots.</p> <p>Update: Not sure if it is based on a length of time or if last gets reset on reboot but I only get the most recent boot timestamp with the last command. last -x also does not return any further info. Sounds like a script is my best bet.</p> <p>Update: Uptimed is the information I am looking for, not sure how to grep that info in code. Managing my own script for a db sounds like the best fit for an application.</p>
[{'answer_id': 79503, 'author': 'John Boker', 'author_id': 2847, 'author_profile': 'https://Stackoverflow.com/users/2847', 'pm_score': 1, 'selected': False, 'text': '<p>i dont think this information is saved between reboots.</p>\n\n<p>if shutting down properly you could run a command on shutdown that saves the uptime, that way you could read it back after booting back up.</p>\n'}, {'answer_id': 79515, 'author': 'roo', 'author_id': 716, 'author_profile': 'https://Stackoverflow.com/users/716', 'pm_score': 5, 'selected': False, 'text': '<p>the <a href="http://linux.about.com/library/cmd/blcmdl1_last.htm" rel="noreferrer"><code>last</code></a> command will give you the reboot times of the system. You could take the difference between each successive reboot and that should give the uptime of the machine.</p>\n\n<p><strong>update</strong></p>\n\n<p><a href="https://stackoverflow.com/questions/79490/linux-uptime-history#79553">1800 INFORMATION</a> answer is a better solution.</p>\n'}, {'answer_id': 79530, 'author': 'Kyle Cronin', 'author_id': 658, 'author_profile': 'https://Stackoverflow.com/users/658', 'pm_score': 1, 'selected': False, 'text': '<p>This information is not normally saved. However, you can sign up for an online service that will do this for you. You just install a client that will send your uptime to the server every 5 minutes and the site will present you with a graph of your uptimes:</p>\n\n<p><a href="http://uptimes-project.org/" rel="nofollow noreferrer">http://uptimes-project.org/</a></p>\n'}, {'answer_id': 79535, 'author': 'Shermozle', 'author_id': 10788, 'author_profile': 'https://Stackoverflow.com/users/10788', 'pm_score': 2, 'selected': False, 'text': '<p>This isn\'t stored between boots, but <a href="http://www.uptimes-project.org" rel="nofollow noreferrer">The Uptimes Project</a> is a third-party option to track it, with software for a range of platforms.</p>\n\n<p>Another tool available on Debian is <a href="http://podgorny.cz/moin/Uptimed" rel="nofollow noreferrer">uptimed</a> which tracks uptimes between boots.</p>\n'}, {'answer_id': 79540, 'author': 'etchasketch', 'author_id': 14640, 'author_profile': 'https://Stackoverflow.com/users/14640', 'pm_score': 6, 'selected': True, 'text': '<p>You could create a simple script which runs uptime and dumps it to a file.</p>\n\n<pre><code>uptime &gt;&gt; uptime.log\n</code></pre>\n\n<p>Then set up a cron job for it.</p>\n'}, {'answer_id': 79553, 'author': '1800 INFORMATION', 'author_id': 3146, 'author_profile': 'https://Stackoverflow.com/users/3146', 'pm_score': 6, 'selected': False, 'text': '<p>Install <a href="https://github.com/rpodgorny/uptimed" rel="nofollow noreferrer">uptimed</a>. It does exactly what you want.</p>\n\n<p>Edit:</p>\n\n<p>You can apparantly include it in a PHP page as easily as this:</p>\n\n<pre><code>&lt;? system("/usr/local/bin/uprecords -a -B"); ?&gt;\n</code></pre>\n\n<p><a href="https://web.archive.org/web/20090228064718/http://www.robertjohnkaper.com/software/uptimed/example.html" rel="nofollow noreferrer">Examples</a></p>\n'}, {'answer_id': 79699, 'author': 'paxdiablo', 'author_id': 14860, 'author_profile': 'https://Stackoverflow.com/users/14860', 'pm_score': 2, 'selected': False, 'text': "<p>I would create a cron job to run at the required resolution (say 10 minutes) by entering the following [on <em>one</em> single line - I've just separated it for formatting purposes] in your crontab (cron -l to list, cron -e to edit).</p>\n\n<pre><code>0,10,20,30,40,50 * * * *\n /bin/echo $(/bin/date +\\%Y-\\%m-\\%d) $(/usr/bin/uptime)\n &gt;&gt;/tmp/uptime.hist 2&gt;&amp;1\n</code></pre>\n\n<p>This appends the date, time and uptime to the uptime.hist file every ten minutes while the machine is running. You can then examine this file manually to figure out the information or write a script to process it as you see fit.</p>\n\n<p>Whenever the uptime reduces, there's been a reboot since the previous record. When there are large gaps between lines (i.e., more than the expected ten minutes), the machine's been down during that time.</p>\n"}, {'answer_id': 80135, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>Try this out: </p>\n\n<pre><code>last | grep reboot \n</code></pre>\n'}, {'answer_id': 6330117, 'author': 'Slet', 'author_id': 792504, 'author_profile': 'https://Stackoverflow.com/users/792504', 'pm_score': 1, 'selected': False, 'text': '<p>Or you can use tuptime <a href="https://sourceforge.net/projects/tuptime/" rel="nofollow">https://sourceforge.net/projects/tuptime/</a> for a total uptime time.</p>\n'}, {'answer_id': 18943901, 'author': 'sepehr', 'author_id': 184176, 'author_profile': 'https://Stackoverflow.com/users/184176', 'pm_score': 4, 'selected': False, 'text': '<p>according to <code>last</code> manual page:</p>\n\n<blockquote>\n <p>The pseudo user reboot logs in each time the system is rebooted.\n Thus last reboot will show a log of all reboots since the log file\n was created.</p>\n</blockquote>\n\n<p>so last column of <code>#last reboot</code> command gives you uptime history:</p>\n\n<pre><code>#last reboot\nreboot system boot **************** Sat Sep 21 03:31 - 08:27 (1+04:56) \nreboot system boot **************** Wed Aug 7 07:08 - 08:27 (46+01:19)\n</code></pre>\n'}, {'answer_id': 20195042, 'author': 'peterh', 'author_id': 1783163, 'author_profile': 'https://Stackoverflow.com/users/1783163', 'pm_score': 0, 'selected': False, 'text': '<p>Nagios can make even very beautiful diagrams about this.</p>\n'}, {'answer_id': 23121600, 'author': 'rfmoz', 'author_id': 793908, 'author_profile': 'https://Stackoverflow.com/users/793908', 'pm_score': 1, 'selected': False, 'text': '<p>You can use tuptime, a simple command for report the total uptime in linux keeping it betwwen reboots.</p>\n\n<p><a href="http://sourceforge.net/projects/tuptime/" rel="nofollow">http://sourceforge.net/projects/tuptime/</a></p>\n'}, {'answer_id': 55663620, 'author': 'Jan Schermer', 'author_id': 11355087, 'author_profile': 'https://Stackoverflow.com/users/11355087', 'pm_score': 1, 'selected': False, 'text': '<p>Since I haven\'t found an answer here that would help retroactively, maybe this will help someone.</p>\n\n<p>kern.log (depending on your distribution) should log a timestamp.\nIt will be something like:\n2019-01-28T06:25:25.459477+00:00 someserver kernel: [44114473.614361] somemessage</p>\n\n<p>"44114473.614361" represents seconds since last boot, from that you can calculate the uptime without having to install anything.</p>\n'}, {'answer_id': 62146140, 'author': 'sebisnow', 'author_id': 6207983, 'author_profile': 'https://Stackoverflow.com/users/6207983', 'pm_score': 0, 'selected': False, 'text': '<h1>Use Syslog</h1>\n\n<p>For anyone coming here searching for their past uptime.\nThe solution of @1800_Information is a good advise for the future, but I needed to find information for my past uptimes on a specific date.</p>\n\n<p>Therefore I used syslog to determine when that day the system was started (first log entry of that day) and when the system was shutdown again.</p>\n\n<h2>Boot time</h2>\n\n<p>To get the system start time grep for the month and day and show only the first lines:</p>\n\n<pre><code>sudo grep "May 28" /var/log/syslog* | head\n</code></pre>\n\n<h2>Shutdown time</h2>\n\n<p>To get the system shutdown time grep for the month and day and show only the last few lines:</p>\n\n<pre><code>sudo grep "May 28" /var/log/syslog* | tail\n</code></pre>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79490', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/777/']
79,493
<p>I want to use Apple's or RedHat's built-in Apache but I want to use Perl 5.10 and mod_perl. What's the least intrusive way to accomplish this? I want the advantage of free security patching for the vendor's Apache, dav, php, etc., but I care a lot about which version of Perl I use and what's in my @INC path. I don't mind compiling my own mod_perl.</p>
[{'answer_id': 79696, 'author': 'Ian', 'author_id': 2311, 'author_profile': 'https://Stackoverflow.com/users/2311', 'pm_score': 1, 'selected': False, 'text': '<p>You\'ll want to look into <a href="http://httpd.apache.org/docs/2.2/mod/mod_so.html" rel="nofollow noreferrer">mod_so</a></p>\n'}, {'answer_id': 80032, 'author': 'Gary Richardson', 'author_id': 2506, 'author_profile': 'https://Stackoverflow.com/users/2506', 'pm_score': 1, 'selected': False, 'text': '<p>I\'ve done this before. It wasn\'t pretty, but it worked, especially since vendor perl\'s are usually 2-3 years old.</p>\n\n<p>I started with making my own perl RPM that installed perl into a different location, like <code>/opt/</code>. This was pretty straight forward. I mostly started with this because I didn\'t want the system utilities that used perl to break when I upgraded/installed new modules. I had to modify all my scripts to specify <code>#!/opt/bin/perl</code> at the top and sometimes I even played with the path to make sure my perl came first.</p>\n\n<p>Next, I grabbed a mod_perl source RPM and modified it to use my <code>/opt/bin/perl</code> instead of <code>/usr/bin/perl</code>. I don\'t have access to the changes I made, since it was at a different gig. It took me a bit of playing around to get it. </p>\n\n<p>It did work, but I\'m not an RPM wizard, so dependency checking didn\'t work out so well. For example, I could uninstall my custom RPM and break everything. It wasn\'t a big deal for me, so I moved on.</p>\n\n<p>I was also mixing RPM\'s with CPAN installs of modules (did I mention we built our own custom CPAN mirror with our own code?). This was a bit fragile too. Again, I didn\'t have the resources (ie, time) to figure out how to bend <a href="http://sourceforge.net/projects/cpan2rpm/" rel="nofollow noreferrer">cpan2rpm</a> to use my perl and not cause RPM conflicts.</p>\n\n<p>If I had it all to do again, I would make a custom 5.10 perl RPM and just replace the system perl. Then I would use <code>cpan2rpm</code> to create the RPM packages I needed for my software and compile my own mod_perl RPM.</p>\n'}, {'answer_id': 83080, 'author': 'Michael Cramer', 'author_id': 1496728, 'author_profile': 'https://Stackoverflow.com/users/1496728', 'pm_score': 4, 'selected': True, 'text': "<ol>\n<li><p>Build your version of Perl 5.10 following any special instructions from the mod_perl documentation. Tell Perl configurator to install in some non-standard place, like /usr/local/perl/5.10.0</p></li>\n<li><p>Use the instructions to build a shared library (or dynamic, or .so) mod_perl against your distribution's Apache, but make sure you run the Makefile.PL using <em>your</em> version of perl:</p>\n\n<p>/usr/local/perl/5.10.0/bin/perl Makefile.PL APXS=/usr/bin/apxs</p></li>\n<li><p>Install and configure mod_perl like normal.</p></li>\n</ol>\n\n<p>It may be helpful, after step one, to change your path so you don't accidentially get confused about which version of Perl you're using:</p>\n\n<pre><code>export PATH=/usr/local/perl/5.10.0/bin:$PATH\n</code></pre>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79493', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14783/']
79,496
<p>I am looking for a way to connect to Facebook by allowing the user to enter in their username and password and have our app connect to their account and get their contacts so that they can invite them to join their group on our site. I have written a Facebook app before, but this is not an app as much as it is a connector so that they can invite all their friends or just some to the site we are working on.</p> <p>I have seen several other sites do this and also connect to Yahoo, Gmail and Hotmail contacts. I don't think they are using Facebook Connect to do this since it is so new, but they may be. </p> <p>Any solution in any language is fine as I can port whatever example to use C#. I cannot find anything specifically on Google or Facebook to address this specific problem. Any help is appreciated. </p> <p>I saw a first answer get removed that had suggested I might need to scrape the friends page. The more I look around, this might be what I need to do. Any other way I think will require the person to add it as an app. I am wondering how a answer can get removed, maybe that user deleted it.</p>
[{'answer_id': 79571, 'author': 'Coda', 'author_id': 14807, 'author_profile': 'https://Stackoverflow.com/users/14807', 'pm_score': 2, 'selected': False, 'text': '<p>Seems like Facebook has an api for this. Check this blog here.</p>\n\n<p><a href="http://developers.facebook.com/news.php?blog=1&amp;story=73" rel="nofollow noreferrer">http://developers.facebook.com/news.php?blog=1&amp;story=73</a></p>\n'}, {'answer_id': 79593, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 3, 'selected': False, 'text': "<p>Not answering the question but hopefully providing some insight...</p>\n\n<p>It's features like this that teach people that it is ok to enter their username and password for site A on a form from site B. This is most definitely not ok. Please do not make people think it is.</p>\n\n<p>But maybe the Facebook API allows you to circumvent this problem, by making people log into <em>Facebook itself</em> to give your app access. A slight but important difference.</p>\n"}, {'answer_id': 93582, 'author': 'Jim Zimmerman', 'author_id': 11196, 'author_profile': 'https://Stackoverflow.com/users/11196', 'pm_score': 2, 'selected': False, 'text': '<p>I looked up that it is alright to answer my own post, so here it is. </p>\n\n<p>It turns out that you will have to scrape the friends list which is not legal in facebook terms of use. So we will not be doing this for our sites. Here are a few articles that show what happens when you don\'t play by the rules. Plaxo tested their scraping with Scoble and Facebook shut down Scobles account in January of this year.</p>\n\n<p><a href="http://scobleizer.com/2008/01/03/what-i-was-using-to-hit-facebook/" rel="nofollow noreferrer">http://scobleizer.com/2008/01/03/what-i-was-using-to-hit-facebook/</a></p>\n\n<p><a href="http://news.cnet.com/8301-13577_3-9839474-36.html" rel="nofollow noreferrer">http://news.cnet.com/8301-13577_3-9839474-36.html</a></p>\n'}, {'answer_id': 286351, 'author': 'Justin Yost', 'author_id': 657, 'author_profile': 'https://Stackoverflow.com/users/657', 'pm_score': 1, 'selected': False, 'text': '<p>Here is an open source PHP 5 tool to let you import contacts from both e-mail and some social networks including Facebook: <a href="http://openinviter.com/index.php" rel="nofollow noreferrer">OpenInviter</a> is an open source PHP class, written in PHP5, for importing contacts from most of the well-known e-mail providers &amp; social networks.</p>\n'}, {'answer_id': 1056322, 'author': 'Jim Zimmerman', 'author_id': 11196, 'author_profile': 'https://Stackoverflow.com/users/11196', 'pm_score': 3, 'selected': True, 'text': '<p>I asked this question awhile ago and before facebook connect was live and well. The best way to really do this is using facebook connect.</p>\n\n<p><a href="http://developers.facebook.com/connect.php?tab=website" rel="nofollow noreferrer">http://developers.facebook.com/connect.php?tab=website</a></p>\n\n<p>I am currently using this on our live site and using the Facebook Developer Toolkit for .NET on Codeplex here: </p>\n\n<p><a href="http://www.codeplex.com/FacebookToolkit" rel="nofollow noreferrer">http://www.codeplex.com/FacebookToolkit</a></p>\n\n<p>Good luck!</p>\n'}, {'answer_id': 1606882, 'author': 'Jon Hadley', 'author_id': 161525, 'author_profile': 'https://Stackoverflow.com/users/161525', 'pm_score': 3, 'selected': False, 'text': '<p>You can use <a href="https://developers.facebook.com/docs/guides/web/" rel="nofollow noreferrer">Facebook Connect</a> \'Account Linking\'.</p>\n\n<p>Python/Django example from <a href="https://developers.facebook.com/docs/reference/fbml/request-form/" rel="nofollow noreferrer">Facebook developers wiki</a>:</p>\n\n<p><strong>Page:</strong></p>\n\n<pre class="lang-py prettyprint-override"><code>def invite_friends(request): \n #HTML escape function for invitation content. \n from cgi import escape \n facebook_uid = request.facebook.uid \n\n # Convert the array of friends into a comma-delimeted string. \n exclude_ids = ",".join([str(a) for a in request.facebook.friends.getAppUsers()]) \n\n # Prepare the invitation text that all invited users will receive. \n content = """&lt;fb:name uid="%s" firstnameonly="true" shownetwork="false"/&gt; wants to invite you to play Online board games, &lt;fb:req-choice url="%s" label="Put Online Gaming and Video Chat on your profile!"/&gt;""" % (facebook_uid, request.facebook.get_add_url()) \n\n invitation_content = escape(content, True) \n return render_to_response(\'facebook/invite_friends.fbml\',\n {\'content\': invitation_content, \'exclude_ids\': exclude_ids })\n</code></pre>\n\n<p><strong>Template:</strong></p>\n\n<pre class="lang-html prettyprint-override"><code>&lt;fb:request-form action="http://apps.facebook.com/livevideochat/?skipped=1" \n method="POST" invite="true" type="Online Games" \n content="{{ content }}"&gt; \n\n &lt;fb:multi-friend-selector max="20" \n actiontext="Here are your friends who aren\'t using Online Games and Live Video Chat. Invite them to play Games Online today!" \n showborder="true" rows="5" exclude_ids="{{ exclude_ids }}"&gt; &lt;/fb:request-form&gt;\n</code></pre>\n'}, {'answer_id': 6652394, 'author': 'John', 'author_id': 839154, 'author_profile': 'https://Stackoverflow.com/users/839154', 'pm_score': -1, 'selected': False, 'text': '<p>Just import them into Yahoo using FB Connect. All better? No screen scraping, no FB violations. Done.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79496', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11196/']
79,498
<p>I have determined that my JSON, coming from the server, is valid (making the ajax call manually), but I would really like to use JQuery. I have also determined that the "post" URL, being sent to the server, is correct, using firebug. However, the error callback is still being triggered (parse error). I also tried datatype: text.</p> <p>Are there other options that I should include?</p> <pre><code>$(function() { $("#submit").bind("click", function() { $.ajax({ type: "post", url: "http://myServer/cgi-bin/broker" , datatype: "json", data: {'start' : start,'end' : end}, error: function(request,error){ alert(error); }, success: function(request) { alert(request.length); } }); // End ajax }); // End bind }); // End eventlistener </code></pre>
[{'answer_id': 79617, 'author': 'Adam Weber', 'author_id': 9324, 'author_profile': 'https://Stackoverflow.com/users/9324', 'pm_score': 5, 'selected': True, 'text': '<p>Here are a few suggestions I would try:</p>\n\n<p>1) the \'datatype\' option you have specified should be \'dataType\' (case-sensitive I believe)</p>\n\n<p>2) try using the \'contentType\' option as so:</p>\n\n<pre><code>contentType: "application/json; charset=utf-8"\n</code></pre>\n\n<p>I\'m not sure how much that will help as it\'s used in the request to your post url, not in the response.\nSee this article for more info: <a href="http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax" rel="noreferrer">http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax</a>\n(It\'s written for asp.net, but may be applicable)</p>\n\n<p>3) Triple check the output of your post url and run the output through a JSON validator just to be absolutely sure it\'s valid and can be parsed into a JSON object. <a href="http://www.jsonlint.com" rel="noreferrer">http://www.jsonlint.com</a></p>\n\n<p>Hope some of this helps!</p>\n'}, {'answer_id': 6434910, 'author': 'Big Al', 'author_id': 809665, 'author_profile': 'https://Stackoverflow.com/users/809665', 'pm_score': 0, 'selected': False, 'text': '<p>The data parameter is wrong. Here is an example that works:</p>\n\n<p>data: { index: ddl.selectedIndex },</p>\n\n<p>This contructs an object with property called index with value ddl.selectedIndex.</p>\n\n<p>You need to remove the quotes from your data parameter line</p>\n\n<p>Good luck\nA</p>\n'}, {'answer_id': 9664708, 'author': 'Bohdan Hdal', 'author_id': 801142, 'author_profile': 'https://Stackoverflow.com/users/801142', 'pm_score': 1, 'selected': False, 'text': '<p>Why <code>myResult</code> instead of <code>request</code>?</p>\n\n<pre><code>success: function(request) {\n alert(myResult.length);\n}\n</code></pre>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79498', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2755/']
79,533
<p>I would like to ask some advices or experiences from architecture or technology for building real-time system. Before I have some experience on developing "Queuing Management System", I have done by sending TcpServer and TcpClient message to all operators when a operator changed the queue number. But I think this strategy a lot complicated and issues.</p> <p>Could anyone guide me some ideas or frameworks?</p>
[{'answer_id': 79616, 'author': 'etchasketch', 'author_id': 14640, 'author_profile': 'https://Stackoverflow.com/users/14640', 'pm_score': 0, 'selected': False, 'text': '<p>I havent worked on anything real-time, but I would assume that looking into <a href="http://www.ibm.com/developerworks/linux/library/l-real-time-linux/" rel="nofollow noreferrer">real-time linux</a> would be a good start to understanding the problems and solutions they have come up with dealing with real-time applications.</p>\n'}, {'answer_id': 79847, 'author': 'moobaa', 'author_id': 3569, 'author_profile': 'https://Stackoverflow.com/users/3569', 'pm_score': 3, 'selected': False, 'text': '<p>First up: hardcore real-time peeps will take issue with the use of ".NET" and "real-time" in the same sentence, due to .NET\'s non-deterministic nature ;)</p>\n\n<p>Having said that, if you\'re just implementing a supervisory or visualisation layer over an existing real-time system (say, implementing a SCADA-type system), then .NET should be fine. Then your network architecture can boil down to two scenarios:</p>\n\n<ul>\n<li>Clients poll from a server: you create a centralised server which contains much of your process logic, and clients poll from this server periodically.</li>\n<li>Server supports a publish/subscribe mechanism: clients subscribe to the server\'s information, and the server sends out updates when they occur.</li>\n</ul>\n\n<p>There\'s no one "right" way to do the above comms; it depends a lot on size and frequency of updates, network traffic, etc.</p>\n'}, {'answer_id': 162431, 'author': 'harriyott', 'author_id': 5744, 'author_profile': 'https://Stackoverflow.com/users/5744', 'pm_score': 0, 'selected': False, 'text': '<p>I\'d recommend looking at <a href="http://www.qnx.com" rel="nofollow noreferrer">QNX</a>.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79533', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14808/']
79,536
<p>Besides full-text indexing and using LIKE keyword, what are other tools to build search functionality on top of MS SQL? This question is particularly for searching records, not files.</p>
[{'answer_id': 79563, 'author': 'jimg', 'author_id': 2621, 'author_profile': 'https://Stackoverflow.com/users/2621', 'pm_score': 2, 'selected': False, 'text': '<p>2008\'s <a href="http://technet.microsoft.com/en-us/library/cc721269.aspx" rel="nofollow noreferrer">full text search capabilities</a> have been improved - perhaps look there first..</p>\n'}, {'answer_id': 79573, 'author': 'Martin08', 'author_id': 8203, 'author_profile': 'https://Stackoverflow.com/users/8203', 'pm_score': 1, 'selected': False, 'text': '<p>I believe MS SQL 2005+ has the capability to search using regular expression. </p>\n\n<p>MSDN has an article about this <a href="http://msdn.microsoft.com/en-us/magazine/cc163473.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/magazine/cc163473.aspx</a>.</p>\n'}, {'answer_id': 79603, 'author': 'Richard McGuire', 'author_id': 5086, 'author_profile': 'https://Stackoverflow.com/users/5086', 'pm_score': 2, 'selected': False, 'text': '<p>In episode 11 of the SO podcast Jeff and Joel discussed full text searching of SQL Server, Joel\'s recommendation was <a href="http://incubator.apache.org/lucene.net/" rel="nofollow noreferrer">Lucene.NET</a>. You can see their discussion in that episode\'s <a href="https://stackoverflow.fogbugz.com/default.asp?W12621" rel="nofollow noreferrer">transcript</a>, it is about a quarter of the way down the page.</p>\n'}, {'answer_id': 598070, 'author': 'Corey Trager', 'author_id': 9328, 'author_profile': 'https://Stackoverflow.com/users/9328', 'pm_score': 2, 'selected': True, 'text': '<p>I documented how I used Lucene.NET in my ASP.NET application BugTracker.NET here:</p>\n\n<p><a href="http://www.ifdefined.com/blog/post/2009/02/Full-Text-Search-in-ASPNET-using-LuceneNET.aspx" rel="nofollow noreferrer">http://www.ifdefined.com/blog/post/2009/02/Full-Text-Search-in-ASPNET-using-LuceneNET.aspx</a></p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79536', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13594/']
79,537
<p>I teach a sort of "lite" C++ programming course to novices ("lite" meaning no pointers, no classes, just plain old C, plus references and STL string and vectors). Students have no previous experience in programming, so I believe that using an interactive debugger would help them understand program flow, variables, and recursion.</p> <p>The course is taught in Linux. Teaching them to use gdb is just overkill (they will not use nor understand most features). I just need something simple but easy to use: to see at which line the program is now, what is in the stack (local variables, previous calls, etc.). I look something similar to old Turbo Pascal or Turbo C++ Borland's debugger, or Visual Studio debugger.</p> <p>Thank you,</p>
[{'answer_id': 79547, 'author': 'jbleners', 'author_id': 542226, 'author_profile': 'https://Stackoverflow.com/users/542226', 'pm_score': 5, 'selected': False, 'text': '<p><a href="http://www.gnu.org/software/ddd/" rel="noreferrer">ddd</a> is a graphical front-end to gdb that is pretty nice. One of the down sides is a classic X interface, but I seem to recall it being pretty intuitive.</p>\n'}, {'answer_id': 79591, 'author': 'Jon Ball', 'author_id': 10216, 'author_profile': 'https://Stackoverflow.com/users/10216', 'pm_score': 4, 'selected': False, 'text': '<p>You may want to check out Eclipse CDT. It provides a C/C++ IDE that runs on multiple platforms (e.g. Windows, Linux, Mac OS X, etc.). Debugging with Eclipse CDT is comparable to using other tools such as Visual Studio.</p>\n\n<p>You can check out the <a href="http://download.eclipse.org/tools/cdt/docs/tutorials/debug_tutorial/cdt_w_debug.htm" rel="noreferrer">Eclipse CDT Debug tutorial</a> that also includes a number of screenshots.</p>\n'}, {'answer_id': 79663, 'author': 'HidekiAI', 'author_id': 7234, 'author_profile': 'https://Stackoverflow.com/users/7234', 'pm_score': 4, 'selected': False, 'text': '<p>Perhaps it is indirect to gdb (because it\'s an IDE), but my recommendations would be <a href="http://www.kdevelop.org/" rel="noreferrer" title="KDevelop">KDevelop</a>. Being quite spoiled with Visual Studio\'s debugger (professionally at work for many years), I\'ve so far felt the most comfortable debugging in KDevelop (as hobby at home, because I could not afford Visual Studio for personal use - until Express Edition came out). It does "look something similar to" Visual Studio compared to other IDE\'s I\'ve experimented with (including Eclipse CDT) when it comes to debugging step-through, step-in, etc (placing break points is a bit awkward because I don\'t like to use mouse too much when coding, but it\'s not difficult).</p>\n'}, {'answer_id': 2773974, 'author': 'CMircea', 'author_id': 161336, 'author_profile': 'https://Stackoverflow.com/users/161336', 'pm_score': 4, 'selected': False, 'text': '<p><a href="http://qt.nokia.com/products/developer-tools" rel="noreferrer">Qt Creator</a>, apart from other goodies, also has a good debugger integration, for CDB, GDB and the Symnbian debugger, on all supported platforms. You don\'t need to use Qt to use the Qt Creator IDE, nor do you need to use QMake - it also has CMake integration, although QMake is very easy to use.</p>\n\n<p>You may want to use Qt Creator as the IDE to teach programming with, consider it has some good features:</p>\n\n<ul>\n<li>Very smart and advanced C++ editor</li>\n<li>Project and build management tools</li>\n<li>QMake and CMake integration</li>\n<li>Integrated, context-sensitive help system</li>\n<li>Excellent visual debugger (CDB, GDB and Symbian)</li>\n<li>Supports GCC and VC++</li>\n<li>Rapid code navigation tools</li>\n<li>Supports Windows, Linux and Mac OS X</li>\n</ul>\n'}, {'answer_id': 8952391, 'author': 'Narek Babajanyan', 'author_id': 1195676, 'author_profile': 'https://Stackoverflow.com/users/1195676', 'pm_score': 5, 'selected': False, 'text': '<p>You could try using <a href="http://sources.redhat.com/insight" rel="noreferrer">Insight</a> a graphical front-end for gdb written by Red Hat\nOr if you use GNOME desktop environment, you can also try <a href="http://projects.gnome.org/nemiver/" rel="noreferrer">Nemiver</a>.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79537', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
79,538
<p>I just installed Ubuntu 8.04 and I'm taking a course in Java so I figured why not install a IDE while I am installing it. So I pick my IDE of choice, Eclipse, and I make a very simple program, Hello World, to make sure everything is running smoothly. When I go to use Scanner for user input I get a very odd error:</p> <p><b>My code:</b><pre>import java.util.Scanner;</p> <p>class test { public static void main (String [] args) { Scanner sc = new Scanner(System.in); System.out.println("hi"); } }</pre></p> <p><b>The output:</b></p> <pre> Exception in thread "main" java.lang.Error: Unresolved compilation problems: Scanner cannot be resolved to a type Scanner cannot be resolved to a type at test.main(test.java:5) </pre>
[{'answer_id': 79551, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 3, 'selected': True, 'text': "<p>The Scanner class is new in Java 5. I do not know what Hardy's default Java environment is, but it is not Sun's and therefore may be outdated.</p>\n\n<p>I recommend installing the package sun-java6-jdk to get the most up-to-date version, then telling Eclipse to use it.</p>\n"}, {'answer_id': 79557, 'author': 'tgdavies', 'author_id': 11002, 'author_profile': 'https://Stackoverflow.com/users/11002', 'pm_score': 0, 'selected': False, 'text': "<p>If you are using a version of Java before 1.5, java.util.Scanner doesn't exist.</p>\n\n<p>Which version of the JDK is your Eclipse project set up to use?</p>\n\n<p>Have a look at Project, Properties, Java Build Path -- look for the 'JRE System Library' entry, which should have a version number next to it.</p>\n"}, {'answer_id': 82475, 'author': 'Lee Theobald', 'author_id': 1900, 'author_profile': 'https://Stackoverflow.com/users/1900', 'pm_score': 0, 'selected': False, 'text': '<p>It could also be that although you are have JDK 1.5 or higher, the project has some specific settings set that tell it to compile as 1.4. You can test this via Project >> Properties >> Java Compiler and ensure the "Compiler Compliance Level" is set to 1.5 or higher.</p>\n'}, {'answer_id': 473785, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I know, It\'s quite a while since the question was posted. But the solution may still be of interest to anyone out there. It\'s actually quite simple...</p>\n\n<p>Under Ubuntu you need to set the java compiler "javac" to use sun\'s jdk instead of any other alternative. The difference to some of the answers posted so far is that I am talking about javac NOT java. To do so fire up a shell and do the following:</p>\n\n<ol>\n<li>As root or sudo type in at command line:</li>\n</ol>\n\n<p><code># update-alternatives --config javac</code></p>\n\n<ol start="2">\n<li><p>Locate the number pointing to sun\'s jdk, type in this number, and hit "ENTER". </p></li>\n<li><p>You\'re done! From now on you can enjoy java.util.Scanner under Ubuntu.</p></li>\n</ol>\n\n<p><code>System.out.println("Say thank you, Mr.");\nScanner scanner = java.util.Scanner(System.in);\nString thanks = scanner.next();\nSystem.out.println("Your welcome.");</code></p>\n'}, {'answer_id': 60959558, 'author': 'boi yeet', 'author_id': 12864849, 'author_profile': 'https://Stackoverflow.com/users/12864849', 'pm_score': 0, 'selected': False, 'text': '<p>You imported Scanner but you\'re not using it. You\'re using Scanner, which requires user inputs. You\'re trying to print out one thing, but you\'re exposing the your program to the fact that you are going to use your own input, so it decides to print "Hello World" after you give a user input. But since you are not deciding what the program will print, the system gets confused since it doesn\'t know what to print. You need something like <code>int a=sc.nextInt();</code> or <code>String b=sc.nextLine();</code> and then give your user input. But you said you want <code>Hello World!</code>, so Scanner is redundant.</p>\n'}, {'answer_id': 68014889, 'author': 'ailar', 'author_id': 16177997, 'author_profile': 'https://Stackoverflow.com/users/16177997', 'pm_score': 0, 'selected': False, 'text': '<pre class="lang-java prettyprint-override"><code>package com.company;\n\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n System.out.print(&quot;Input seconds: &quot;);\n int num = in.nextInt();\n\n for (int i = 1; i &lt;=num; i++) {\n\n if(i%10==3)\n {\n System.out.println(i);\n }\n }\n\n }\n}\n</code></pre>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79538', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/97220/']
79,541
<p>I'm creating a simple form for a site I manage. I use jQuery for my JavaScript. I noticed a large amount of plugins for jQuery and forms. Does anybody have any favorites that they find especially useful? In particular, plugins to help with validation would be the most useful.</p>
[{'answer_id': 79555, 'author': 'Camilo Díaz Repka', 'author_id': 861, 'author_profile': 'https://Stackoverflow.com/users/861', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://plugins.jquery.com/project/validate" rel="nofollow noreferrer">Form Validation</a> is one that comes to my mind. I think is being used here in SO.</p>\n'}, {'answer_id': 80255, 'author': 'Zach', 'author_id': 9128, 'author_profile': 'https://Stackoverflow.com/users/9128', 'pm_score': 3, 'selected': False, 'text': '<p>The jQuery <a href="http://malsup.com/jquery/form/" rel="nofollow noreferrer">Form Plugin</a> is pretty much standard. It handles serializing form fields and AJAX submission.</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79541', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12529/']
79,542
<p>Does anyone know much about the Asp.Net webconfig element <a href="http://msdn.microsoft.com/en-us/library/bb513840.aspx" rel="nofollow noreferrer"></a>? I'm looking at it because I'm implementing an MS Ajax updatepanel in an existing site, and after doing some looking around, on the web I'm not finding a lot of info about it. </p> <p>And to avoid the flood of replies telling me how inefficient the update panel is, and that it's not actually providing any benefit etc. etc. I know! Let's say I've got my reasons for using it and leave it at that.</p> <p>I guess my main question is;, will setting enableCompression="true" and enableCaching="true" help the performace of my update panel in any way?</p>
[{'answer_id': 79559, 'author': 'Quintin Robinson', 'author_id': 12707, 'author_profile': 'https://Stackoverflow.com/users/12707', 'pm_score': 2, 'selected': True, 'text': "<p>Given the traversing of the DOM that is actually happening with an update panel it's generally not the content that is hindering performance.. it is the PC/Browser.</p>\n\n<p>I know this is exactly what you aren't looking for but unless your panel contains a significant amount of data then compression and caching isn't going to help you terribly.</p>\n"}, {'answer_id': 357038, 'author': 'Wavel', 'author_id': 13413, 'author_profile': 'https://Stackoverflow.com/users/13413', 'pm_score': 0, 'selected': False, 'text': "<p>I took this from the scriptresourcehandler documentation:\nBy default, the ScriptResourceHandler class compresses and caches embedded script files for Internet Explorer 7.</p>\n\n<p>So I don't think you'll see any difference if you set enableCompression/enableCaching true because it's already happening if you're using IE7.</p>\n"}]
2008/09/17
['https://Stackoverflow.com/questions/79542', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10696/']
79,582
<p>What is the best compilable scripting language for Win32? I prefer .EXE's because I don't want to install the runtime on the servers first (my company administrates many via remote), but I need to be able to do things like NTFS permissions and (if possible) APIs over the network.</p> <p>There was a small Perl which appeared to be able to do most of this, but it does not seem to have been updated/developed in quite a while. I have wondered about Lua, but I don't know if it has everything I need yet (and don't want to hunt through fifty library sites trying to find out). Any thoughts?</p>
[{'answer_id': 79622, 'author': 'Swaroop C H', 'author_id': 4869, 'author_profile': 'https://Stackoverflow.com/users/4869', 'pm_score': 4, 'selected': True, 'text': '<p>Have you considered using an EXE maker? For example, you can code in Python and use <a href="http://www.py2exe.org" rel="noreferrer">py2exe</a> to create a standalone EXE that runs anywhere (it actually packages Python into the exe, so you don\'t have to install the runtime).</p>\n'}, {'answer_id': 79625, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 2, 'selected': False, 'text': '<p>A scripting language is, almost by definition, not compiled into a standalone executable. So maybe you need to restate your intentions or give some indication about what kind of program you want to create.</p>\n\n<p>C# is a powerful language that compiles to .EXE and allows you to interface with pretty much anything (through native p/invoke calls, if necessary). A basic but very usable Visual Studio for C# can be downloaded for free from the Microsoft website. The .NET runtime is installed on most systems nowadays.</p>\n'}, {'answer_id': 79653, 'author': 'Antti Kissaniemi', 'author_id': 2948, 'author_profile': 'https://Stackoverflow.com/users/2948', 'pm_score': 2, 'selected': False, 'text': '<p>Ruby is my scripting language of choice.</p>\n\n<p>Try <a href="http://www.erikveen.dds.nl/rubyscript2exe/" rel="nofollow noreferrer">RubyScript2Exe</a>.</p>\n'}, {'answer_id': 79818, 'author': 'VonC', 'author_id': 6309, 'author_profile': 'https://Stackoverflow.com/users/6309', 'pm_score': 1, 'selected': False, 'text': '<p>Did you consider <a href="http://www.autoitscript.com/autoit3/" rel="nofollow noreferrer">AutoIt</a> ?</p>\n\n<p>It is a scripting language, and you can quickly transform a script into an exe...</p>\n'}, {'answer_id': 79849, 'author': 'Rob Hansen', 'author_id': 14928, 'author_profile': 'https://Stackoverflow.com/users/14928', 'pm_score': 1, 'selected': False, 'text': '<p>At OSCON 2005, I heard Damien Conway say "the only thing better than Perl is something that works well, even if it\'s not written in Perl."</p>\n\n<p>It\'s good advice. Instead of looking for the <i>best</i> language that can be compiled to an .EXE, worry a lot more about writing it in <i>a</i> language that can be compiled to an .EXE. Use whatever works. Just remember that the quality of your programming matters infinitely more than what language you use.</p>\n\n<p>That said, I like py2exe. YMMV. Good luck!</p>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79582', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14429/']
79,584
<p>I find myself drawn to the Parsing Expression Grammar formalism for describing domain specific languages, but so far the implementation code I've found has been written in languages like Java and Haskell that aren't web server friendly in the shared hosting environment that my organization has to live with.</p> <p>Does anyone know of any PEG libraries or PackRat Parser Generators for Javascript or PHP? Of course code generators in any languages that can produce Javascript or PHP source code would do the trick.</p>
[{'answer_id': 79604, 'author': 'Allen', 'author_id': 6043, 'author_profile': 'https://Stackoverflow.com/users/6043', 'pm_score': 3, 'selected': False, 'text': '<p>There is in fact one for Javascript: OMeta. <a href="http://www.tinlizzie.org/ometa/" rel="nofollow noreferrer">http://www.tinlizzie.org/ometa/</a></p>\n\n<p>I also implemented a version of this in Python: <a href="http://github.com/python-parsley/parsley" rel="nofollow noreferrer">http://github.com/python-parsley/parsley</a></p>\n'}, {'answer_id': 79610, 'author': 'Joe Skora', 'author_id': 14057, 'author_profile': 'https://Stackoverflow.com/users/14057', 'pm_score': -1, 'selected': False, 'text': '<p><strong>Have you looked at <a href="http://www.antlr.org/" rel="nofollow noreferrer">ANTLR</a>?</strong> It produces lexer and parser code, handles abstract syntax trees, lets you insert code the grammar to be injected into the lexer/parser code, and <strong>its available for a variety of languages!</strong></p>\n'}, {'answer_id': 236045, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>look at <a href="https://github.com/leblancmeneses/NPEG" rel="nofollow noreferrer">https://github.com/leblancmeneses/NPEG</a> can easily be converted into php.\nParse tree is created with anonymous functions.</p>\n'}, {'answer_id': 1364204, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>There\'s also <a href="http://freecode.com/projects/kouprey" rel="nofollow noreferrer">Kouprey</a> for JavaScript, which is a very easy to use PEG generator/library.</p>\n'}, {'answer_id': 2476022, 'author': 'David Majda', 'author_id': 277736, 'author_profile': 'https://Stackoverflow.com/users/277736', 'pm_score': 4, 'selected': False, 'text': '<p>I have recently written <a href="http://pegjs.majda.cz/" rel="noreferrer">PEG.js</a>, PEG-based parser generator for JavaScript. It can be used from a command-line or you can try it from your browser.</p>\n'}, {'answer_id': 5318855, 'author': 'jcubic', 'author_id': 387194, 'author_profile': 'https://Stackoverflow.com/users/387194', 'pm_score': 2, 'selected': False, 'text': '<p>php PEG <a href="https://github.com/maetl/php-peg" rel="nofollow">https://github.com/maetl/php-peg</a></p>\n\n<p>This post is really old but I found it through google, and It should have been answered</p>\n'}, {'answer_id': 13337742, 'author': 'ento', 'author_id': 20226, 'author_profile': 'https://Stackoverflow.com/users/20226', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://languagejs.com/" rel="nofollow">Language.js</a>:</p>\n\n<blockquote>\n <p>Language.js is an open source experimental new parser based on PEG (Parsing Expression Grammar), with the special addition of the "naughty OR" operator to handle errors in a unique new way. It makes use of memoization to achieve linear time parsing speed</p>\n</blockquote>\n'}]
2008/09/17
['https://Stackoverflow.com/questions/79584', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14706/']