qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
287,587
<p>I have the following code, I'm trying to get a table with 4 columns across. If I run out of columns, create a new row and make 4 more coumns. rinse. lather. repeat.</p> <pre><code>&lt;tbody&gt; &lt;% int i = 0; foreach (ItmXtnMultimedia multimedia in ViewData.Model.ItmXtnMultimedia) { if (i%4 == 0 &amp;&amp; i== ...
[ { "answer_id": 287667, "author": "Ian P", "author_id": 10853, "author_profile": "https://Stackoverflow.com/users/10853", "pm_score": 0, "selected": false, "text": "<p>You should replace the second if with else if.. Other than that, it's okay.</p>\n\n<pre><code>foreach (ItmXtnMultimedia m...
2008/11/13
[ "https://Stackoverflow.com/questions/287587", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34133/" ]
I have the following code, I'm trying to get a table with 4 columns across. If I run out of columns, create a new row and make 4 more coumns. rinse. lather. repeat. ``` <tbody> <% int i = 0; foreach (ItmXtnMultimedia multimedia in ViewData.Model.ItmXtnMultimedia) { if (i%4 == 0 && i== 0) { %><tr><% } if (i...
What about a little refactor? ``` <% foreach (ItmXtnMultimedia multimedia in ViewData.Model.ItmXtnMultimedia) { manageColumnsForMe( 4 ) %><td><%= multimedia.ImgTag100 %></td><% } %> ``` And the put the other code in a function using a static variable to store i You can reuse the same function with different ...
287,588
<p>Why does the select statement below return two different values ?</p> <pre><code>declare @tempDec decimal set @tempDec = 1.0 / (1.0 + 1.0) select @tempDec, 1.0 / (1.0 + 1.0) </code></pre>
[ { "answer_id": 287605, "author": "Chloraphil", "author_id": 16162, "author_profile": "https://Stackoverflow.com/users/16162", "pm_score": 1, "selected": false, "text": "<p>I found out from a coworker just as I posted this.</p>\n\n<p>You need to specify the default precision and scale.</p...
2008/11/13
[ "https://Stackoverflow.com/questions/287588", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16162/" ]
Why does the select statement below return two different values ? ``` declare @tempDec decimal set @tempDec = 1.0 / (1.0 + 1.0) select @tempDec, 1.0 / (1.0 + 1.0) ```
That's fine for literals like 1.0, but if you're pulling the data from table columns, you need to cast/convert the first evaluated number in your equation: ``` convert(decimal, [col1]) / ([col2] + [col3]) ``` -or- ``` convert(decimal(15, 2), [col1]) / ([col2] + [col3]) ```
287,592
<p>Why does the following have the effect it does - it prints a terminal full of random characters and then exits leaving a command prompt that produces garbage when you type in it. (I tried it because I thought it would produce a seg fault).</p> <p><img src="https://i.stack.imgur.com/kGkf4.png" alt="http://oi38.tinyp...
[ { "answer_id": 287602, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 3, "selected": false, "text": "<p>You are just printing out what is in memory because your loop doesn't stop at the end of the string. Each random byte...
2008/11/13
[ "https://Stackoverflow.com/questions/287592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Why does the following have the effect it does - it prints a terminal full of random characters and then exits leaving a command prompt that produces garbage when you type in it. (I tried it because I thought it would produce a seg fault). ![http://oi38.tinypic.com/r9qxbt.jpg](https://i.stack.imgur.com/kGkf4.png) ```...
It will eventually seg fault, but before that it'll print out whatever bytes are in the same page. That's why you see random chars on the screen. Those may well include escape sequences to change (say) the character encoding of the console. That's why you end up with gibberish when you type on the console after it's e...
287,594
<p>I have a rather simple scenario where I have two tables in which I want to add data. They are managed with primary key/foreign key. I want to add new data into TABLE A and then retrieve the Id and insert into TABLE B. </p> <p>I can certainly do it with a stored procedure, but I'm looking at trying to do it using Li...
[ { "answer_id": 313042, "author": "BigJoe714", "author_id": 37786, "author_profile": "https://Stackoverflow.com/users/37786", "pm_score": 5, "selected": true, "text": "<p>Do you have the relationship defined between the 2 tables in the object relational designed? If so, you can have linq ...
2008/11/13
[ "https://Stackoverflow.com/questions/287594", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31148/" ]
I have a rather simple scenario where I have two tables in which I want to add data. They are managed with primary key/foreign key. I want to add new data into TABLE A and then retrieve the Id and insert into TABLE B. I can certainly do it with a stored procedure, but I'm looking at trying to do it using Linq. What...
Do you have the relationship defined between the 2 tables in the object relational designed? If so, you can have linq take care of assigning the ID property of the second table automatically. Example... Table A – Order OrderId OrderDate Table B – Order Item OrderItemId OrderId ItemId Code (Usin...
287,595
<p>This seems like a very simple and a very common problem. The simplest example I can think of is this:</p> <p>The form has five checkboxes with a "check all/check none" checkbox above them. When a user selects checking all checkboxes, I toggle the states of the "children" - obviously I don't want to fire the check e...
[ { "answer_id": 287659, "author": "Ryan Lundy", "author_id": 5486, "author_profile": "https://Stackoverflow.com/users/5486", "pm_score": 2, "selected": false, "text": "<p>From your other question, I'm going to guess you're using VB .NET. So, RemoveHandler is your best bet. Normally in V...
2008/11/13
[ "https://Stackoverflow.com/questions/287595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35555/" ]
This seems like a very simple and a very common problem. The simplest example I can think of is this: The form has five checkboxes with a "check all/check none" checkbox above them. When a user selects checking all checkboxes, I toggle the states of the "children" - obviously I don't want to fire the check events of a...
I've come across this before and usually seen people do this: ``` /*SNIP*/ private bool isMassUpdate; public void Check1_Check(object sender, EventArgs e) { if(!isMassUpdate) { do some stuff } } /*SNIP*/ ``` You can also detach and reattach the event handlers, however, I'm told this can be a sourc...
287,596
<p>Is it safe to use MS SQL's WITH (NOLOCK) option for select statements and insert statements if you never modify a row, but only insert or delete rows?</p> <p>I..e you never do an UPDATE to any of the rows.</p>
[ { "answer_id": 287635, "author": "Tom H", "author_id": 5696608, "author_profile": "https://Stackoverflow.com/users/5696608", "pm_score": 4, "selected": true, "text": "<p>If you're asking whether or not you'll get data that may no longer be accurate, then it depends on your queries. For e...
2008/11/13
[ "https://Stackoverflow.com/questions/287596", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
Is it safe to use MS SQL's WITH (NOLOCK) option for select statements and insert statements if you never modify a row, but only insert or delete rows? I..e you never do an UPDATE to any of the rows.
If you're asking whether or not you'll get data that may no longer be accurate, then it depends on your queries. For example, if you do something like: ``` SELECT my_id, my_date FROM My_Table WHERE my_date >= '2008-01-01' ``` at the same time that a row is being inserted with a date on or after 2...
287,630
<p>I have a right outer join, that almost does what I want...</p> <pre><code>SELECT users_usr.firstname_usr, users_usr.lastname_usr, credit_acc.given_credit_acc, users_usr.created_usr, users_usr.sitenum_usr, users_usr.original_aff_usr, users_usr.id_usr FROM credit_acc right Outer Join users_usr ON credit_acc.uid_usr =...
[ { "answer_id": 287638, "author": "Robert Gamble", "author_id": 25222, "author_profile": "https://Stackoverflow.com/users/25222", "pm_score": 3, "selected": true, "text": "<pre><code>SELECT\nusers_usr.firstname_usr,\nusers_usr.lastname_usr,\ncredit_acc.given_credit_acc,\nusers_usr.created...
2008/11/13
[ "https://Stackoverflow.com/questions/287630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13704/" ]
I have a right outer join, that almost does what I want... ``` SELECT users_usr.firstname_usr, users_usr.lastname_usr, credit_acc.given_credit_acc, users_usr.created_usr, users_usr.sitenum_usr, users_usr.original_aff_usr, users_usr.id_usr FROM credit_acc right Outer Join users_usr ON credit_acc.uid_usr = users_usr.id_...
``` SELECT users_usr.firstname_usr, users_usr.lastname_usr, credit_acc.given_credit_acc, users_usr.created_usr, users_usr.sitenum_usr, users_usr.original_aff_usr, users_usr.id_usr FROM credit_acc right Outer Join users_usr ON credit_acc.uid_usr = users_usr.id_usr WHERE credit_acc.type_acc = 'init' OR credit_acc.type_ac...
287,632
<p>Very odd problem as this is working perfectly on our old Classic ASP site. We are basically querying the database and exporting around 2200 lines of text to a Text File through Response.Write to be output to a dialog box and allows the user to save the file.</p> <p>Response.Clear() Response.ClearContent() ...
[ { "answer_id": 287637, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 3, "selected": true, "text": "<p>Attach a remote debugger and find where its hanging?</p>\n\n<p>You need to figure out if its the string writer loop, or th...
2008/11/13
[ "https://Stackoverflow.com/questions/287632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Very odd problem as this is working perfectly on our old Classic ASP site. We are basically querying the database and exporting around 2200 lines of text to a Text File through Response.Write to be output to a dialog box and allows the user to save the file. Response.Clear() Response.ClearContent() Response.ClearHea...
Attach a remote debugger and find where its hanging? You need to figure out if its the string writer loop, or the actual query code (which is not provided here).
287,645
<p>I want to discover at run-time ONLY the static Methods of a class, how can I do this? Or, how to differentiate between static and non-static methods.</p>
[ { "answer_id": 287654, "author": "Tom Hawtin - tackline", "author_id": 4725, "author_profile": "https://Stackoverflow.com/users/4725", "pm_score": 9, "selected": true, "text": "<p>Use <code>Modifier.isStatic(method.getModifiers())</code>.</p>\n\n<pre><code>/**\n * Returns the public stat...
2008/11/13
[ "https://Stackoverflow.com/questions/287645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/518/" ]
I want to discover at run-time ONLY the static Methods of a class, how can I do this? Or, how to differentiate between static and non-static methods.
Use `Modifier.isStatic(method.getModifiers())`. ``` /** * Returns the public static methods of a class or interface, * including those declared in super classes and interfaces. */ public static List<Method> getStaticMethods(Class<?> clazz) { List<Method> methods = new ArrayList<Method>(); for (Method meth...
287,655
<p>In OpenGL I'm trying to rotate a camera around a point, with camera being distance r from the point and facing the point when it rotates. In other words, I want the camera to move along the circumference of a circle at a radius r from the center, with the camera facing the center at any point along the circumferen...
[ { "answer_id": 287675, "author": "Alnitak", "author_id": 6782, "author_profile": "https://Stackoverflow.com/users/6782", "pm_score": 6, "selected": true, "text": "<p>You need to either:</p>\n\n<ul>\n<li>rotate the camera around the origin and then translate it (*)</li>\n</ul>\n\n<p>or:</...
2008/11/13
[ "https://Stackoverflow.com/questions/287655", "https://Stackoverflow.com", "https://Stackoverflow.com/users/396/" ]
In OpenGL I'm trying to rotate a camera around a point, with camera being distance r from the point and facing the point when it rotates. In other words, I want the camera to move along the circumference of a circle at a radius r from the center, with the camera facing the center at any point along the circumference. ...
You need to either: * rotate the camera around the origin and then translate it (\*) or: * use `gluLookAt` to keep the camera pointing at the center of the circle (\*) rotation functions normally rotate about the origin. To rotate around another point `P` you have to: * translate(-P) * rotate * translate(P)
287,663
<p>I have 2 handlers using the same form. How do I remove the handlers before adding the new one (C#)?</p>
[ { "answer_id": 287678, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": false, "text": "<p>If you know what those handlers are, just remove them in the same way that you subscribed to them, except with -= ins...
2008/11/13
[ "https://Stackoverflow.com/questions/287663", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6013/" ]
I have 2 handlers using the same form. How do I remove the handlers before adding the new one (C#)?
If you are working in the form itself, you should be able to do something like: PseudoCode: ``` Delegate[] events = Form1.SomeEvent.GetInvokationList(); foreach (Delegate d in events) { Form1.SomeEvent -= d; } ``` From outside of the form, your SOL.
287,679
<p>How do I create tabbed navigation with the "Current" tab highlighted in the UI?</p>
[ { "answer_id": 287688, "author": "Kyle West", "author_id": 34133, "author_profile": "https://Stackoverflow.com/users/34133", "pm_score": 4, "selected": true, "text": "<p>Before MVC I looked at the file path and figured out which tab was currrent. Now it's a lot easier, you can assign the...
2008/11/13
[ "https://Stackoverflow.com/questions/287679", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34133/" ]
How do I create tabbed navigation with the "Current" tab highlighted in the UI?
Before MVC I looked at the file path and figured out which tab was currrent. Now it's a lot easier, you can assign the current tab based on the current controller. Check it out ... Most of the work happens in the usercontrol. ``` public partial class AdminNavigation : ViewUserControl { /// <summary> /// Thi...
287,684
<p>I'm using this simple regular expression to validate a hex string:</p> <pre><code>^[A-Fa-f0-9]{16}$ </code></pre> <p>As you can see, I'm using a quantifier to validate that the string is 16 characters long. I was wondering if I can use another quantifier in the same regex to validate the string length to be either...
[ { "answer_id": 287687, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 3, "selected": false, "text": "<pre><code>^(?:[A-Fa-f0-9]{16}|[A-Fa-f0-9]{18})$\n</code></pre>\n" }, { "answer_id": 287692, "author": "Jon Skeet",...
2008/11/13
[ "https://Stackoverflow.com/questions/287684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24927/" ]
I'm using this simple regular expression to validate a hex string: ``` ^[A-Fa-f0-9]{16}$ ``` As you can see, I'm using a quantifier to validate that the string is 16 characters long. I was wondering if I can use another quantifier in the same regex to validate the string length to be either 16 or 18 (not 17).
I believe ``` ^([A-Fa-f0-9]{2}){8,9}$ ``` will work. This is nice because it generalizes to any even-length string.
287,685
<p>I have a bunch of controls (textbox and combobox) on a form with toolstripcontainer and toolstripbuttons for save, cancel etc for edits. We are using .Net 3.5 SP1<br> There is bunch of logic written in control.lostfocus and control.leave events. These events are not being called when clicked on the toolstrip butto...
[ { "answer_id": 287732, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<p>You can extend those controls and then call the OnLostFocus and OnLeave protected methods of the base class...</p>\n" }, ...
2008/11/13
[ "https://Stackoverflow.com/questions/287685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18169/" ]
I have a bunch of controls (textbox and combobox) on a form with toolstripcontainer and toolstripbuttons for save, cancel etc for edits. We are using .Net 3.5 SP1 There is bunch of logic written in control.lostfocus and control.leave events. These events are not being called when clicked on the toolstrip buttons. I...
You could listen to the click events on the buttons, and in the handler call their focus method. That would (hopefully) cause the previously focused control to respond correctly. Add the following handler to each button's click event: ``` private void ButtonClick(object sender, EventArgs e) { if(sender != null) { ...
287,703
<p>I'm using IIS 6 with EPiserver CMS which requires all requests to go through aspnet_isapi.dll.</p> <p>I want to gzip all my static files (js, css mainly). Trying to setup compression in IIS didn't work.</p> <p>Is there a setting in EPiServer that will allow me to achieve this? Can .net framework compress files au...
[ { "answer_id": 287771, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 3, "selected": true, "text": "<p>You'll need to configure the html extension in the IIS metabase <strong>as a dynamically compressed extension</strong>. Y...
2008/11/13
[ "https://Stackoverflow.com/questions/287703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29555/" ]
I'm using IIS 6 with EPiserver CMS which requires all requests to go through aspnet\_isapi.dll. I want to gzip all my static files (js, css mainly). Trying to setup compression in IIS didn't work. Is there a setting in EPiServer that will allow me to achieve this? Can .net framework compress files automatically?
You'll need to configure the html extension in the IIS metabase **as a dynamically compressed extension**. You are probably treating it as a static page. If the .js and .css extensions are mapped to aspnet\_isapi they are considered as dynamic pages. The setting in [metabase.xml](http://www.microsoft.com/technet/prod...
287,713
<p>I thought this code would work, but the regular expression doesn't ever match the \r\n. I have viewed the data I am reading in a hex editor and verified there really is a hex D and hex A pattern in the file.</p> <p>I have also tried the regular expressions /\xD\xA/m and /\x0D\x0A/m but they also didn't match.</p> ...
[ { "answer_id": 287735, "author": "Cameron Price", "author_id": 35526, "author_profile": "https://Stackoverflow.com/users/35526", "pm_score": 4, "selected": false, "text": "<pre><code>lines2 = lines.split.join(\"\\n\")\n</code></pre>\n" }, { "answer_id": 287739, "author": "mwi...
2008/11/13
[ "https://Stackoverflow.com/questions/287713", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7893/" ]
I thought this code would work, but the regular expression doesn't ever match the \r\n. I have viewed the data I am reading in a hex editor and verified there really is a hex D and hex A pattern in the file. I have also tried the regular expressions /\xD\xA/m and /\x0D\x0A/m but they also didn't match. This is my cod...
What do you get when you do `puts lines`? That will give you a clue. By default `File.open` opens the file in text mode, so your `\r\n` characters will be automatically converted to `\n`. Maybe that's the reason `lines` are always equal to `lines2`. To prevent Ruby from parsing the line ends use the `rb` mode: ``` C:...
287,717
<p>I am currently trying to create a menu system for a game and cannot arrive at any really sound way to do it. There are several menu screens, each of them non-trivial, so that I would like to keep these as separate classes. The main problem I am having is passing control between these menu screens.</p> <p>I tried bu...
[ { "answer_id": 287784, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>I think a MenuManager class would be the way to go. You'd have one Menu base class which all the menu screens derive from, ...
2008/11/13
[ "https://Stackoverflow.com/questions/287717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17279/" ]
I am currently trying to create a menu system for a game and cannot arrive at any really sound way to do it. There are several menu screens, each of them non-trivial, so that I would like to keep these as separate classes. The main problem I am having is passing control between these menu screens. I tried building eac...
One of the tricks I learned to decent design is always separate your data from your code. This will do WONDERS for your specific problem. By this I mean that the menu items (strings) and relationships between the menus should be stored somewhere either in an array or a separate file (and read into an array). You then...
287,750
<p>I have a webpage where I want the user to see a new image when they put thier mouse over a certain part of the image. I used an image map.</p> <pre><code>&lt;img src="pic.jpg" usemap="#picmap" /&gt; &lt;map id="picmap" name="picmap"&gt;&lt;area shape="rect" coords ="10,20,30,40" onMouseOver="mouse_on_write('mouse ...
[ { "answer_id": 287766, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 1, "selected": false, "text": "<p>What you want todo is preload the images behind the scenes.</p>\n\n<p>Then, when moused over, the browser will already ha...
2008/11/13
[ "https://Stackoverflow.com/questions/287750", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30181/" ]
I have a webpage where I want the user to see a new image when they put thier mouse over a certain part of the image. I used an image map. ``` <img src="pic.jpg" usemap="#picmap" /> <map id="picmap" name="picmap"><area shape="rect" coords ="10,20,30,40" onMouseOver="mouse_on_write('mouse is on spot')" onMouseOut="mous...
You don't need to create any page elements, it can all be preloaded using JavaScript: ``` tempImg = new Image() tempImg.src="pic2.jpg" ``` EDIT: If you have a lot of images, you can use the poor-man's multi-preloader: ``` preloads = "red.gif,green.gif,blue.gif".split(",") var tempImg = [] for(var x=0;x<preloads.l...
287,757
<p>I read the part of <a href="http://docs.python.org/library/configparser.html" rel="noreferrer">the docs</a> and saw that the <code>ConfigParser</code> returns a list of key/value pairs for the options within a section. I figured that keys did not need to be unique within a section, otherwise the parser would just re...
[ { "answer_id": 287942, "author": "Jeremy Cantrell", "author_id": 18866, "author_profile": "https://Stackoverflow.com/users/18866", "pm_score": 4, "selected": true, "text": "<p>ConfigParser isn't designed to handle such conditions. Furthermore, your config file doesn't make sense to me.</...
2008/11/13
[ "https://Stackoverflow.com/questions/287757", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3594/" ]
I read the part of [the docs](http://docs.python.org/library/configparser.html) and saw that the `ConfigParser` returns a list of key/value pairs for the options within a section. I figured that keys did not need to be unique within a section, otherwise the parser would just return a mapping. I designed my config file ...
ConfigParser isn't designed to handle such conditions. Furthermore, your config file doesn't make sense to me. ConfigParser gives you a dict-like structure for each section, so when you call parser.items(section), I'm expecting similar output to dict.items(), which is just a list of key/value tuples. I would never exp...
287,783
<p>I am using an ancient version of Oracle (8.something) and my ADO.NET application needs to do some fairly large transactions. Large enough to not fin in our small rollback segments. Now we have a large rollback segment as well but it is not used by default.</p> <p>Oracle has a command to select the rollback segment ...
[ { "answer_id": 289832, "author": "pablo", "author_id": 16112, "author_profile": "https://Stackoverflow.com/users/16112", "pm_score": 2, "selected": true, "text": "<p>If this is a 'one-off' requirement then one solution is to put the other rollback segments offline while you run your tran...
2008/11/13
[ "https://Stackoverflow.com/questions/287783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8954/" ]
I am using an ancient version of Oracle (8.something) and my ADO.NET application needs to do some fairly large transactions. Large enough to not fin in our small rollback segments. Now we have a large rollback segment as well but it is not used by default. Oracle has a command to select the rollback segment to be used...
If this is a 'one-off' requirement then one solution is to put the other rollback segments offline while you run your transactions then put them online when you've finished; ``` ALTER ROLLBACK SEGMENT <name> OFFLINE; ALTER ROLLBACK SEGMENT <name> ONLINE; ``` Otherwise make all the rollback segments the same size.
287,789
<p>I have a huge file that I must parse line by line. Speed is of the essence. </p> <p>Example of a line:</p> <blockquote> <pre><code>Token-1 Here-is-the-Next-Token Last-Token-on-Line ^ ^ Current Position Position after GetToken </code></pre> </bl...
[ { "answer_id": 287803, "author": "utku_karatas", "author_id": 14716, "author_profile": "https://Stackoverflow.com/users/14716", "pm_score": 0, "selected": false, "text": "<p>Rolling your own is the fastest way for sure. For more on this topic, you could see <a href=\"http://synedit.sourc...
2008/11/13
[ "https://Stackoverflow.com/questions/287789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30176/" ]
I have a huge file that I must parse line by line. Speed is of the essence. Example of a line: > > > ``` > Token-1 Here-is-the-Next-Token Last-Token-on-Line > ^ ^ > Current Position > Position after GetToken > > ``` > > GetToken is called, ...
* Use PChar incrementing for speed of processing * If some tokens are not needed, only copy token data on demand * Copy PChar to local variable when actually scanning through characters * Keep source data in a single buffer unless you must handle line by line, and even then, consider handling line processing as a separ...
287,794
<p>How should a relational database be designed to handle multi-valued attributes ?</p> <p><strong>edit</strong>: To elaborate: </p> <p>There are two ways I could think of for doing this -</p> <ol> <li>Trying something like putting comma separated values in the field, which appears a bit clumsy.</li> <li>Create anot...
[ { "answer_id": 287821, "author": "Glenn", "author_id": 25191, "author_profile": "https://Stackoverflow.com/users/25191", "pm_score": 1, "selected": false, "text": "<p>Is the relationship one-to-many or many-to-many? With the one-to-many relationship, I recommend a foreign key in the chil...
2008/11/13
[ "https://Stackoverflow.com/questions/287794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30252/" ]
How should a relational database be designed to handle multi-valued attributes ? **edit**: To elaborate: There are two ways I could think of for doing this - 1. Trying something like putting comma separated values in the field, which appears a bit clumsy. 2. Create another table for the field and let the multiple v...
In conventional relational database design, each row & column must store only one value. Don't store comma-separated lists or anything wacky like that. For example, say a sports team has seven members. You could do this: ``` CREATE TABLE team ( team_id INT PRIMARY KEY, team_name VARCHAR(50), team_memb...
287,832
<p>I am creating a form in HTML that will be printed, with fields that need to be written in by the recipient. Basically what I want is a single line that stretches from the end of the field label to the side of the page. Here's how I'm doing it right now:</p> <pre><code>&lt;table width="100%"&gt; &lt;tr&gt; ...
[ { "answer_id": 287838, "author": "billjamesdev", "author_id": 13824, "author_profile": "https://Stackoverflow.com/users/13824", "pm_score": 2, "selected": false, "text": "<p>How about using the span tag?</p>\n\n<pre><code>&lt;span style=\"border-bottom....\"&gt;Text&lt;/span&gt;\n</code>...
2008/11/13
[ "https://Stackoverflow.com/questions/287832", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23935/" ]
I am creating a form in HTML that will be printed, with fields that need to be written in by the recipient. Basically what I want is a single line that stretches from the end of the field label to the side of the page. Here's how I'm doing it right now: ``` <table width="100%"> <tr> <td width="1%"> ...
I think your solution is better than the responses thus far. The only thing I'd change about your solution is that I'd use a css class instead of inline. Your solution will have better alignment than using spans. Your code will look cleaner with table elements than with spans as well. Also, you might want to consider...
287,839
<p>[former title: Is there a way to force a relationship structure on a tag-based organizational methodology?]</p> <p>I have some entities, and they have a series of attributes. Some of the attributes affect what other attributes the entity can have, many of the attributes are organized into groups, and occasionally e...
[ { "answer_id": 287977, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 3, "selected": true, "text": "<p><strong>edit</strong>: Your description of variable attributes that apply only depending on the values in other attr...
2008/11/13
[ "https://Stackoverflow.com/questions/287839", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20770/" ]
[former title: Is there a way to force a relationship structure on a tag-based organizational methodology?] I have some entities, and they have a series of attributes. Some of the attributes affect what other attributes the entity can have, many of the attributes are organized into groups, and occasionally entities ar...
**edit**: Your description of variable attributes that apply only depending on the values in other attributes is a non-relational, non-normalized design. RDBMS may not be the best solution for storing this kind of data. Probably RDF would be a good solution for data that requires this level of flexibility. My earlier ...
287,845
<p>I have a fair number of Python scripts that contain reusable code that are used and referenced by other Python scripts. However, these scripts tend to be scattered across different directories and I find it to be somewhat tedious to have to include (most often multiple) calls to sys.path.append on my top-level scrip...
[ { "answer_id": 287884, "author": "bouvard", "author_id": 24608, "author_profile": "https://Stackoverflow.com/users/24608", "pm_score": 2, "selected": false, "text": "<p>If your reusable files are packaged (that is, they include an <code>__init__.py</code> file) and the path to that packa...
2008/11/13
[ "https://Stackoverflow.com/questions/287845", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4872/" ]
I have a fair number of Python scripts that contain reusable code that are used and referenced by other Python scripts. However, these scripts tend to be scattered across different directories and I find it to be somewhat tedious to have to include (most often multiple) calls to sys.path.append on my top-level scripts....
The simple answer is to put your reusable code in your site-packages directory, which is in your sys.path. You can also extend the search path by adding .pth files somewhere in your path. See <https://docs.python.org/2/install/#modifying-python-s-search-path> for more details Oh, and python 2.6/3.0 adds support for P...
287,849
<p>I'm trying to replace the programs that run from my startup directory with a batch script. The batch script will simply warn me that the programs are going to run and I can either continue running the script or stop it. </p> <p>Here's the script as I have written so far:</p> <pre><code>@echo off echo You are abo...
[ { "answer_id": 287866, "author": "Carl Seleborg", "author_id": 2095, "author_profile": "https://Stackoverflow.com/users/2095", "pm_score": 2, "selected": false, "text": "<p>There is the <code>start</code> command that will behave much like if you clicked the files in Explorer.</p>\n" }...
2008/11/13
[ "https://Stackoverflow.com/questions/287849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2916/" ]
I'm trying to replace the programs that run from my startup directory with a batch script. The batch script will simply warn me that the programs are going to run and I can either continue running the script or stop it. Here's the script as I have written so far: ``` @echo off echo You are about to run startup progr...
This works: ``` @echo off echo You are about to run startup programs! pause ::load outlook start /b "" "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /recycle ::load Visual Studio 2008 start /b "" "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" ```
287,871
<p>How do I output colored text to the terminal in Python?</p>
[ { "answer_id": 287896, "author": "UberJumper", "author_id": 34395, "author_profile": "https://Stackoverflow.com/users/34395", "pm_score": 5, "selected": false, "text": "<p>For Windows you cannot print to console with colors unless you're using the <a href=\"https://en.wikipedia.org/wiki/...
2008/11/13
[ "https://Stackoverflow.com/questions/287871", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35062/" ]
How do I output colored text to the terminal in Python?
This somewhat depends on what platform you are on. The most common way to do this is by printing ANSI escape sequences. For a simple example, here's some Python code from the [Blender build scripts](https://svn.blender.org/svnroot/bf-blender/trunk/blender/build_files/scons/tools/bcolors.py): ``` class bcolors: HEA...
287,875
<p>I'm trying to come up with a reusable JS or jQuery function that would allow me to test if one object is a DOM descendant of another. </p> <p>I've seen a model of testing for </p> <pre><code>$b.parents('nodename').length&gt;0 </code></pre> <p>Which is fantastic when you only need to check if an element is a child...
[ { "answer_id": 287889, "author": "picardo", "author_id": 32816, "author_profile": "https://Stackoverflow.com/users/32816", "pm_score": 2, "selected": false, "text": "<p>Try this:</p>\n\n<pre><code>$('#foo').filter(function(){\n\n return $(this).parent().is('#foo-parent');\n\n});\n</cod...
2008/11/13
[ "https://Stackoverflow.com/questions/287875", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37429/" ]
I'm trying to come up with a reusable JS or jQuery function that would allow me to test if one object is a DOM descendant of another. I've seen a model of testing for ``` $b.parents('nodename').length>0 ``` Which is fantastic when you only need to check if an element is a child of any node by that name. But what...
In [jQuery ancestors using jQuery objects](https://stackoverflow.com/questions/245241/jquery-ancestors-using-jquery-objects#245266) I suggested ``` if ($(obj1).parents().index($(obj2)) >= 0) { // obj1 is a descendant of obj2 } ```
287,899
<p>Can anyone think of a good solution for getting IOC into a console application?</p> <p>At the moment we are just using a static class with the following method:</p> <pre><code>public static T Resolve&lt;T&gt;() { return dependencyResolver.Resolve&lt;T&gt;(); } </code></pre> <p>I would like the experience to b...
[ { "answer_id": 287902, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 1, "selected": false, "text": "<p>I've used Spring.NET from a console app with no problems. You just need to point it at your config file, and it will ...
2008/11/13
[ "https://Stackoverflow.com/questions/287899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11755/" ]
Can anyone think of a good solution for getting IOC into a console application? At the moment we are just using a static class with the following method: ``` public static T Resolve<T>() { return dependencyResolver.Resolve<T>(); } ``` I would like the experience to be seamless but cannot think of a way of achie...
You will have to make a service locater call (`Resolve<T>()`) somewhere. The trick is to get it as out-of-the-way as possible. For console applications this bootstrapping happens in the `Main()` method. Do it there and minimize those Resolve calls elsewhere and you'll be great. For most dependencies, use constructor in...
287,903
<p>Would the following make the objects fulfil all characteristics that enums have in JavaScript? Something like:</p> <pre class="lang-js prettyprint-override"><code>my.namespace.ColorEnum = { RED : 0, GREEN : 1, BLUE : 2 } // later on if(currentColor == my.namespace.ColorEnum.RED) { // whatever } </code></p...
[ { "answer_id": 287917, "author": "Gareth", "author_id": 31582, "author_profile": "https://Stackoverflow.com/users/31582", "pm_score": 9, "selected": false, "text": "<p>This isn't much of an answer, but I'd say that works just fine, personally</p>\n\n<p>Having said that, since it doesn't ...
2008/11/13
[ "https://Stackoverflow.com/questions/287903", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5309/" ]
Would the following make the objects fulfil all characteristics that enums have in JavaScript? Something like: ```js my.namespace.ColorEnum = { RED : 0, GREEN : 1, BLUE : 2 } // later on if(currentColor == my.namespace.ColorEnum.RED) { // whatever } ``` Or is there some other way I can do this?
Since 1.8.5 it's possible to [seal and freeze the object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze), so define the above as: ``` const DaysEnum = Object.freeze({"monday":1, "tuesday":2, "wednesday":3, ...}) ``` or ``` const DaysEnum = {"monday":1, "tuesday":2, "...
287,907
<p>I want to transfer data between a smart phone app and a website. What are the conventional and not-so-conventional ways of doing it? </p> <p>Here's what I have thought of so far:</p> <ol> <li>Simple HTTP GET/POST with data being represented as JSON array string, variations of this being encrypted/compressed string...
[ { "answer_id": 287917, "author": "Gareth", "author_id": 31582, "author_profile": "https://Stackoverflow.com/users/31582", "pm_score": 9, "selected": false, "text": "<p>This isn't much of an answer, but I'd say that works just fine, personally</p>\n\n<p>Having said that, since it doesn't ...
2008/11/13
[ "https://Stackoverflow.com/questions/287907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16071/" ]
I want to transfer data between a smart phone app and a website. What are the conventional and not-so-conventional ways of doing it? Here's what I have thought of so far: 1. Simple HTTP GET/POST with data being represented as JSON array string, variations of this being encrypted/compressed string as parameter. 2. We...
Since 1.8.5 it's possible to [seal and freeze the object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze), so define the above as: ``` const DaysEnum = Object.freeze({"monday":1, "tuesday":2, "wednesday":3, ...}) ``` or ``` const DaysEnum = {"monday":1, "tuesday":2, "...
287,928
<p>DataGridView, for example, lets you do this:</p> <pre><code>DataGridView dgv = ...; DataGridViewCell cell = dgv[1,5]; </code></pre> <p>but for the life of me I can't find the documentation on the index/square-bracket operator. What do they call it? Where is it implemented? Can it throw? How can I do the same t...
[ { "answer_id": 287938, "author": "Patrick Desjardins", "author_id": 13913, "author_profile": "https://Stackoverflow.com/users/13913", "pm_score": 5, "selected": false, "text": "<pre class=\"lang-none prettyprint-override\"><code>Operators Overloadability\n\n+, -...
2008/11/13
[ "https://Stackoverflow.com/questions/287928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26286/" ]
DataGridView, for example, lets you do this: ``` DataGridView dgv = ...; DataGridViewCell cell = dgv[1,5]; ``` but for the life of me I can't find the documentation on the index/square-bracket operator. What do they call it? Where is it implemented? Can it throw? How can I do the same thing in my own classes? ETA: ...
you can find how to do it [here](http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx). In short it is: ``` public object this[int i] { get { return InnerList[i]; } set { InnerList[i] = value; } } ``` If you only need a getter the syntax in [answer below](https://stackoverflow.com/a/34098286/21733) can be ...
287,954
<p>To add a NOT NULL Column to a table with many records, a DEFAULT constraint needs to be applied. This constraint causes the entire ALTER TABLE command to take a long time to run if the table is very large. This is because:</p> <p>Assumptions:</p> <ol> <li>The DEFAULT constraint modifies existing records. This mean...
[ { "answer_id": 287971, "author": "Pyrolistical", "author_id": 21838, "author_profile": "https://Stackoverflow.com/users/21838", "pm_score": 0, "selected": false, "text": "<p>I think this depends on the SQL flavor you are using, but what if you took option 2, but at the very end alter tab...
2008/11/13
[ "https://Stackoverflow.com/questions/287954", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13484/" ]
To add a NOT NULL Column to a table with many records, a DEFAULT constraint needs to be applied. This constraint causes the entire ALTER TABLE command to take a long time to run if the table is very large. This is because: Assumptions: 1. The DEFAULT constraint modifies existing records. This means that the db needs ...
I ran into this problem for my work also. And my solution is along #2. Here are my steps (I am using SQL Server 2005): 1) Add the column to the table with a default value: ``` ALTER TABLE MyTable ADD MyColumn varchar(40) DEFAULT('') ``` 2) Add a `NOT NULL` constraint with the `NOCHECK` option. The `NOCHECK` does n...
287,960
<p>I know that jQuery and prototype have a $.each() function for iterating over each element in an array. Does YUI offer any help with this?</p>
[ { "answer_id": 288083, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 3, "selected": false, "text": "<p>What keeps you from simply <em>iterating</em> the array?</p>\n\n<pre><code>for(var i=0; i&lt;ary.length; i++)\n // ass...
2008/11/13
[ "https://Stackoverflow.com/questions/287960", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I know that jQuery and prototype have a $.each() function for iterating over each element in an array. Does YUI offer any help with this?
What keeps you from simply *iterating* the array? ``` for(var i=0; i<ary.length; i++) // assuming that ary[] contains objects with a DoSometing() method ary[i].doSomething(); ```
287,965
<p>I have two tables: Client(id,name,...)<br> Purchase(id,item,date,client_id,...)</p> <p>They have their respective Model, with their validations. What I need is to create a new client with a new purchase, all into the create method of Client controller. Something like this:</p> <pre><code>def create @client = C...
[ { "answer_id": 288026, "author": "mwilliams", "author_id": 23909, "author_profile": "https://Stackoverflow.com/users/23909", "pm_score": 3, "selected": true, "text": "<p>Take a look at the following page on <a href=\"http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord/Associations\" ...
2008/11/13
[ "https://Stackoverflow.com/questions/287965", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36599/" ]
I have two tables: Client(id,name,...) Purchase(id,item,date,client\_id,...) They have their respective Model, with their validations. What I need is to create a new client with a new purchase, all into the create method of Client controller. Something like this: ``` def create @client = Client.new(params[:cli...
Take a look at the following page on [working with associations](http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord/Associations). Rails provides you with a bunch of handy methods on your objects. Like the following: ``` Client.purchases.empty? Client.purchases.size, Client.purchases Client.purchases<<(purchase...
287,976
<p>I'd like to make an (MS)SQL query that returns something like this:</p> <pre><code>Col1 Col2 Col3 ---- --------------------- ------ AAA 18.92 18.92 BBB 20.00 40.00 AAA 30.84 30.84 BBB 06.00 12.00 AAA 30.84 30.84 AA...
[ { "answer_id": 287982, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 6, "selected": true, "text": "<p>You didn't mention what kind of database you're using. Here's something that will work in SQL Server:</p>\n\n<pre><...
2008/11/13
[ "https://Stackoverflow.com/questions/287976", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34632/" ]
I'd like to make an (MS)SQL query that returns something like this: ``` Col1 Col2 Col3 ---- --------------------- ------ AAA 18.92 18.92 BBB 20.00 40.00 AAA 30.84 30.84 BBB 06.00 12.00 AAA 30.84 30.84 AAA 46.79 ...
You didn't mention what kind of database you're using. Here's something that will work in SQL Server: ``` SELECT Col1, Col2, CASE WHEN Col1='AAA' THEN Col2 WHEN Col1='BBB' THEN Col2*2 ELSE NULL END AS Col3 FROM ... ```
287,986
<p>Ruby on Rails controllers will automatically convert parameters to an array if they have a specific format, like so:</p> <pre><code>http://foo.com?x[]=1&amp;x[]=5&amp;x[]=bar </code></pre> <p>This would get converted into the following array:</p> <pre><code>['1','5','bar'] </code></pre> <p>Is there any way I can...
[ { "answer_id": 288004, "author": "mmattax", "author_id": 1638, "author_profile": "https://Stackoverflow.com/users/1638", "pm_score": 1, "selected": false, "text": "<p>I usually do something like this...</p>\n\n<pre>\n<code>\nvar s:HTTPService = new HTTPService();\ns.url = \"http://foo.co...
2008/11/13
[ "https://Stackoverflow.com/questions/287986", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19964/" ]
Ruby on Rails controllers will automatically convert parameters to an array if they have a specific format, like so: ``` http://foo.com?x[]=1&x[]=5&x[]=bar ``` This would get converted into the following array: ``` ['1','5','bar'] ``` Is there any way I can do this with an ActionScript 3 HTTPService object, by us...
I was working on this same problem as well. Fortunatly, Flex supports this out of the box. Just use an Array for the field value: ``` var service:HTTPService = new HTTPService(); service.useProxy = true; service.destination = "myservicet"; service.resultFormat = HTTPService.RESULT_FORMAT_XML; var fields:Array = ["ca...
287,991
<p>How can I match (PCRE) everything inbetween two tags?</p> <p>I tried something like this:</p> <blockquote> <p>&lt;!--\s&#42;LoginStart\s&#42;--&gt;(.*)&lt;!--\s&#42;LoginEnd\s&#42;--&gt;</p> </blockquote> <p>But it didn't work out too well for me..</p> <p>I'm kind of new to regular expressions, so I was hoping...
[ { "answer_id": 288006, "author": "John Fiala", "author_id": 9143, "author_profile": "https://Stackoverflow.com/users/9143", "pm_score": 1, "selected": false, "text": "<p>PHP and regex? Here's some suggestions:</p>\n\n<pre><code>'/&lt;!--\\s*LoginStart\\s*--&gt;(.*)&lt;!--\\s*LoginEnd\\s...
2008/11/13
[ "https://Stackoverflow.com/questions/287991", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37439/" ]
How can I match (PCRE) everything inbetween two tags? I tried something like this: > > <!--\s\*LoginStart\s\*-->(.\*)<!--\s\*LoginEnd\s\*--> > > > But it didn't work out too well for me.. I'm kind of new to regular expressions, so I was hoping if someone would be kind enough to explain to me how I would accompl...
``` $string = '<!-- LoginStart --><div id="stuff">text</div><!-- LoginEnds -->'; $regex = '#<!--\s*LoginStart\s*-->(.*?)<!--\s*LoginEnds\s*-->#s'; preg_match($regex, $string, $matches); print_r($matches); // $matches[1] = <div id="stuff">text</div> ``` explanations: ``` (.*?) = non greedy match (match the first <!...
288,007
<pre><code>SELECT DISTINCT 'LRS-TECH 1' || rpad(code,7) || rpad('APPTYPE',30) || rpad(licensing_no,30) || rpad(' ',300) AS RECORD FROM APPS WHERE L_code = '1000' AND licensing_no IS NOT NULL </code></pre> <p>This seems to be the primary culprit in why I cannot export these records to a textfile in my deve...
[ { "answer_id": 288025, "author": "digitalsanctum", "author_id": 22436, "author_profile": "https://Stackoverflow.com/users/22436", "pm_score": 0, "selected": false, "text": "<p>If you don't already have indexes on L_code and licensing_no columns, I would try that.</p>\n" }, { "ans...
2008/11/13
[ "https://Stackoverflow.com/questions/288007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` SELECT DISTINCT 'LRS-TECH 1' || rpad(code,7) || rpad('APPTYPE',30) || rpad(licensing_no,30) || rpad(' ',300) AS RECORD FROM APPS WHERE L_code = '1000' AND licensing_no IS NOT NULL ``` This seems to be the primary culprit in why I cannot export these records to a textfile in my development environment...
You cannot diagnose this problem unless you know how the query is being optimised. Try this: ``` explain plan for SELECT DISTINCT 'LRS-TECH 1' || rpad(code,7) || rpad('APPTYPE',30) || rpad(licensing_no,30) || rpad(' ',300) AS RECORD FROM APPS WHERE L_code = '1000' AND licensing_no IS NOT NULL / select * from ta...
288,011
<p>Joel often talks about using MS Excel for lightweight project management, but I'm curious about actual implementations of this idea. I've seen some templates that seem to clone MS Project via macros, which would be overkill for a lightweight project. Anyone have any useful templates?</p>
[ { "answer_id": 288028, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 2, "selected": false, "text": "<p>You have some pretty advance template with <a href=\"http://pipetalk.stores.yahoo.net/frdopiexgasc.html\" rel=\"nofollow nor...
2008/11/13
[ "https://Stackoverflow.com/questions/288011", "https://Stackoverflow.com", "https://Stackoverflow.com/users/327/" ]
Joel often talks about using MS Excel for lightweight project management, but I'm curious about actual implementations of this idea. I've seen some templates that seem to clone MS Project via macros, which would be overkill for a lightweight project. Anyone have any useful templates?
try ``` feature task estimated hours actual hours current % ---------- ---------- --------------- ------------ --------- ``` if estimated hours times current % is greater than actual hours, you are behind schedule update the actual hours and current % on a daily basis see also [joel's old excel tem...
288,020
<p>I found one source which successfully overrode <code>Time.strftime</code> like this:</p> <pre><code>class Time alias :old_strftime :strftime def strftime #do something old_strftime end end </code></pre> <p>The trouble is, <code>strftime</code> is an instance method. I need to override <code>Time.now...
[ { "answer_id": 288077, "author": "Austin Ziegler", "author_id": 36378, "author_profile": "https://Stackoverflow.com/users/36378", "pm_score": 2, "selected": false, "text": "<p>Class methods are just methods. I highly recommend against this, but you have two equivalent choices:</p>\n\n<pr...
2008/11/13
[ "https://Stackoverflow.com/questions/288020", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30997/" ]
I found one source which successfully overrode `Time.strftime` like this: ``` class Time alias :old_strftime :strftime def strftime #do something old_strftime end end ``` The trouble is, `strftime` is an instance method. I need to override `Time.now` - a class method - in such away that any caller gets...
This is kinda hard to get your head around sometimes, but you need to open the "eigenclass" which is the singleton associated with a specific class object. the syntax for this is class << self do...end. ``` class Time alias :old_strftime :strftime def strftime puts "got here" old_strftime end end clas...
288,027
<p>In Object Oriented Paradigm, I would create an object/conceptual model before I start implementing it using OO language.</p> <p>Is there anything parallel to object model in functional programming. Is it called functional model? or we create the same conceptual model in both the paradigm before implementing it in o...
[ { "answer_id": 288079, "author": "Rohit", "author_id": 16071, "author_profile": "https://Stackoverflow.com/users/16071", "pm_score": 0, "selected": false, "text": "<p>A flowchart and/or process model/diagram can be used as a functional model for non OO programs. But it still doesn't give...
2008/11/13
[ "https://Stackoverflow.com/questions/288027", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30917/" ]
In Object Oriented Paradigm, I would create an object/conceptual model before I start implementing it using OO language. Is there anything parallel to object model in functional programming. Is it called functional model? or we create the same conceptual model in both the paradigm before implementing it in one of the ...
In fact there is. There is a form of specification for functional languages based on Abstract Data Types called algebraic specification. Their behavior is very similar to that of objects in some ways, however the constructs are logical and mathematical, and are immutable like functional constructs. A particular functi...
288,034
<p>I need some help regarding algorithm for randomness. So Problem is.</p> <p>There are 50 events going to happen in 8 hours duration. Events can happen at random times. Now it means in each second there is a chance of event happening is 50/(8*60*60)= .001736. How can I do this with random generation algorithm?</p> <...
[ { "answer_id": 288046, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "<p>Both <code>r</code> and <code>RAND_MAX</code> are integers, so the expression</p>\n\n<pre><code>double chance = r / RA...
2008/11/13
[ "https://Stackoverflow.com/questions/288034", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33411/" ]
I need some help regarding algorithm for randomness. So Problem is. There are 50 events going to happen in 8 hours duration. Events can happen at random times. Now it means in each second there is a chance of event happening is 50/(8\*60\*60)= .001736. How can I do this with random generation algorithm? I can get ran...
* Create a list of 50 numbers. * Fill them with a random number between 1 and 8 \* 60 \* 60. * Sort them And you have the 50 seconds. Note that you can have duplicates.
288,044
<p>I am using a <code>ListView</code> to display the main screen of my application.<br> The main screen is essentially a <code>menu</code> to get into the different sections of application. Currently, I have the <code>ListView</code> whose contents are added programmatically in the <code>onCreate</code> method. </p> ...
[ { "answer_id": 322555, "author": "Feet", "author_id": 18340, "author_profile": "https://Stackoverflow.com/users/18340", "pm_score": 1, "selected": false, "text": "<p>From the google docs for ArrayAdapter.</p>\n\n<blockquote>\n <p>To use something other than TextViews\n for the array di...
2008/11/13
[ "https://Stackoverflow.com/questions/288044", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37436/" ]
I am using a `ListView` to display the main screen of my application. The main screen is essentially a `menu` to get into the different sections of application. Currently, I have the `ListView` whose contents are added programmatically in the `onCreate` method. Here is the code snippet that does this: ``` String[...
What I typically do for a ListView is to implement my own Adapter by extending the handy BaseAdapter class. One of the abstract methods you'll implement will be getView() as the previous poster mentioned. From there you can inflate a layout containing an ImageView, get a reference to it using findViewById, and set the ...
288,045
<p>I am accessing a .NET COM object from C++. I want to know the version information about this COM object. When I open the TLB in OLEVIEW.exe I can see the version information associated with the coclass. How can I access this information from C++? This is the information I get:</p> <pre><code>[ uuid(XXXXXXXX-XXXX-...
[ { "answer_id": 322555, "author": "Feet", "author_id": 18340, "author_profile": "https://Stackoverflow.com/users/18340", "pm_score": 1, "selected": false, "text": "<p>From the google docs for ArrayAdapter.</p>\n\n<blockquote>\n <p>To use something other than TextViews\n for the array di...
2008/11/13
[ "https://Stackoverflow.com/questions/288045", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8661/" ]
I am accessing a .NET COM object from C++. I want to know the version information about this COM object. When I open the TLB in OLEVIEW.exe I can see the version information associated with the coclass. How can I access this information from C++? This is the information I get: ``` [ uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXX...
What I typically do for a ListView is to implement my own Adapter by extending the handy BaseAdapter class. One of the abstract methods you'll implement will be getView() as the previous poster mentioned. From there you can inflate a layout containing an ImageView, get a reference to it using findViewById, and set the ...
288,054
<p>Goal: Efficiently show/hide rows based on the data in the row.</p> <ol> <li>Create a helper column that determines whether or not a row should be hidden.</li> <li>Have the formula in the helper column return an error or a number.</li> <li>Hide the helper column and write code to execute the hiding/showing.</li> </...
[ { "answer_id": 288970, "author": "SpyJournal", "author_id": 10326, "author_profile": "https://Stackoverflow.com/users/10326", "pm_score": 1, "selected": false, "text": "<p>there is a different way and that is to use th auto filter feature - after all VBA has an A in it - use the features...
2008/11/13
[ "https://Stackoverflow.com/questions/288054", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25197/" ]
Goal: Efficiently show/hide rows based on the data in the row. 1. Create a helper column that determines whether or not a row should be hidden. 2. Have the formula in the helper column return an error or a number. 3. Hide the helper column and write code to execute the hiding/showing. Question: Which one of the follo...
there is a different way and that is to use th auto filter feature - after all VBA has an A in it - use the features of the application wherever possible so this bit of code is pretty short and sweet - assumes that the data is a contiguous block in columns a and b and assumes no other error handling in play. the resume...
288,062
<p>It seems as though the following calls do what you'd expect (close the stream and not allow any further input - anything waiting for input on the stream returns error), but is it guaranteed to be correct across all compilers/platforms?</p> <pre><code>close(fileno(stdin)); fclose(stdin); </code></pre>
[ { "answer_id": 288089, "author": "Sniggerfardimungus", "author_id": 30997, "author_profile": "https://Stackoverflow.com/users/30997", "pm_score": 4, "selected": false, "text": "<p>DO NOT DO a close on fileno(FILE*). FILE is a buffering object. Looking into its implementation and meddli...
2008/11/13
[ "https://Stackoverflow.com/questions/288062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5963/" ]
It seems as though the following calls do what you'd expect (close the stream and not allow any further input - anything waiting for input on the stream returns error), but is it guaranteed to be correct across all compilers/platforms? ``` close(fileno(stdin)); fclose(stdin); ```
Nothing is guaranteed correct across every possible operating system. However, calling fclose(stdin) will work on any POSIX compliant operating system as well as Windows operating systems, so you should hit pretty much anything in general use at the moment. As stated by the previous answer as well as my comment, there...
288,068
<p>I need to add localization to the exceptions thrown by my application as a lot are ApplicationExceptions and handled and logged to an error report. Ideally I want to create a new Exception, imheriting from ApplicationException that I can pass the resource key as well as arguments to, so that the exception messsage ...
[ { "answer_id": 288129, "author": "labilbe", "author_id": 1195872, "author_profile": "https://Stackoverflow.com/users/1195872", "pm_score": 3, "selected": true, "text": "<p>Here is a sample of what I do.\nEmillException inherits from ApplicationException.</p>\n\n<pre><code>\nnamespace eMi...
2008/11/13
[ "https://Stackoverflow.com/questions/288068", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6684/" ]
I need to add localization to the exceptions thrown by my application as a lot are ApplicationExceptions and handled and logged to an error report. Ideally I want to create a new Exception, imheriting from ApplicationException that I can pass the resource key as well as arguments to, so that the exception messsage can ...
Here is a sample of what I do. EmillException inherits from ApplicationException. ``` namespace eMill.Model.Exceptions { public sealed class AccountNotFoundException : EmillException { private readonly string _accountName; public AccountNotFoundException(string accountName) { ...
288,070
<p>I am using a WCF service and a net.tcp endpoint with serviceAuthentication's principal PermissionMode set to UseWindowsGroups.</p> <p>Currently in the implementation of the service i am using the PrincipalPermission attribute to set the role requirements for each method. </p> <pre><code> [PrincipalPermissio...
[ { "answer_id": 288758, "author": "Panos", "author_id": 8049, "author_profile": "https://Stackoverflow.com/users/8049", "pm_score": 3, "selected": true, "text": "<p>If I understood well you want to select the role at runtime. This can be done with a <a href=\"http://msdn.microsoft.com/en-...
2008/11/13
[ "https://Stackoverflow.com/questions/288070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37444/" ]
I am using a WCF service and a net.tcp endpoint with serviceAuthentication's principal PermissionMode set to UseWindowsGroups. Currently in the implementation of the service i am using the PrincipalPermission attribute to set the role requirements for each method. ``` [PrincipalPermission(SecurityAction.Dema...
If I understood well you want to select the role at runtime. This can be done with a [permission](http://msdn.microsoft.com/en-us/library/system.security.permissions.principalpermission.aspx) demand within the WCF operation. E.g. ``` public string method1() { PrincipalPermission p = new PrincipalPermission(null, "...
288,076
<p>I'm trying to upload an image to my site through a form, however it's much more efficient to (rather than bog down the database) just store the location of the image in the database.</p> <p>I'm having trouble with my form and really don't know where to go:</p> <pre><code>&lt;?=form_open('bro/submit_new');?&gt; //...
[ { "answer_id": 288101, "author": "victoriah", "author_id": 37014, "author_profile": "https://Stackoverflow.com/users/37014", "pm_score": 4, "selected": true, "text": "<p>CodeIgniter's file uploading class will do this for you. The <a href=\"http://codeigniter.com/user_guide/libraries/fil...
2008/11/13
[ "https://Stackoverflow.com/questions/288076", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24565/" ]
I'm trying to upload an image to my site through a form, however it's much more efficient to (rather than bog down the database) just store the location of the image in the database. I'm having trouble with my form and really don't know where to go: ``` <?=form_open('bro/submit_new');?> //other form data Image: <in...
CodeIgniter's file uploading class will do this for you. The [entry in their user guide](http://codeigniter.com/user_guide/libraries/file_uploading.html) explains as well as I could, so I'm going to point you there. Essentially you'd just need to modify the controller that they have there to include a bit where you p...
288,084
<p>Is there any other way to get a list of file names via <code>T-SQL</code> other than </p> <pre><code>INSERT INTO @backups(filename) EXEC master.sys.xp_cmdshell 'DIR /b c:\some folder with sql backups in it </code></pre> <p>I am attempting to get a list of SQL backup files from a folder to restore and I do NOT want...
[ { "answer_id": 288451, "author": "Sam", "author_id": 37379, "author_profile": "https://Stackoverflow.com/users/37379", "pm_score": 1, "selected": false, "text": "<p>If you have access to the <em>server that backup up the files</em>, you can use the system tables to find the backup file(s...
2008/11/13
[ "https://Stackoverflow.com/questions/288084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4096/" ]
Is there any other way to get a list of file names via `T-SQL` other than ``` INSERT INTO @backups(filename) EXEC master.sys.xp_cmdshell 'DIR /b c:\some folder with sql backups in it ``` I am attempting to get a list of SQL backup files from a folder to restore and I do NOT want to use the `xp_cmdshell` for obvious...
The alternative to xp\_cmdshell I came up is below: My situation is a little unique in that I am attempting a poor man's log shipping. I have a folder (not the default SQL backup location) where transaction logs are deposited from a remote server. I am writing a c# app that loops through that directory and creates a c...
288,111
<p>I have an HTTPHandler that is reading in a set of CSS files and combining them and then GZipping them. However, some of the CSS files contain a Byte Order Mark (due to a bug in TFS 2005 auto merge) and in FireFox the BOM is being read as part of the actual content so it's screwing up my class names etc. How can I ...
[ { "answer_id": 289114, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": 3, "selected": false, "text": "<p>Expanding on <a href=\"https://stackoverflow.com/questions/288111/remove-byte-order-mark-from-a-file-readallbytes-byte...
2008/11/13
[ "https://Stackoverflow.com/questions/288111", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4541/" ]
I have an HTTPHandler that is reading in a set of CSS files and combining them and then GZipping them. However, some of the CSS files contain a Byte Order Mark (due to a bug in TFS 2005 auto merge) and in FireFox the BOM is being read as part of the actual content so it's screwing up my class names etc. How can I strip...
Expanding on [Jon's comment](https://stackoverflow.com/questions/288111/remove-byte-order-mark-from-a-file-readallbytes-byte#comment21871755_288111) with a sample. ``` var name = GetFileName(); var bytes = System.IO.File.ReadAllBytes(name); System.IO.File.WriteAllBytes(name, bytes.Skip(3).ToArray()); ```
288,153
<p>I would like to know How to create a fps-game with SDL lib? </p> <p>Are there any books that explain with examples? </p>
[ { "answer_id": 288165, "author": "Dan Blair", "author_id": 1327, "author_profile": "https://Stackoverflow.com/users/1327", "pm_score": 0, "selected": false, "text": "<p>Pretty much anything that says in the TItle the \"Tricks of the Game Programming Gurus\" is going to show you how to ma...
2008/11/13
[ "https://Stackoverflow.com/questions/288153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24639/" ]
I would like to know How to create a fps-game with SDL lib? Are there any books that explain with examples?
this wins for most open ended question. You could literally write a book. But lets settle for pointing in the right direction... Step one, you will need good debugging skills for a project like this. Pick up Code Complete by Steve McConnell. Read the whole thing. The time invested will pay for itself more than anythin...
288,178
<p>I have been trying to learn more about lambda expressions lately, and thought of a interesting exercise...</p> <p>is there a way to simplify a c++ integration function like this:</p> <pre><code>// Integral Function double integrate(double a, double b, double (*f)(double)) { double sum = 0.0; // Evaluate i...
[ { "answer_id": 288311, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 4, "selected": true, "text": "<p>What about this:</p>\n\n<pre><code>public double Integrate(double a,double b, Func&lt;double, double&gt; f)\n...
2008/11/13
[ "https://Stackoverflow.com/questions/288178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have been trying to learn more about lambda expressions lately, and thought of a interesting exercise... is there a way to simplify a c++ integration function like this: ``` // Integral Function double integrate(double a, double b, double (*f)(double)) { double sum = 0.0; // Evaluate integral{a,b} f(x) dx ...
What about this: ``` public double Integrate(double a,double b, Func<double, double> f) { double sum = 0.0; for (int n = 0; n <= 100; ++n) { double x = a + n * (b - a) / 100.0; sum += f(x) * (b - a) / 101.0; } return sum; } ``` Test: ``` Func<double, double> fun = x => Math....
288,192
<p>I'm writing Application A and DLL B, both in C#.NET. How do I do the following: </p> <ol> <li>A calls function in B </li> <li>Want B to use delegate/callback to update status in UI of A </li> </ol> <p>This is <em>not</em> about BackgroundWorker...that part works fine in A. What I can't see is how to let B know ...
[ { "answer_id": 288212, "author": "Rob Prouse", "author_id": 30827, "author_profile": "https://Stackoverflow.com/users/30827", "pm_score": 3, "selected": false, "text": "<p>You have two options. The most common is to have an event in B and have your UI in A subscribe to that event. B then...
2008/11/13
[ "https://Stackoverflow.com/questions/288192", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm writing Application A and DLL B, both in C#.NET. How do I do the following: 1. A calls function in B 2. Want B to use delegate/callback to update status in UI of A This is *not* about BackgroundWorker...that part works fine in A. What I can't see is how to let B know what function to call in A.
To expand on Rob Prouse's answer, you need to declare a delegate and then pass a matching method into it. In B: ``` public delegate void CallbackDelegate(string status); public void DoWork(string param, CallbackDelegate callback) { callback("status"); } ``` In A: ``` public void MyCallback(string status) { ...
288,200
<p>We're having a bit of fun here at work. It all started with one of the guys setting up a Hackintosh and we were wondering whether it was faster than a Windows Box of (nearly) same specs that we have. So we decided to write a little test for it. Just a simple Prime number calculator. It's written in Java and tells us...
[ { "answer_id": 288252, "author": "BP.", "author_id": 36984, "author_profile": "https://Stackoverflow.com/users/36984", "pm_score": 1, "selected": false, "text": "<p>Keeping in mind that there are better ways to look for primes...</p>\n\n<p>I think that you can take this loop:</p>\n\n<blo...
2008/11/13
[ "https://Stackoverflow.com/questions/288200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18340/" ]
We're having a bit of fun here at work. It all started with one of the guys setting up a Hackintosh and we were wondering whether it was faster than a Windows Box of (nearly) same specs that we have. So we decided to write a little test for it. Just a simple Prime number calculator. It's written in Java and tells us th...
Well I see a couple of quick optimizations that can be done. First you don't have to try each number up to half of the current number. Instead you only have try up to the square root of the current number. And the other optimization was what BP said with a twist: Instead of ``` int count = 0; ... for (int i = 2; i <...
288,210
<p>I used to do this:</p> <pre><code>SELECT layerID FROM layers WHERE ownerID = ? AND collectionID = ? </code></pre> <p>Which would give me an array of layerID's, and then I'd loop and do this for each one:</p> <pre><code>SELECT DATA FROM drawings WHERE layerID = ? </code></pre> <p>And it all worked fine. So now I'...
[ { "answer_id": 288237, "author": "dkretz", "author_id": 31641, "author_profile": "https://Stackoverflow.com/users/31641", "pm_score": 4, "selected": true, "text": "<p>Try a join. ANY ends up looking a lot like an unoptimizable UNION to the query optimizer.</p>\n\n<pre><code>SELECT d.DATA...
2008/11/13
[ "https://Stackoverflow.com/questions/288210", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14569/" ]
I used to do this: ``` SELECT layerID FROM layers WHERE ownerID = ? AND collectionID = ? ``` Which would give me an array of layerID's, and then I'd loop and do this for each one: ``` SELECT DATA FROM drawings WHERE layerID = ? ``` And it all worked fine. So now I'm trying to do it in one step, so I try this: ``...
Try a join. ANY ends up looking a lot like an unoptimizable UNION to the query optimizer. ``` SELECT d.DATA, d.layerID FROM drawings AS d INNER JOIN layers AS l ON d.layerID = l.layerID WHERE l.ownerID = ? AND l.collectionID = ? ```
288,222
<p>In SQL Server (in my case, 2005) how can I add the identity property to an existing table column using T-SQL?</p> <p>Something like:</p> <pre><code>alter table tblFoo alter column bar identity(1,1) </code></pre>
[ { "answer_id": 288273, "author": "JohnFx", "author_id": 30018, "author_profile": "https://Stackoverflow.com/users/30018", "pm_score": 6, "selected": true, "text": "<p>I don't beleive you can do that. Your best bet is to create a new identity column and copy the data over using an identit...
2008/11/13
[ "https://Stackoverflow.com/questions/288222", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30529/" ]
In SQL Server (in my case, 2005) how can I add the identity property to an existing table column using T-SQL? Something like: ``` alter table tblFoo alter column bar identity(1,1) ```
I don't beleive you can do that. Your best bet is to create a new identity column and copy the data over using an identity insert command (if you indeed want to keep the old values). Here is a decent article describing the process in detail: <http://www.mssqltips.com/tip.asp?tip=1397>
288,256
<p>I need to insert 20,000 rows in a single table (SQL Server 2005) using iBatis. What's the fastest way to do it ? I'm already using batch mode, but it didn't help much:</p> <pre><code>try { sqlMap.startTransaction(); sqlMap.startBatch(); // ... execute statements in between sqlMap.commitTransaction(); } fina...
[ { "answer_id": 288281, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 1, "selected": false, "text": "<p>Bulk inserts are best done using the database's own bulk loader tools. For Oracle, it's SQL*Loader, for example. Often...
2008/11/13
[ "https://Stackoverflow.com/questions/288256", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7111/" ]
I need to insert 20,000 rows in a single table (SQL Server 2005) using iBatis. What's the fastest way to do it ? I'm already using batch mode, but it didn't help much: ``` try { sqlMap.startTransaction(); sqlMap.startBatch(); // ... execute statements in between sqlMap.commitTransaction(); } finally { sqlMap...
Although this is not specific to your db server, I have previously had success writing the rows out to a local file in csv format and then having the database importing the file. This was considerably faster than insert statements or even a batch insert.
288,277
<p>I have a JavaScript variable which holds an HTML page and due to the setup I need to extract everything between <code>&lt;div id="LiveArea"&gt;</code> and <code>&lt;/div&gt;</code> from that variable using JavaScript.</p> <p>Any help is greatly appreciated.</p>
[ { "answer_id": 288297, "author": "mmattax", "author_id": 1638, "author_profile": "https://Stackoverflow.com/users/1638", "pm_score": 1, "selected": false, "text": "<p>I'm not sure I follow you when you say, \"Javascript variable which holds an html page\", but If you need to extract the ...
2008/11/13
[ "https://Stackoverflow.com/questions/288277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a JavaScript variable which holds an HTML page and due to the setup I need to extract everything between `<div id="LiveArea">` and `</div>` from that variable using JavaScript. Any help is greatly appreciated.
``` var html = "<stuff><div id=\"LiveArea\">hello stackoverflow!</div></stuff>"; var matches = html.match(/<div\s+id="LiveArea">[\S\s]*?<\/div>/gi); var matches = matches[0].replace(/(<\/?[^>]+>)/gi, ''); // Strip HTML tags? alert(matches); ```
288,282
<p>Here's some code I have:</p> <pre><code>MyClass* MyClass::getInstance() { static MyClass instance; return &amp;instance; } </code></pre> <p>I want to look into this singleton's current values. But I'm currently paused three hours into execution, and the reason I'm paused is that I'm out of memory. So I can't...
[ { "answer_id": 288329, "author": "Nathan Kitchen", "author_id": 31000, "author_profile": "https://Stackoverflow.com/users/31000", "pm_score": 1, "selected": false, "text": "<p>In gdb, you can put a watchpoint on the mangled name of the variable.</p>\n\n<p>For example, with this function:...
2008/11/13
[ "https://Stackoverflow.com/questions/288282", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4790/" ]
Here's some code I have: ``` MyClass* MyClass::getInstance() { static MyClass instance; return &instance; } ``` I want to look into this singleton's current values. But I'm currently paused three hours into execution, and the reason I'm paused is that I'm out of memory. So I can't put a breakpoint in this meth...
Well, the function-scoped static `instance` variable doesn't show up in a `.map` file generated by `cl.exe /Fm`, and it doesn't show up when I use `x programname!*MyClass*` in WinDbg, so the mangled name doesn't seem to contain `MyClass` at all. **Option 1: Disassemble `MyClass::getInstance`** This approach seems eas...
288,289
<p>In Websphere when you do an LDAP query using LdapContext are the transmission of credentials encrypted?</p> <pre><code>LdapContext ctx = new InitialLdapContext (env, null); </code></pre> <p>Lets say I make an LdapContext for a web app to do some custom LDAP calls.</p> <p>How do I know if my call is secure / encry...
[ { "answer_id": 492381, "author": "Michael Sharek", "author_id": 1958, "author_profile": "https://Stackoverflow.com/users/1958", "pm_score": 3, "selected": true, "text": "<p>In order to secure/encrypt your LDAP calls you need to issue the \"Start TLS\" operation.</p>\n\n<p>Otherwise I thi...
2008/11/13
[ "https://Stackoverflow.com/questions/288289", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30807/" ]
In Websphere when you do an LDAP query using LdapContext are the transmission of credentials encrypted? ``` LdapContext ctx = new InitialLdapContext (env, null); ``` Lets say I make an LdapContext for a web app to do some custom LDAP calls. How do I know if my call is secure / encrypted?
In order to secure/encrypt your LDAP calls you need to issue the "Start TLS" operation. Otherwise I think transport is plain text. For more: <http://java.sun.com/products/jndi/tutorial/ldap/ext/starttls.html> Obviously the Java API is based on LDAP itself. So you could learn more about how the protocol itself handl...
288,294
<p>This may be too generic a question as is but... I am stumped by trying to move through the directories from within a shell script. I'm not a *nix power user, but I am comfortable working through the command line for most tasks. I'd like to call a script that can move 'me' to a directory instead of just the script pr...
[ { "answer_id": 288302, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 2, "selected": false, "text": "<p>You can't. The script has its own copy of the environment, and so it can't change the login shell's environment.</p...
2008/11/13
[ "https://Stackoverflow.com/questions/288294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
This may be too generic a question as is but... I am stumped by trying to move through the directories from within a shell script. I'm not a \*nix power user, but I am comfortable working through the command line for most tasks. I'd like to call a script that can move 'me' to a directory instead of just the script proc...
You can create a function that is called goto (or whatever) and make sure it is defined in your .bashrc (or you can "source" it from your current shell): ``` function goto { # the "$USER" part will expand to the current username # the "$1" will expand to the first argument to the function ("goto xyz" => $1 is...
288,298
<p>How much code documentation in your .NET source is too much?</p> <p>Some background: I inherited a large codebase that I've talked about in some of the other questions I've posted here on SO. One of the "features" of this codebase is a God Class, a single static class with >3000 lines of code encompassing several d...
[ { "answer_id": 288312, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<p>Jeff has a really good article about commenting (or should I say, not commenting) here...</p>\n\n<p><a href=\"http://www.co...
2008/11/13
[ "https://Stackoverflow.com/questions/288298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7565/" ]
How much code documentation in your .NET source is too much? Some background: I inherited a large codebase that I've talked about in some of the other questions I've posted here on SO. One of the "features" of this codebase is a God Class, a single static class with >3000 lines of code encompassing several dozen stati...
I think a good part of the problem here is the verbose and crufty XML documentation syntax MS has foisted on us (JavaDoc wasn't much better either). The question of how to format it is, to a large degree, independent of how much is appropriate. Using the XML format for comments is optional. You can use DOxygen or othe...
288,304
<p>I have some .NET remoting code where a factory method, implemented in some server side class, returns interfaces to concrete objects, also executing on the very same server. .NET remoting automagically creates proxies and allows me to pass the interfaces across to the client, which can then call them directly.</p> ...
[ { "answer_id": 288321, "author": "jezell", "author_id": 27453, "author_profile": "https://Stackoverflow.com/users/27453", "pm_score": 0, "selected": false, "text": "<p>The ChannelFactory class does exactly this, generates a proxy dynamically at runtime given an interface.</p>\n" }, {...
2008/11/13
[ "https://Stackoverflow.com/questions/288304", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4597/" ]
I have some .NET remoting code where a factory method, implemented in some server side class, returns interfaces to concrete objects, also executing on the very same server. .NET remoting automagically creates proxies and allows me to pass the interfaces across to the client, which can then call them directly. Example...
[Use Sessions instead of Client-Activated Objects (MSDN)](http://msdn.microsoft.com/en-us/library/aa730857%28VS.80%29.aspx#netremotewcf_topic6)
288,319
<p>I realized the solution to this problem while I was creating the documentation to ASK this question...so I am posting the answer if for no other reason than to keep me from wasting time on this in the future</p>
[ { "answer_id": 288328, "author": "Jay Corbett", "author_id": 2755, "author_profile": "https://Stackoverflow.com/users/2755", "pm_score": 2, "selected": false, "text": "<p>If the content to be TOGGLEd is displayed (visible) when the page is rendered the functions would be in the following...
2008/11/13
[ "https://Stackoverflow.com/questions/288319", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2755/" ]
I realized the solution to this problem while I was creating the documentation to ASK this question...so I am posting the answer if for no other reason than to keep me from wasting time on this in the future
`toggle()` is pretty buggy at times, i've had it do odd things to checkmarks (unchecking them) and other assorted issues. i'd suggest just handling it using a click event, much less minor annoyances. and this way, you don't have to worry about what state `#lowerDiv` is in in the first place: ``` $('#upperDiv').click(f...
288,357
<p>So if I have:</p> <pre><code>public class ChildClass : BaseClass { public new virtual string TempProperty { get; set; } } public class BaseClass { public virtual string TempProperty { get; set; } } </code></pre> <p>How can I use reflection to see that ChildClass is hiding the Base implementation of TempPr...
[ { "answer_id": 288372, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": -1, "selected": false, "text": "<p>Correction, if you are using VB the property you are looking for is \"IsHideBySig\". This will be false in the case ...
2008/11/13
[ "https://Stackoverflow.com/questions/288357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1946/" ]
So if I have: ``` public class ChildClass : BaseClass { public new virtual string TempProperty { get; set; } } public class BaseClass { public virtual string TempProperty { get; set; } } ``` How can I use reflection to see that ChildClass is hiding the Base implementation of TempProperty? I'd like the answ...
We'll have to deal in terms of the methods of the property here rather than the property itself, because it is the get/set methods of the property that actually get overridden rather than the property itself. I'll use the get method as you should never have a property without one, though a complete solution should chec...
288,368
<p>Do any of the existing JavaScript frameworks have a non-regex <code>replace()</code> function, or has this already been posted on the web somewhere as a one-off function?</p> <p>For example I want to replace <code>"@!#$123=%"</code> and I don't want to worry about which characters to escape. Most languages seem to ...
[ { "answer_id": 288384, "author": "Owen", "author_id": 4853, "author_profile": "https://Stackoverflow.com/users/4853", "pm_score": 6, "selected": true, "text": "<p>i may be misunderstanding your question, but javascript does have a <a href=\"https://developer.mozilla.org/en-US/docs/Web/Ja...
2008/11/13
[ "https://Stackoverflow.com/questions/288368", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36590/" ]
Do any of the existing JavaScript frameworks have a non-regex `replace()` function, or has this already been posted on the web somewhere as a one-off function? For example I want to replace `"@!#$123=%"` and I don't want to worry about which characters to escape. Most languages seem to have both methods of doing repla...
i may be misunderstanding your question, but javascript does have a [`replace()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) ``` var string = '@!#$123=%'; var newstring = string.replace('@!#$123=%', 'hi'); ``` **edit**: (see comments) the 5th edition does seem to...
288,374
<p>A method I work with that is called tens of thousands of times started throwing exceptions recently. In most debugging circumstances I would set a breakpoint at the top of this method and run through until I reach the call I'm interested in with a parameter value that triggers the exception. In this case that woul...
[ { "answer_id": 288408, "author": "Dana the Sane", "author_id": 2567, "author_profile": "https://Stackoverflow.com/users/2567", "pm_score": 0, "selected": false, "text": "<p>I wonder if you are getting a stack overflow. Does VS track all the values for str or anything to do with each stat...
2008/11/13
[ "https://Stackoverflow.com/questions/288374", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28350/" ]
A method I work with that is called tens of thousands of times started throwing exceptions recently. In most debugging circumstances I would set a breakpoint at the top of this method and run through until I reach the call I'm interested in with a parameter value that triggers the exception. In this case that would be ...
Anytime that I have tried to use conditional breakpoints in Visual Studio I've had the same problem. The debugger runs so slowly that it becomes useless. Instead I end up temporarily adding an if statement to the code and adding my breakpoint inside of that. This isn't as convenient, but the code executes at a normal p...
288,402
<p>if you</p> <pre><code>Describe dbms_transform PROCEDURE COMPUTE_TRANSFORMATION Argument Name Type In/Out ------------------------------ ----------------------- ------ MESSAGE STANDARD IN TRANSFORMATION_SCHEMA VARCHAR2 ...
[ { "answer_id": 288471, "author": "cagcowboy", "author_id": 19629, "author_profile": "https://Stackoverflow.com/users/19629", "pm_score": 0, "selected": false, "text": "<p>Abstract Data Type?</p>\n\n<p><a href=\"http://www.psoug.org/reference/dbms_transform.html\" rel=\"nofollow noreferre...
2008/11/13
[ "https://Stackoverflow.com/questions/288402", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
if you ``` Describe dbms_transform PROCEDURE COMPUTE_TRANSFORMATION Argument Name Type In/Out ------------------------------ ----------------------- ------ MESSAGE STANDARD IN TRANSFORMATION_SCHEMA VARCHAR2 IN ...
The type is "<ADT\_1>" which is defined in package *standard*. According to the [reference](http://www.psoug.org/reference/standard.html) these > > data types are generics, used > specially within package STANDARD and > some other Oracle packages. They are > protected against other use; sorry. > True generic ty...
288,409
<p>If I create a UserControl and add some objects to it, how can I grab the HTML it would render?</p> <p>ex.</p> <pre><code>UserControl myControl = new UserControl(); myControl.Controls.Add(new TextBox()); // ...something happens return strHTMLofControl; </code></pre> <p>I'd like to just convert a newly built User...
[ { "answer_id": 288414, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 1, "selected": false, "text": "<p>Call its <code>.RenderControl()</code> method.</p>\n" }, { "answer_id": 288419, "author": "azamsharp", ...
2008/11/13
[ "https://Stackoverflow.com/questions/288409", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25538/" ]
If I create a UserControl and add some objects to it, how can I grab the HTML it would render? ex. ``` UserControl myControl = new UserControl(); myControl.Controls.Add(new TextBox()); // ...something happens return strHTMLofControl; ``` I'd like to just convert a newly built UserControl to a string of HTML.
You can render the control using `Control.RenderControl(HtmlTextWriter)`. Feed `StringWriter` to the `HtmlTextWriter`. Feed `StringBuilder` to the `StringWriter`. Your generated string will be inside the `StringBuilder` object. Here's a code example for this solution: ``` string html = String.Empty; using (TextWri...
288,412
<p>I did a few tests with TouchJSON last night and it worked pretty well in general for simple cases. I'm using the following code to read some JSON content from a file, and deserialize it:</p> <pre><code>NSString *jsonString = [[NSString alloc] initWithContentsOfFile:@"data.json"]; NSData *jsonData = [jsonString data...
[ { "answer_id": 288855, "author": "rpj", "author_id": 23498, "author_profile": "https://Stackoverflow.com/users/23498", "pm_score": 4, "selected": true, "text": "<p>This isn't an answer, but a pointer to a different framework:</p>\n\n<p><a href=\"http://code.google.com/p/json-framework/\"...
2008/11/13
[ "https://Stackoverflow.com/questions/288412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35478/" ]
I did a few tests with TouchJSON last night and it worked pretty well in general for simple cases. I'm using the following code to read some JSON content from a file, and deserialize it: ``` NSString *jsonString = [[NSString alloc] initWithContentsOfFile:@"data.json"]; NSData *jsonData = [jsonString dataUsingEncoding:...
This isn't an answer, but a pointer to a different framework: <http://code.google.com/p/json-framework/> I've been using it quite a bit lately, serializing and de-serializing complex data structures from third-party services such as Google Local and between my own Objective-C and Perl code with absolutely no problems...
288,413
<p>I am using this code to verify a behavior of a method I am testing:</p> <pre><code> _repository.Expect(f =&gt; f.FindAll(t =&gt; t.STATUS_CD == "A")) .Returns(new List&lt;JSOFile&gt;()) .AtMostOnce() .Verifiable(); </code></pre> <p>_repository is defined as:</p> <pre><code>private Mock&lt;IReposito...
[ { "answer_id": 288509, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>In Rhino Mocks you would do something like this...</p>\n\n<p>Instead of using an Expect, use a Stub and Ignore the argument...
2008/11/13
[ "https://Stackoverflow.com/questions/288413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10589/" ]
I am using this code to verify a behavior of a method I am testing: ``` _repository.Expect(f => f.FindAll(t => t.STATUS_CD == "A")) .Returns(new List<JSOFile>()) .AtMostOnce() .Verifiable(); ``` \_repository is defined as: ``` private Mock<IRepository<JSOFile>> _repository; ``` When my test is run...
This is a bit of a cheaty way. I do a .ToString() on the expressions and compare them. This means you have to write the lambda the same way in the class under test. If you wanted, you could do some parsing at this point ``` [Test] public void MoqTests() { var mockedRepo = new Mock<IRepository<Meeti...
288,430
<p>How Can I put information in a outputstream from tapestry5 ?</p> <p>I need a page when a user enters it open a dialog for save or open the file with the outputstream information.</p> <p>I write the next code:</p> <p>public class Index {</p> <pre><code>@Inject private RequestGlobals requestGlobals; @OnEvent("act...
[ { "answer_id": 296682, "author": "Chochos", "author_id": 10165, "author_profile": "https://Stackoverflow.com/users/10165", "pm_score": 3, "selected": true, "text": "<p>Your method should have a return type of StreamResponse. You return an implementation of the interface StreamResponse, w...
2008/11/13
[ "https://Stackoverflow.com/questions/288430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34768/" ]
How Can I put information in a outputstream from tapestry5 ? I need a page when a user enters it open a dialog for save or open the file with the outputstream information. I write the next code: public class Index { ``` @Inject private RequestGlobals requestGlobals; @OnEvent("activate") public void onActivate() { ...
Your method should have a return type of StreamResponse. You return an implementation of the interface StreamResponse, which simply returns the data you want with the content type you want. Look it up here: <http://tapestry.apache.org/tapestry5/apidocs/> more info here: <http://tapestry.formos.com/nightly/tapestry5...
288,441
<p>I long thought that in C, all variables had to be declared at the beginning of the function. I know that in C99, the rules are the same as in C++, but what are the variable declaration placement rules for C89/ANSI C?</p> <p>The following code compiles successfully with <code>gcc -std=c89</code> and <code>gcc -ansi<...
[ { "answer_id": 288455, "author": "mipadi", "author_id": 28804, "author_profile": "https://Stackoverflow.com/users/28804", "pm_score": 8, "selected": true, "text": "<p>It compiles successfully because GCC allows the declaration of <code>s</code> as a GNU extension, even though it's not pa...
2008/11/13
[ "https://Stackoverflow.com/questions/288441", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30323/" ]
I long thought that in C, all variables had to be declared at the beginning of the function. I know that in C99, the rules are the same as in C++, but what are the variable declaration placement rules for C89/ANSI C? The following code compiles successfully with `gcc -std=c89` and `gcc -ansi`: ``` #include <stdio.h> ...
It compiles successfully because GCC allows the declaration of `s` as a GNU extension, even though it's not part of the C89 or ANSI standard. If you want to adhere strictly to those standards, you must pass the `-pedantic` flag. The declaration of `c` at the start of a `{ }` block is part of the C89 standard; the bloc...
288,445
<p>I have a swf file that's embedded in a html page, and I have a close button in the swf page, I want the swf to disappear when I click on the button, what is the best way to do that? Thanks.</p>
[ { "answer_id": 288468, "author": "Steve Paulo", "author_id": 9414, "author_profile": "https://Stackoverflow.com/users/9414", "pm_score": 1, "selected": false, "text": "<p>Write a JavaScript function that will hide the swf or its containing element, and call that function via the \"close ...
2008/11/13
[ "https://Stackoverflow.com/questions/288445", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34797/" ]
I have a swf file that's embedded in a html page, and I have a close button in the swf page, I want the swf to disappear when I click on the button, what is the best way to do that? Thanks.
If your ursing swfobject 2.1 to embed the swf you can use this built-in javascript swfobject.removeSWF() function: ``` function removeFlashFromHTML() { swfobject.removeSWF("id_of_your_html_object"); } ``` now you call the javascript function from flash using ExternalInterface: ``` function buttonClicked(evt:Mous...
288,465
<p>I'm building an XML DOM document in C++. My problem is this: I execute an XPATH query from an Element in my Document, which I know will return another Element. The elementPtr->selectSingleNode call returns an IXMLDOMNode. How can I gain access to the attributes of this node?</p> <p>Part of me wants to downcast the...
[ { "answer_id": 288518, "author": "DavidK", "author_id": 31394, "author_profile": "https://Stackoverflow.com/users/31394", "pm_score": 1, "selected": false, "text": "<p>How did you try to do the downcast from IXMLDOMNode to IXMLDOMElement? You can't just use a C++ cast for that, as it's a...
2008/11/13
[ "https://Stackoverflow.com/questions/288465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37481/" ]
I'm building an XML DOM document in C++. My problem is this: I execute an XPATH query from an Element in my Document, which I know will return another Element. The elementPtr->selectSingleNode call returns an IXMLDOMNode. How can I gain access to the attributes of this node? Part of me wants to downcast the Node to an...
I don't see anything wrong with what you have written. The smart com pointers will help you convert if they can, you don't have to write the query interface yourself. ``` MSXML2::IXMLDOMNodePtr pParentNode = pParameterElement->selectSingleNode("parent"); MSXML2::IXMLDOMElementPtr pParentElement( pParentNode ); ``` ...
288,467
<p>I am trying to link the as3corelib library to use their JSON functionality following <a href="http://www.mikechambers.com/blog/2006/03/28/tutorial-using-json-with-flex-2-and-actionscript-3/" rel="nofollow noreferrer">this tutorial</a>. But am having trouble compiling it. My command looks like:</p> <pre> mxmlc --str...
[ { "answer_id": 288576, "author": "jdoklovic", "author_id": 34336, "author_profile": "https://Stackoverflow.com/users/34336", "pm_score": 0, "selected": false, "text": "<p>Are you using the flex Gubmo sdk?\nLooks like the method it's complaining about is in an interface that's part of Gum...
2008/11/13
[ "https://Stackoverflow.com/questions/288467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5304/" ]
I am trying to link the as3corelib library to use their JSON functionality following [this tutorial](http://www.mikechambers.com/blog/2006/03/28/tutorial-using-json-with-flex-2-and-actionscript-3/). But am having trouble compiling it. My command looks like: ``` mxmlc --strict=true -library-path+=as3corelib.swc --file...
I found an older version of the library bundled with some tutorial which worked. Submitted a bug report to as3corelib, of course I am not entirely sure how valid the bug is.
288,508
<p>Does Xcode support anything akin to Visual Studio style <code>#region</code> directives for arbitrary code folding?</p>
[ { "answer_id": 288530, "author": "Jason Coco", "author_id": 34218, "author_profile": "https://Stackoverflow.com/users/34218", "pm_score": 7, "selected": true, "text": "<p>No, you can only fold code on various defined scoping levels in Xcode.</p>\n\n<p>You can use little tricks to make na...
2008/11/13
[ "https://Stackoverflow.com/questions/288508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13932/" ]
Does Xcode support anything akin to Visual Studio style `#region` directives for arbitrary code folding?
No, you can only fold code on various defined scoping levels in Xcode. You can use little tricks to make navigating via the function menu easier, though. ``` #pragma mark ``` Allows you to create a grouping where the label following mark will show up in the function menu. If the label is a hyphen, a separator is in...
288,511
<p>The idea is to move all of the right elements into the left and the left into the right with an empty space in the middle. The elements can either jump over one or two pieces into an empty space. </p> <pre><code>LLL[ ]RRR </code></pre> <p>I'm trying to think of a heuristic for this task. Is the heuristic meant to ...
[ { "answer_id": 288522, "author": "EBGreen", "author_id": 1358, "author_profile": "https://Stackoverflow.com/users/1358", "pm_score": 1, "selected": false, "text": "<p>Are you looking for a heuristic or an algorithm? A heuristic may or may not solve a given problem. It is really just inte...
2008/11/13
[ "https://Stackoverflow.com/questions/288511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
The idea is to move all of the right elements into the left and the left into the right with an empty space in the middle. The elements can either jump over one or two pieces into an empty space. ``` LLL[ ]RRR ``` I'm trying to think of a heuristic for this task. Is the heuristic meant to aid in finding a possible ...
Sounds like you are a bit confused about what a heuristic is. A rough definition is "a simplifying assumption" or "a decent guess" For example, let's say you have to put together a basketball team, and you have fact sheets on people who want to play that list their contact info, birth date, and height. You could hold...
288,512
<p>Anyone knows a good way to resize any window to for example 640x480?</p> <p>Reason is, of course, screencasting.</p> <p>Under windows I've used ZoneSize from donationcoder. (Btw: For Firefox it's easy, just use the web developer toolbar.)</p>
[ { "answer_id": 288537, "author": "Robert Gamble", "author_id": 25222, "author_profile": "https://Stackoverflow.com/users/25222", "pm_score": 7, "selected": true, "text": "<p>Use the <a href=\"http://www.sweb.cz/tripie/utils/wmctrl/\" rel=\"noreferrer\">wmctrl</a> command:</p>\n\n<p>To li...
2008/11/13
[ "https://Stackoverflow.com/questions/288512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9987/" ]
Anyone knows a good way to resize any window to for example 640x480? Reason is, of course, screencasting. Under windows I've used ZoneSize from donationcoder. (Btw: For Firefox it's easy, just use the web developer toolbar.)
Use the [wmctrl](http://www.sweb.cz/tripie/utils/wmctrl/) command: To list the windows: ``` $ wmctrl -l 0x00c00003 -1 rgamble-desktop Bottom Expanded Edge Panel 0x00c00031 -1 rgamble-desktop Top Expanded Edge Panel 0x00e00022 -1 rgamble-desktop Desktop 0x0260007c 0 rgamble-desktop Google - Mozilla Firefox ``` To r...
288,513
<p>Here is what I am trying to do: Given a date, a day of the week, and an integer <code>n</code>, determine whether the date is the <code>n</code>th day of the month.</p> <p>For example:</p> <ul> <li><p>input of <code>1/1/2009,Monday,2</code> would be false because <code>1/1/2009</code> is not the second Monday</p><...
[ { "answer_id": 288529, "author": "Robert Wagner", "author_id": 10784, "author_profile": "https://Stackoverflow.com/users/10784", "pm_score": 5, "selected": true, "text": "<p>You could change the check of the week so the function would read:</p>\n\n<pre><code>private bool NthDayOfMonth(Da...
2008/11/13
[ "https://Stackoverflow.com/questions/288513", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19038/" ]
Here is what I am trying to do: Given a date, a day of the week, and an integer `n`, determine whether the date is the `n`th day of the month. For example: * input of `1/1/2009,Monday,2` would be false because `1/1/2009` is not the second Monday * input of `11/13/2008,Thursday,2` would return true because it is the ...
You could change the check of the week so the function would read: ``` private bool NthDayOfMonth(DateTime date, DayOfWeek dow, int n){ int d = date.Day; return date.DayOfWeek == dow && (d-1)/7 == (n-1); } ``` Other than that, it looks pretty good and efficient.
288,540
<p>C#: How do you tell which item index is selected in ListView?</p>
[ { "answer_id": 288548, "author": "Tim Merrifield", "author_id": 36706, "author_profile": "https://Stackoverflow.com/users/36706", "pm_score": 1, "selected": false, "text": "<p>Use the SelectedIndex property of the class.</p>\n" }, { "answer_id": 288551, "author": "Cristian Li...
2008/11/13
[ "https://Stackoverflow.com/questions/288540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
C#: How do you tell which item index is selected in ListView?
``` ListView mylistv = new ListView(); var index = mylistv.SelectedIndices(); ``` That should do it.
288,559
<p>Even though error_reporting is set to 0, database errors are still being printed to screen. Is there a setting somewhere I can change to disable database error reporting? This is for CodeIgniter v1.6.x</p> <p><strong>EDIT</strong>: Re: Fixing errors - Um, yes. I want to fix the errors. I get error notices from my e...
[ { "answer_id": 288641, "author": "Tom Haigh", "author_id": 22224, "author_profile": "https://Stackoverflow.com/users/22224", "pm_score": 3, "selected": false, "text": "<ul>\n<li><p>You don't want to change\nerror_reporting to 0, because that will\nalso suppress errors from being\nlogged....
2008/11/13
[ "https://Stackoverflow.com/questions/288559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Even though error\_reporting is set to 0, database errors are still being printed to screen. Is there a setting somewhere I can change to disable database error reporting? This is for CodeIgniter v1.6.x **EDIT**: Re: Fixing errors - Um, yes. I want to fix the errors. I get error notices from my error log, not from wha...
Found the answer: In `config/database.php:` ``` // ['db_debug'] TRUE/FALSE - Whether database errors should be displayed. ``` so: ``` $db['default']['db_debug'] = FALSE; ``` ... should disable.
288,560
<p>I have the following structure:</p> <pre><code> &lt;StructLayout(LayoutKind.Sequential)&gt; _ Public Structure _WTS_CLIENT_ADDRESS Public AddressFamily As Integer &lt;MarshalAs(UnmanagedType.ByValArray, SizeConst:=20)&gt; _ Public Address() As Byte End Structure </code></pre> <p>...
[ { "answer_id": 311934, "author": "Jérôme Laban", "author_id": 26346, "author_profile": "https://Stackoverflow.com/users/26346", "pm_score": 3, "selected": true, "text": "<p>You're almost there with your code. I agree with you, the MSDN is not quite explicit on what's inside that byte arr...
2008/11/13
[ "https://Stackoverflow.com/questions/288560", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13338/" ]
I have the following structure: ``` <StructLayout(LayoutKind.Sequential)> _ Public Structure _WTS_CLIENT_ADDRESS Public AddressFamily As Integer <MarshalAs(UnmanagedType.ByValArray, SizeConst:=20)> _ Public Address() As Byte End Structure ``` Which is populated by the following ca...
You're almost there with your code. I agree with you, the MSDN is not quite explicit on what's inside that byte array, but here's what you can do : ``` IPAddress address = new IPAddress(_ClientIPAddress.Address.Skip(2).Take(4).ToArray()); ``` The first two bytes do not seem to be used, but in the case of AF\_INET (w...
288,564
<p>I have a web application project (wap) that is successfully being deployed to a development server by our tfsbuild server.</p> <p>I'd like the build server to run our collection of webtests after deployment.</p> <p>What is a best practice (or ANY practice) for doing this?</p>
[ { "answer_id": 311934, "author": "Jérôme Laban", "author_id": 26346, "author_profile": "https://Stackoverflow.com/users/26346", "pm_score": 3, "selected": true, "text": "<p>You're almost there with your code. I agree with you, the MSDN is not quite explicit on what's inside that byte arr...
2008/11/13
[ "https://Stackoverflow.com/questions/288564", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2424/" ]
I have a web application project (wap) that is successfully being deployed to a development server by our tfsbuild server. I'd like the build server to run our collection of webtests after deployment. What is a best practice (or ANY practice) for doing this?
You're almost there with your code. I agree with you, the MSDN is not quite explicit on what's inside that byte array, but here's what you can do : ``` IPAddress address = new IPAddress(_ClientIPAddress.Address.Skip(2).Take(4).ToArray()); ``` The first two bytes do not seem to be used, but in the case of AF\_INET (w...
288,573
<p>When using regular expressions in Ruby, what is the difference between $1 and \1?</p>
[ { "answer_id": 288595, "author": "Avdi", "author_id": 20487, "author_profile": "https://Stackoverflow.com/users/20487", "pm_score": 7, "selected": true, "text": "<p>\\1 is a backreference which will only work in the same <code>sub</code> or <code>gsub</code> method call, e.g.:</p>\n\n<pr...
2008/11/13
[ "https://Stackoverflow.com/questions/288573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
When using regular expressions in Ruby, what is the difference between $1 and \1?
\1 is a backreference which will only work in the same `sub` or `gsub` method call, e.g.: ``` "foobar".sub(/foo(.*)/, '\1\1') # => "barbar" ``` $1 is a global variable which can be used in later code: ``` if "foobar" =~ /foo(.*)/ then puts "The matching word was #{$1}" end ``` Output: ``` "The matching word w...
288,575
<p>I inherited a project that uses SQL Server 200x, wherein a column that stores a value that is always considered as a percentage in the problem domain is stored as its greater than 1 decimal equivalent. For example, <em>70%</em> (0.7, literally) is stored as <em>70</em>, <em>100%</em> as <em>100</em>, etc. Aside from...
[ { "answer_id": 288578, "author": "Andrew Bullock", "author_id": 28543, "author_profile": "https://Stackoverflow.com/users/28543", "pm_score": 3, "selected": false, "text": "<p>If its a byte field then it takes up less room in the db than floating point numbers, but unless you have millio...
2008/11/13
[ "https://Stackoverflow.com/questions/288575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4296/" ]
I inherited a project that uses SQL Server 200x, wherein a column that stores a value that is always considered as a percentage in the problem domain is stored as its greater than 1 decimal equivalent. For example, *70%* (0.7, literally) is stored as *70*, *100%* as *100*, etc. Aside from the need to remember to \* 0.0...
There are actually four good reasons I can think of that you might want to store—and calculate with—whole-number percentage values rather than floating-point equivalents: 1. Depending on the data types chosen, the integer value may take up less space. 2. Depending on the data type, the floating-point value may lose pr...
288,582
<p>Here's the scenario - a client uploads a Sybase dump file to (gzipped) to our local FTP server. We have an automated process which picks these up and then moves them to different server within the network where the database server resides. Unfortunately, this transfer is over a WAN, which for large files takes a lon...
[ { "answer_id": 554300, "author": "Vincent", "author_id": 66697, "author_profile": "https://Stackoverflow.com/users/66697", "pm_score": 0, "selected": false, "text": "<p>There is no way to really verify the integrity of the dump file without loading it in some way by a backup server. The ...
2008/11/13
[ "https://Stackoverflow.com/questions/288582", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1030/" ]
Here's the scenario - a client uploads a Sybase dump file to (gzipped) to our local FTP server. We have an automated process which picks these up and then moves them to different server within the network where the database server resides. Unfortunately, this transfer is over a WAN, which for large files takes a long t...
There are a few things you can do from the command line. The first, on the sending side, is to generate md5sum's of the files. ``` $ md5sum *.dmp 2bddf3cd8b04010183dd3295ce7594ff pubs_1.dmp 7510e0250c8d68bae3e0e794c211e60b pubs_2.dmp 091fe54fa5fd81d8c109cc7835d37f4a pubs_3.dmp ``` On the client side, they can run...
288,603
<p>I am getting </p> <pre><code>Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in *filename* on line 81 </code></pre> <p>While running a query to build a chart. The query gets data from the mysql db and uses it to build the chart.</p> <p>Usually, I get this error and go to the...
[ { "answer_id": 288610, "author": "mercutio", "author_id": 1951, "author_profile": "https://Stackoverflow.com/users/1951", "pm_score": 3, "selected": true, "text": "<p>Do this:</p>\n\n<pre><code>$rosh=mysql_query(\"select distinct term from search_terms\")\n or die(\"Error with query: \"...
2008/11/13
[ "https://Stackoverflow.com/questions/288603", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1149/" ]
I am getting ``` Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in *filename* on line 81 ``` While running a query to build a chart. The query gets data from the mysql db and uses it to build the chart. Usually, I get this error and go to the code and find where I've screwed ...
Do this: ``` $rosh=mysql_query("select distinct term from search_terms") or die("Error with query: " . mysql_error()); ``` and this: ``` $bash=mysql_query($bashq) or die("Error with query: " . mysql_error(); ``` That will tell you when it fails. You are correct though, you're getting that message because mys...
288,612
<p>I have a form that excepts a file upload in ASP.NET. I need to increase the max upload size to above the 4 MB default.</p> <p>I have found in certain places referencing the below code at <a href="http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.maxrequestlength.aspx" rel="noreferr...
[ { "answer_id": 288644, "author": "Stefan", "author_id": 19307, "author_profile": "https://Stackoverflow.com/users/19307", "pm_score": 3, "selected": false, "text": "<p>If its windows 2003 / IIS 6.0 then check out AspMaxRequestEntityAllowed = \"204800\" in the file <strong>metabase.xml</s...
2008/11/13
[ "https://Stackoverflow.com/questions/288612", "https://Stackoverflow.com", "https://Stackoverflow.com/users/576/" ]
I have a form that excepts a file upload in ASP.NET. I need to increase the max upload size to above the 4 MB default. I have found in certain places referencing the below code at [msdn](http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.maxrequestlength.aspx). ``` [ConfigurationProp...
This setting goes in your web.config file. It affects the entire application, though... I don't think you can set it per page. ```xml <configuration> <system.web> <httpRuntime maxRequestLength="xxx" /> </system.web> </configuration> ``` "xxx" is in KB. The default is 4096 (= 4 MB).
288,614
<p>How would I go about creating a real world form creation class that I can use to display a new form with fields of different types, as how many fields I want, I can use drop downs and I can do all of this by using OOP?</p>
[ { "answer_id": 288706, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 4, "selected": true, "text": "<p>You definitely can. Consider a Form class which stores information about the form itself: the <code>method</code>, <code>act...
2008/11/13
[ "https://Stackoverflow.com/questions/288614", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37418/" ]
How would I go about creating a real world form creation class that I can use to display a new form with fields of different types, as how many fields I want, I can use drop downs and I can do all of this by using OOP?
You definitely can. Consider a Form class which stores information about the form itself: the `method`, `action`, `enctype` attributes. Also throw in stuff like an optional heading and/or description text at the top. Of course you will also need an array of input elements. These could probably be put into their own cla...
288,619
<p>Say I have a sql query </p> <pre><code>SELECT fname, lname, dob, ssn, address1, address2, zip, phone,state from users </code></pre> <p>Now say the records are now either in dictionary base or a strongly typed collection.</p> <p>I have a grid view control and i want to bind it to my collection but I only want to d...
[ { "answer_id": 288627, "author": "Cristian Libardo", "author_id": 16526, "author_profile": "https://Stackoverflow.com/users/16526", "pm_score": 2, "selected": false, "text": "<p>Perhaps LINQ and an anonymous class could do the trick for you.</p>\n\n<pre><code>from user in UserCollection\...
2008/11/13
[ "https://Stackoverflow.com/questions/288619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Say I have a sql query ``` SELECT fname, lname, dob, ssn, address1, address2, zip, phone,state from users ``` Now say the records are now either in dictionary base or a strongly typed collection. I have a grid view control and i want to bind it to my collection but I only want to display fname, lname, dob and ssn ...
Perhaps LINQ and an anonymous class could do the trick for you. ``` from user in UserCollection select new { FirstName=user.fname, LastName=user.lname, Dob=user.dob, SSN=user.ssn } ```
288,637
<p>I need to construct some rather simple SQL, I suppose, but as it's a rare event that I work with DBs these days I can't figure out the details.</p> <p>I have a table 'posts' with the following columns:</p> <blockquote> <p>id, caption, text</p> </blockquote> <p>and a table 'comments' with the following columns:<...
[ { "answer_id": 288655, "author": "hark", "author_id": 34826, "author_profile": "https://Stackoverflow.com/users/34826", "pm_score": -1, "selected": false, "text": "<p>You're basically looking at performing a subquery --</p>\n\n<p><code>SELECT p.caption FROM posts p WHERE (SELECT COUNT(*)...
2008/11/13
[ "https://Stackoverflow.com/questions/288637", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4055/" ]
I need to construct some rather simple SQL, I suppose, but as it's a rare event that I work with DBs these days I can't figure out the details. I have a table 'posts' with the following columns: > > id, caption, text > > > and a table 'comments' with the following columns: > > id, name, text, post\_id > > > ...
``` select p.caption, count(c.id) from posts p join comments c on p.id = c.post_id group by p.caption having count (c.id) > 0 ```
288,687
<p>I've written a cheap &amp; cheerful sound board in for my Mac, and I play the various sounds with NSSound like this:</p> <pre><code>-(void)play:(NSSound *)soundEffect:(BOOL)stopIfPlaying { BOOL wasPlaying = FALSE; if([nowPlaying isPlaying]) { [nowPlaying stop]; wasPlaying = TRUE; } ...
[ { "answer_id": 289386, "author": "Chris Blackwell", "author_id": 1329401, "author_profile": "https://Stackoverflow.com/users/1329401", "pm_score": 0, "selected": false, "text": "<p>Something like this perhaps? You probably want a more linear dropoff, but the basic idea is make a loop and...
2008/11/13
[ "https://Stackoverflow.com/questions/288687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11470/" ]
I've written a cheap & cheerful sound board in for my Mac, and I play the various sounds with NSSound like this: ``` -(void)play:(NSSound *)soundEffect:(BOOL)stopIfPlaying { BOOL wasPlaying = FALSE; if([nowPlaying isPlaying]) { [nowPlaying stop]; wasPlaying = TRUE; } if(soundEffec...
This is the final version of the method: ``` -(void)play:(NSSound *)soundEffect:(BOOL)stopIfPlaying { BOOL wasPlaying = FALSE; if([nowPlaying isPlaying]) { struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 25000000; // If the sound effect is the same, fade it out. if(so...
288,699
<p>Can someone show me how to get the <code>top</code> &amp; <code>left</code> position of a <code>div</code> or <code>span</code> element when one is not specified?</p> <p>ie:</p> <pre><code>&lt;span id='11a' style='top:55px;' onmouseover=&quot;GetPos(this);&quot;&gt;stuff&lt;/span&gt; &lt;span id='12a' onmouseover=&q...
[ { "answer_id": 288708, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 8, "selected": true, "text": "<p>This function will tell you the x,y position of the element relative to the page. Basically you have to loop up through all ...
2008/11/13
[ "https://Stackoverflow.com/questions/288699", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26685/" ]
Can someone show me how to get the `top` & `left` position of a `div` or `span` element when one is not specified? ie: ``` <span id='11a' style='top:55px;' onmouseover="GetPos(this);">stuff</span> <span id='12a' onmouseover="GetPos(this);">stuff</span> ``` In the above, if I do: ``` document.getElementById('11a')....
This function will tell you the x,y position of the element relative to the page. Basically you have to loop up through all the element's parents and add their offsets together. ``` function getPos(el) { // yay readability for (var lx=0, ly=0; el != null; lx += el.offsetLeft, ly += el.offsetT...
288,715
<p>How can I check whether a variable is defined in Ruby? Is there an <code>isset</code>-type method available?</p>
[ { "answer_id": 288724, "author": "digitalsanctum", "author_id": 22436, "author_profile": "https://Stackoverflow.com/users/22436", "pm_score": 4, "selected": false, "text": "<p><code>defined?(your_var)</code> will work. Depending on what you're doing you can also do something like <code>y...
2008/11/13
[ "https://Stackoverflow.com/questions/288715", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
How can I check whether a variable is defined in Ruby? Is there an `isset`-type method available?
Use the `defined?` keyword ([documentation](http://ruby-doc.org/docs/keywords/1.9/Object.html#method-i-defined-3F)). It will return a String with the kind of the item, or `nil` if it doesn’t exist. ``` >> a = 1 => 1 >> defined? a => "local-variable" >> defined? b => nil >> defined? nil => "nil" >> defined? String ...
288,732
<p>I'm working on a program that searches entire drives for a given file. At the moment, I calculate an MD5 hash for the known file and then scan all files recursively, looking for a match.</p> <p>The only problem is that MD5 is painfully slow on large files. Is there a faster alternative that I can use while retainin...
[ { "answer_id": 288749, "author": "jalf", "author_id": 33213, "author_profile": "https://Stackoverflow.com/users/33213", "pm_score": 3, "selected": false, "text": "<p>just read the file linearly? It seems pretty pointless to read the entire file, compute a md5 hash, and then compare the h...
2008/11/13
[ "https://Stackoverflow.com/questions/288732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14333/" ]
I'm working on a program that searches entire drives for a given file. At the moment, I calculate an MD5 hash for the known file and then scan all files recursively, looking for a match. The only problem is that MD5 is painfully slow on large files. Is there a faster alternative that I can use while retaining a very s...
I hope you're checking for an MD5 match only if the file size already matches. Another optimization is to do a quick checksum of the first 1K (or some other arbitrary, but reasonably small number) and make sure those match before working the whole file. Of course, all this assumes that you're just looking for a match...
288,739
<p>I need to generate random numbers within a specified interval, [max;min].</p> <p>Also, the random numbers should be uniformly distributed over the interval, not located to a particular point.</p> <p>Currenly I am generating as:</p> <pre><code>for(int i=0; i&lt;6; i++) { DWORD random = rand()%(max-min+1) + min...
[ { "answer_id": 288753, "author": "Jason Coco", "author_id": 34218, "author_profile": "https://Stackoverflow.com/users/34218", "pm_score": 2, "selected": false, "text": "<p>If you want numbers to be uniformly distributed over the range, you should break your range up into a number of equa...
2008/11/13
[ "https://Stackoverflow.com/questions/288739", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33411/" ]
I need to generate random numbers within a specified interval, [max;min]. Also, the random numbers should be uniformly distributed over the interval, not located to a particular point. Currenly I am generating as: ``` for(int i=0; i<6; i++) { DWORD random = rand()%(max-min+1) + min; } ``` From my tests, random...
Why `rand` is a bad idea ------------------------ Most of the answers you got here make use of the `rand` function and the modulus operator. That method [may not generate numbers uniformly](http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful) (it depends on the range and the value of `RAND_MAX`), ...
288,752
<p>I have this strange issue with my web app. You see, I'm using jQuery with the Forms API and doing $('#MyForm').ajaxSubmit(api parms and callback function goes here).</p> <p>Randomly when I do this, however, and only on Firefox, the page load icon starts spinning, the page load progress bar runs in the status bar, a...
[ { "answer_id": 288753, "author": "Jason Coco", "author_id": 34218, "author_profile": "https://Stackoverflow.com/users/34218", "pm_score": 2, "selected": false, "text": "<p>If you want numbers to be uniformly distributed over the range, you should break your range up into a number of equa...
2008/11/13
[ "https://Stackoverflow.com/questions/288752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have this strange issue with my web app. You see, I'm using jQuery with the Forms API and doing $('#MyForm').ajaxSubmit(api parms and callback function goes here). Randomly when I do this, however, and only on Firefox, the page load icon starts spinning, the page load progress bar runs in the status bar, and the sto...
Why `rand` is a bad idea ------------------------ Most of the answers you got here make use of the `rand` function and the modulus operator. That method [may not generate numbers uniformly](http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful) (it depends on the range and the value of `RAND_MAX`), ...