Id
int64
4
8.51M
PostTypeId
int64
1
7
AcceptedAnswerId
int64
7
75.5M
βŒ€
ParentId
int64
4
41.8M
βŒ€
Score
int64
-208
27.7k
ViewCount
int64
11
12.4M
βŒ€
Body
stringlengths
0
45k
Title
stringlengths
2
150
βŒ€
ContentLicense
stringclasses
3 values
FavoriteCount
int64
0
225
βŒ€
CreationDate
stringlengths
23
23
LastActivityDate
stringlengths
23
23
LastEditDate
stringlengths
23
23
βŒ€
LastEditorUserId
int64
-1
21.3M
βŒ€
OwnerUserId
int64
-1
21.1M
βŒ€
Tags
sequence
7
2
null
4
522
null
An explicit cast to `double` like this isn't necessary: ``` double trans = (double) trackBar1.Value / 5000.0; ``` Identifying the constant as `5000.0` (or as `5000d`) is sufficient: ``` double trans = trackBar1.Value / 5000.0; double trans = trackBar1.Value / 5000d; ```
null
CC BY-SA 4.0
null
2008-07-31T22:17:57.883
2019-10-21T14:03:54.607
2019-10-21T14:03:54.607
5,496,973
9
null
9
1
1,404
null
2,199
784,860
Given a `DateTime` representing a person's birthday, how do I calculate their age in years?
How do I calculate someone's age based on a DateTime type birthday?
CC BY-SA 4.0
0
2008-07-31T23:40:59.743
2023-02-02T18:38:32.613
2022-07-27T22:34:36.320
3,524,942
1
[ "c#", ".net", "datetime" ]
11
1
1,248
null
1,644
197,314
Given a specific `DateTime` value, how do I display relative time, like: - `2 hours ago`- `3 days ago`- `a month ago`
Calculate relative time in C#
CC BY-SA 4.0
0
2008-07-31T23:55:37.967
2022-09-05T11:26:30.187
2022-07-10T00:19:55.237
16,790,137
1
[ "c#", "datetime", "time", "datediff", "relative-time-span" ]
14
1
null
null
491
173,083
What is the difference between [Math.Floor()](http://msdn.microsoft.com/en-us/library/9a6a2sxy.aspx) and [Math.Truncate()](http://msdn.microsoft.com/en-us/library/system.math.truncate.aspx) in .NET?
Difference between Math.Floor() and Math.Truncate()
CC BY-SA 3.0
0
2008-08-01T00:59:11.177
2022-04-22T08:59:43.817
2017-02-25T17:42:17.810
6,495,084
11
[ ".net", "math" ]
6
1
31
null
319
23,465
I have an absolutely positioned `div` containing several children, one of which is a relatively positioned `div`. When I use a `percentage-based width` on the child `div`, it collapses to `0 width` on IE7, but not on Firefox or Safari. If I use `pixel width`, it works. If the parent is relatively positioned, the percentage width on the child works. 1. Is there something I'm missing here? 2. Is there an easy fix for this besides the pixel-based width on the child? 3. Is there an area of the CSS specification that covers this?
Why did the width collapse in the percentage width child element in an absolutely positioned parent on Internet Explorer 7?
CC BY-SA 4.0
0
2008-07-31T22:08:08.620
2021-01-29T18:46:45.963
2021-01-29T18:46:45.963
9,134,576
9
[ "html", "css", "internet-explorer-7" ]
12
2
null
11
347
null
Here's how I do it ``` var ts = new TimeSpan(DateTime.UtcNow.Ticks - dt.Ticks); double delta = Math.Abs(ts.TotalSeconds); if (delta < 60) { return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago"; } if (delta < 60 * 2) { return "a minute ago"; } if (delta < 45 * 60) { return ts.Minutes + " minutes ago"; } if (delta < 90 * 60) { return "an hour ago"; } if (delta < 24 * 60 * 60) { return ts.Hours + " hours ago"; } if (delta < 48 * 60 * 60) { return "yesterday"; } if (delta < 30 * 24 * 60 * 60) { return ts.Days + " days ago"; } if (delta < 12 * 30 * 24 * 60 * 60) { int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30)); return months <= 1 ? "one month ago" : months + " months ago"; } int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365)); return years <= 1 ? "one year ago" : years + " years ago"; ``` Suggestions? Comments? Ways to improve this algorithm?
null
CC BY-SA 4.0
null
2008-07-31T23:56:41.303
2020-06-13T10:30:44.397
2020-06-13T10:30:44.397
238,419
1
null
13
1
null
null
701
277,780
Is there a standard way for a web server to be able to determine a user's timezone within a web page? Perhaps from an HTTP header or part of the `user-agent` string?
Determine a user's timezone
CC BY-SA 4.0
0
2008-08-01T00:42:38.903
2022-03-29T07:31:31.320
2020-12-03T03:37:56.313
584,192
9
[ "html", "browser", "timezone", "user-agent", "timezone-offset" ]
4
1
7
null
794
70,633
I want to assign the decimal variable "trans" to the double variable "this.Opacity". ``` decimal trans = trackBar1.Value / 5000; this.Opacity = trans; ``` When I build the app it gives the following error: > Cannot implicitly convert type decimal to double
How to convert Decimal to Double in C#?
CC BY-SA 4.0
0
2008-07-31T21:42:52.667
2022-09-08T05:07:26.033
2022-09-08T05:07:26.033
16,124,033
8
[ "c#", "floating-point", "type-conversion", "double", "decimal" ]
17
1
26
null
198
85,547
How do I store binary data in [MySQL](http://en.wikipedia.org/wiki/MySQL)?
Binary Data in MySQL
CC BY-SA 3.0
0
2008-08-01T05:09:55.993
2020-12-03T03:37:51.763
2020-12-03T03:37:51.763
584,192
2
[ "mysql", "database", "binary-data", "data-storage" ]
24
1
49
null
193
101,180
If I have a trigger before the update on a table, how can I throw an error that prevents the update on that table?
Throw an error preventing a table update in a MySQL trigger
CC BY-SA 4.0
0
2008-08-01T12:12:19.350
2021-01-29T12:57:17.153
2021-01-29T12:57:17.153
14,152,908
22
[ "mysql", "database", "triggers" ]
22
2
null
9
56
null
The best way that I know of because of leap years and everything is: ``` DateTime birthDate = new DateTime(2000,3,1); int age = (int)Math.Floor((DateTime.Now - birthDate).TotalDays / 365.25D); ```
null
CC BY-SA 4.0
null
2008-08-01T12:07:19.500
2020-02-29T01:31:43.697
2020-02-29T01:31:43.697
63,550
17
null
26
2
null
17
143
null
The answer by phpguy is correct but I think there is a lot of confusion in the additional details there. The basic answer is in a `BLOB` data type / attribute domain. is short for Binary Large Object and that column data type is specific for handling binary data. See [the relevant manual page for MySQL](http://dev.mysql.com/doc/refman/5.7/en/blob.html).
null
CC BY-SA 3.0
null
2008-08-01T12:16:22.167
2016-06-02T05:55:17.060
2016-06-02T05:55:17.060
126,039
48
null
29
2
null
13
205
null
There are no HTTP headers that will report the clients timezone so far although it has been suggested to include it in the HTTP specification. If it was me, I would probably try to fetch the timezone using clientside JavaScript and then submit it to the server using Ajax or something.
null
CC BY-SA 2.5
null
2008-08-01T12:19:17.417
2008-08-01T12:19:17.417
null
null
19
null
31
2
null
6
160
null
The parent `div` needs to have a defined `width`, either in pixels or as a percentage. In InternetΒ ExplorerΒ 7, the parent `div` needs a defined `width` for child percentage `div`s to work correctly.
null
CC BY-SA 3.0
null
2008-08-01T12:22:51.593
2016-03-19T06:10:52.170
2016-03-19T06:10:52.170
63,550
null
null
30
2
null
25
45
null
I've had no trouble using the BSD sockets API in C++, in GNU/Linux. Here's the sample program I used: ``` #include <sys/socket.h> int main() { return AF_INET; } ``` So my take on this is that z/OS is probably the complicating factor here, however, because I've never used z/OS before, much less programmed in it, I can't say this definitively. :-P
null
CC BY-SA 2.5
null
2008-08-01T12:22:40.797
2008-08-01T12:22:40.797
null
null
13
null
16
1
12,446
null
157
87,526
How do you expose a LINQ query as an ASMX web service? Usually, from the business tier, I can return a typed `DataSet` or a `DataTable` which can be serialized for transport over ASMX. How can I do the same for a LINQ query? Is there a way to populate a typed `DataSet` or a `DataTable` via a LINQ query? ``` public static MyDataTable CallMySproc() { string conn = "..."; MyDatabaseDataContext db = new MyDatabaseDataContext(conn); MyDataTable dt = new MyDataTable(); // execute a sproc via LINQ var query = from dr in db.MySproc().AsEnumerable select dr; // copy LINQ query resultset into a DataTable -this does not work ! dt = query.CopyToDataTable(); return dt; } ``` How could I put the result set of a LINQ query into a `DataSet` or a `DataTable`? Alternatively, can the LINQ query be serializable so that I can expose it as an ASMX web service?
Filling a DataSet or a DataTable from a LINQ query result set
CC BY-SA 4.0
0
2008-08-01T04:59:33.643
2021-01-07T14:09:26.367
2021-01-07T14:09:26.367
-1
2
[ "c#", "linq", "web-services", ".net-3.5" ]
27
2
null
11
34
null
@jeff IMHO yours seems a little long. However it does seem a little more robust with support for "yesterday" and "years". But in my experience when this is used, the person is most likely to view the content in the first 30 days. It is only the really hardcore people that come after that. So, I usually elect to keep this short and simple. This is the method I am currently using in one of my websites. This returns only a relative day, hour and time. And then the user has to slap on "ago" in the output. ``` public static string ToLongString(this TimeSpan time) { string output = String.Empty; if (time.Days > 0) output += time.Days + " days "; if ((time.Days == 0 || time.Days == 1) && time.Hours > 0) output += time.Hours + " hr "; if (time.Days == 0 && time.Minutes > 0) output += time.Minutes + " min "; if (output.Length == 0) output += time.Seconds + " sec"; return output.Trim(); } ```
null
CC BY-SA 4.0
null
2008-08-01T12:17:19.357
2020-07-18T04:19:14.303
2020-07-18T04:19:14.303
10,325,630
17
null
25
1
1,443,907
null
175
15,845
I'm having issues getting the C sockets API to work properly in C++ on z/OS. Although I am including `sys/socket.h`, I still get compile time errors telling me that `AF_INET` is not defined. Am I missing something obvious, or is this related to the fact that being on z/OS makes my problems much more complicated? I discovered that there is an `#ifdef` that I'm hitting. Apparently z/OS isn't happy unless I define which "type" of sockets I'm using with: ``` #define _OE_SOCKETS ``` Now, I personally have no idea what this `_OE_SOCKETS` is actually for, so if any z/OS sockets programmers are out there (all 3 of you), perhaps you could give me a rundown of how this all works? Test App ``` #include <sys/socket.h> int main() { return AF_INET; } ``` Compile/Link Output: ``` cxx -Wc,xplink -Wl,xplink -o inet_test inet.C "./inet.C", line 5.16: CCN5274 (S) The name lookup for "AF_INET" did not find a declaration. CCN0797(I) Compilation failed for file ./inet.C. Object file not created. ``` A check of sys/sockets.h does include the definition I need, and as far as I can tell, it is not being blocked by any `#ifdef` statements. I have however noticed it contains the following: ``` #ifdef __cplusplus extern "C" { #endif ``` which encapsulates basically the whole file? Not sure if it matters.
How to use the C socket API in C++ on z/OS
CC BY-SA 4.0
0
2008-08-01T12:13:50.207
2020-12-02T17:23:58.717
2020-12-02T17:23:58.717
792,066
23
[ "c++", "c", "sockets", "mainframe", "zos" ]
34
1
null
null
96
11,240
How do I forcefully unload a `ByteArray` from memory using ActionScript 3? I have tried the following: ``` // First non-working solution byteArray.length = 0; byteArray = new ByteArray(); // Second non-working solution for ( var i:int=0; i < byteArray.length; i++ ) { byteArray[i] = null; } ```
How to unload a ByteArray using Actionscript 3?
CC BY-SA 4.0
0
2008-08-01T12:30:57.630
2022-11-21T06:37:32.257
2020-12-02T17:21:52.303
792,066
null
[ "arrays", "actionscript-3", "apache-flex" ]
42
1
77
null
294
40,275
I am starting a new web application in PHP and this time around I want to create something that people can extend by using a plugin interface. How does one go about writing 'hooks' into their code so that plugins can attach to specific events?
Best way to allow plugins for a PHP application
CC BY-SA 3.0
0
2008-08-01T12:50:18.587
2021-05-29T06:04:39.960
2015-12-14T20:05:51.823
4,595,675
37
[ "php", "plugins", "architecture", "hook" ]
18
2
null
17
59
null
For a table like this: ``` CREATE TABLE binary_data ( id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, description CHAR(50), bin_data LONGBLOB, filename CHAR(50), filesize CHAR(50), filetype CHAR(50) ); ``` Here is a PHP example: ``` <?php // store.php3 - by Florian Dittmer <dittmer@gmx.net> // Example php script to demonstrate the storing of binary files into // an sql database. More information can be found at http://www.phpbuilder.com/ ?> <html> <head><title>Store binary data into SQL Database</title></head> <body> <?php // Code that will be executed if the form has been submitted: if ($submit) { // Connect to the database (you may have to adjust // the hostname, username or password). mysql_connect("localhost", "root", "password"); mysql_select_db("binary_data"); $data = mysql_real_escape_string(fread(fopen($form_data, "r"), filesize($form_data))); $result = mysql_query("INSERT INTO binary_data (description, bin_data, filename, filesize, filetype) ". "VALUES ('$form_description', '$data', '$form_data_name', '$form_data_size', '$form_data_type')"); $id= mysql_insert_id(); print "<p>This file has the following Database ID: <b>$id</b>"; mysql_close(); } else { // else show the form to submit new data: ?> <form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data"> File Description:<br> <input type="text" name="form_description" size="40"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> <br>File to upload/store in database:<br> <input type="file" name="form_data" size="40"> <p><input type="submit" name="submit" value="submit"> </form> <?php } ?> </body> </html> ```
null
CC BY-SA 3.0
null
2008-08-01T05:12:44.193
2016-06-02T05:56:26.060
2016-06-02T05:56:26.060
126,039
null
null
33
2
null
14
559
null
`Math.Floor` rounds down, `Math.Ceiling` rounds up, and `Math.Truncate` rounds towards zero. Thus, `Math.Truncate` is like `Math.Floor` for positive numbers, and like `Math.Ceiling` for negative numbers. Here's the [reference](https://learn.microsoft.com/en-us/dotnet/api/system.math.truncate). For completeness, `Math.Round` rounds to the nearest integer. If the number is exactly midway between two integers, then it rounds towards the even one. [Reference.](https://learn.microsoft.com/en-us/dotnet/api/system.math.round) See also: [Pax Diablo's answer](https://stackoverflow.com/questions/14/whats-the-difference-between-math-floor-and-math-truncate-in-c/580252#580252). Highly recommended!
null
CC BY-SA 4.0
null
2008-08-01T12:26:39.773
2022-04-22T08:57:37.830
2022-04-22T08:57:37.830
121,309
13
null
39
1
45
null
114
7,992
I am aware that in [.NET](http://en.wikipedia.org/wiki/.NET_Framework) there are three timer types (see [Comparing the Timer Classes in the .NET Framework Class Library](http://msdn.microsoft.com/en-us/magazine/cc164015.aspx)). I have chosen a threaded timer as the other types can drift if the main thread is busy, and I need this to be reliable. The way this timer works in the control of the timer is put on another thread so it can always tick along with the work begin completed on the parent thread when it is not busy. The issue with this timer in a console application is that while the timer is ticking along on another thread the main thread is not doing anything to the application closes. I tried adding a `while true` loop, but then the main thread is too busy when the timer does go off.
Reliable timer in a console application
CC BY-SA 4.0
0
2008-08-01T12:43:11.503
2020-12-10T16:48:40.317
2019-01-20T13:50:37.530
567,854
33
[ "c#", ".net", "vb.net", "timer" ]
51
2
null
36
24
null
Why don't you want to use triggers? They are a good thing if you use them correctly. If you use them as a way to enforce referential integrity that is when they go from good to bad. But if you use them for monitoring, they are not really considered taboo.
null
CC BY-SA 3.0
null
2008-08-01T13:07:52.810
2017-01-26T17:38:44.893
2017-01-26T17:38:44.893
3,735,690
17
null
44
2
null
39
23
null
Consider using a [ManualResetEvent](https://learn.microsoft.com/en-us/dotnet/api/system.threading.manualresetevent) to block the main thread at the end of its processing, and call `Reset()` on it once the timer's processing has finished. If this is something that needs to run continuously, consider moving this into a service process instead of a console app.
null
CC BY-SA 4.0
null
2008-08-01T12:55:42.413
2019-12-24T11:07:38.933
2019-12-24T11:07:38.933
806,202
35
null
49
2
null
24
67
null
[Here is one hack](https://web.archive.org/web/20180330233216/http://www.brokenbuild.com/blog/2006/08/15/mysql-triggers-how-do-you-abort-an-insert-update-or-delete-with-a-trigger/) that may work. It isn't clean, but it looks like it might work: Essentially, you just try to update a column that doesn't exist.
null
CC BY-SA 4.0
null
2008-08-01T13:02:51.900
2019-05-15T01:15:24.680
2019-05-15T01:15:24.680
6,083,675
43
null
45
2
null
39
63
null
You can use something like `Console.ReadLine()` to block the main thread, so other background threads (like timer threads) will still work. You may also use an [AutoResetEvent](https://learn.microsoft.com/en-us/dotnet/api/system.threading.autoresetevent) to block the execution, then (when you need to) you can call Set() method on that AutoResetEvent object to release the main thread. Also ensure that your reference to Timer object doesn't go out of scope and garbage collected.
null
CC BY-SA 4.0
null
2008-08-01T12:56:37.920
2019-12-24T10:19:21.920
2019-12-24T10:19:21.920
5,407,188
39
null
36
1
352
null
153
74,269
How can I monitor an SQL Server database for changes to a table without using triggers or modifying the structure of the database in any way? My preferred programming environment is [.NET](http://en.wikipedia.org/wiki/.NET_Framework) and C#. I'd like to be able to support any [SQL Server 2000](http://en.wikipedia.org/wiki/Microsoft_SQL_Server#Genesis) SP4 or newer. My application is a bolt-on data visualization for another company's product. Our customer base is in the thousands, so I don't want to have to put in requirements that we modify the third-party vendor's table at every installation. By I mean changes to table data, not changes to table structure. Ultimately, I would like the change to trigger an event in my application, instead of having to check for changes at an interval. --- The best course of action given my requirements (no triggers or schema modification, SQL Server 2000 and 2005) seems to be to use the `BINARY_CHECKSUM` function in [T-SQL](http://en.wikipedia.org/wiki/Transact-SQL). The way I plan to implement is this: Every X seconds run the following query: ``` SELECT CHECKSUM_AGG(BINARY_CHECKSUM(*)) FROM sample_table WITH (NOLOCK); ``` And compare that against the stored value. If the value has changed, go through the table row by row using the query: ``` SELECT row_id, BINARY_CHECKSUM(*) FROM sample_table WITH (NOLOCK); ``` And compare the returned checksums against stored values.
Check for changes to an SQL Server table?
CC BY-SA 3.0
0
2008-08-01T12:35:56.917
2021-03-06T07:40:44.407
2016-11-30T07:50:37.517
2,571,493
32
[ "sql", "sql-server", "datatable", "rdbms" ]
58
2
null
48
66
null
Change the previous button type into a button like this: ``` <input type="button" name="prev" value="Previous Page" /> ``` Now the button would be the default, plus you could also add the `default` attribute to it so that your browser will highlight it like so: ``` <input type="submit" name="next" value="Next Page" default /> ```
null
CC BY-SA 4.0
null
2008-08-01T13:14:30.303
2019-07-14T14:28:03.340
2019-07-14T14:28:03.340
63,550
37
null
48
1
31,910
null
286
251,580
Let's say you create a wizard in an HTML form. One button goes back, and one goes forward. Since the button appears first in the markup when you press , it will use that button to submit the form. Example: ``` <form> <!-- Put your cursor in this field and press Enter --> <input type="text" name="field1" /> <!-- This is the button that will submit --> <input type="submit" name="prev" value="Previous Page" /> <!-- But this is the button that I WANT to submit --> <input type="submit" name="next" value="Next Page" /> </form> ``` I would like to get to decide which button is used to submit the form when a user presses . That way, when you press the wizard will move to the next page, not the previous. Do you have to use `tabindex` to do this?
Multiple submit buttons in an HTML form
CC BY-SA 4.0
0
2008-08-01T13:01:17.303
2022-07-22T04:53:16.983
2019-07-14T14:18:39.680
63,550
40
[ "html", "forms", "form-submit", "submit-button" ]
59
1
43,110
null
117
26,917
I have a `DataTable` with a `Name` column. I want to generate a collection of the unique names ordered alphabetically. The following query ignores the clause. ``` var names = (from DataRow dr in dataTable.Rows orderby (string)dr["Name"] select (string)dr["Name"]).Distinct(); ``` Why does the `orderby` not get enforced?
How do I get a distinct, ordered list of names from a DataTable using LINQ?
CC BY-SA 3.0
0
2008-08-01T13:14:33.797
2019-09-30T08:49:44.503
2018-01-30T16:56:45.910
3,919,949
45
[ "c#", "linq", ".net-3.5" ]
52
2
null
34
19
null
Have a look at this article [http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html](http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html) IANA actionscript programmer, however the feeling I'm getting is that, because the garbage collector might not run when you want it to. Hence [http://www.craftymind.com/2008/04/09/kick-starting-the-garbage-collector-in-actionscript-3-with-air/](http://www.craftymind.com/2008/04/09/kick-starting-the-garbage-collector-in-actionscript-3-with-air/) So I'd recommend trying out their collection code and see if it helps ``` private var gcCount:int; private function startGCCycle():void{ gcCount = 0; addEventListener(Event.ENTER_FRAME, doGC); } private function doGC(evt:Event):void{ flash.system.System.gc(); if(++gcCount > 1){ removeEventListener(Event.ENTER_FRAME, doGC); setTimeout(lastGC, 40); } } private function lastGC():void{ flash.system.System.gc(); } ```
null
CC BY-SA 2.5
null
2008-08-01T13:08:59.127
2008-08-01T13:08:59.127
null
null
23
null
62
2
null
59
58
null
So your query will need to work like this ``` var names = (from DataRow dr in dataTable.Rows select (string)dr["Name"]).Distinct().OrderBy( name => name ); ```
null
CC BY-SA 3.0
null
2008-08-01T13:18:37.640
2014-08-19T23:17:56.597
2014-08-19T23:17:56.597
1,248,536
45
null
53
2
null
34
24
null
(I'm not positive about this, but...) AS3 uses a non-deterministic garbage collection which means that dereferenced memory will be freed up whenever the runtime feels like it (typically not unless there's a reason to run, since it's an expensive operation to execute). This is the same approach used by most modern garbage collecting languages (like C# and Java as well). Assuming there are no other references to the memory pointed to by `byteArray` or the items within the array itself, the memory will be freed at some point after you exit the scope where `byteArray` is declared. You can force a garbage collection, though you really shouldn't. If you do, do it only for testing. If you do it in production, you'll hurt performance much more than help it. To force a GC, try (yes, twice): ``` flash.system.System.gc(); flash.system.System.gc(); ``` [You can read more here](http://www.craftymind.com/2008/04/09/kick-starting-the-garbage-collector-in-actionscript-3-with-air/).
null
CC BY-SA 4.0
null
2008-08-01T13:08:59.487
2020-07-23T22:42:04.643
2020-07-23T22:42:04.643
10,325,630
34
null
66
1
4,521
null
89
5,986
How do you page through a collection in LINQ given that you have a `startIndex` and a `count`?
Paging a collection with LINQ
CC BY-SA 3.0
0
2008-08-01T13:20:46.890
2018-04-08T18:47:49.823
2012-05-04T09:03:54.213
1,039,608
17
[ "linq", ".net-3.5" ]
61
1
null
null
52
4,186
Where can I find a list of all of the MIME types and the identifying characters for files? I have an upload form that is restricting uploads based on the extensions and identifying characters, but I cannot seem to find the types. Can anyone help?
Microsoft Office 2007 file type, Mime types and identifying characters
CC BY-SA 4.0
0
2008-08-01T13:17:20.640
2021-07-28T13:00:55.547
2019-12-16T11:47:55.443
5,044,304
null
[ "mime", "file-type", "office-2007" ]
56
2
null
48
60
null
Give your submit buttons the same name like this: ``` <input type="submit" name="submitButton" value="Previous Page" /> <input type="submit" name="submitButton" value="Next Page" /> ``` When the user presses and the goes to the server, you can check the value for `submitButton` on your server-side code which contains a collection of form `name/value` pairs. For example, in [ASP Classic](http://en.wikipedia.org/wiki/Active_Server_Pages): ``` If Request.Form("submitButton") = "Previous Page" Then ' Code for the previous page ElseIf Request.Form("submitButton") = "Next Page" Then ' Code for the next page End If ``` Reference: [Using multiple submit buttons on a single form](http://www.chami.com/tips/internet/042599I.html)
null
CC BY-SA 4.0
null
2008-08-01T13:10:16.473
2019-07-14T14:26:23.487
2019-07-14T14:26:23.487
63,550
39
null
60
2
null
34
15
null
Unfortunately when it comes to memory management in there isn't a whole lot you can do. ActionScript was designed to be easy to use (so they didn't want people to have to worry about memory management) The following is a workaround, instead of creating a `ByteArray` variable try this. ``` var byteObject:Object = new Object(); byteObject.byteArray = new ByteArray(); ... //Then when you are finished delete the variable from byteObject delete byteObject.byteArray; ``` Where `byteArray` is a dynamic property of `byteObject`, you can free the memory that was allocated for it.
null
CC BY-SA 3.0
null
2008-08-01T13:14:40.007
2014-07-11T14:58:07.480
2014-07-11T14:58:07.480
2,354,564
41
null
68
2
null
66
65
null
It is very simple with the `Skip` and `Take` extension methods. ``` var query = from i in ideas select i; var paggedCollection = query.Skip(startIndex).Take(count); ```
null
CC BY-SA 3.0
null
2008-08-01T13:22:04.483
2012-05-04T09:04:26.523
2012-05-04T09:04:26.523
1,039,608
17
null
78
2
null
4
68
null
It sounds like `this.Opacity` is a double value, and the compiler doesn't like you trying to cram a decimal value into it.
null
CC BY-SA 3.0
null
2008-08-01T13:53:06.357
2012-10-14T11:54:40.347
2012-10-14T11:54:40.347
967,315
55
null
72
1
null
null
48
2,089
I want to format my existing comments as 'RDoc comments' so they can be viewed using `ri`. What are some recommended resources for starting out using RDoc?
How do I add existing comments to RDoc in Ruby?
CC BY-SA 3.0
null
2008-08-01T13:38:27.133
2016-12-30T06:56:18.310
2016-12-30T06:56:18.310
2,909,897
25
[ "ruby", "rdoc" ]
65
2
null
61
26
null
[Office 2007 MIME Types for IIS](http://www.bram.us/2007/05/25/office-2007-mime-types-for-iis/) - `.docm`- `.docx`- `.dotm`- `.dotx`- `.potm`- `.potx`- `.ppam`- `.ppsm`- `.ppsx`- `.pptm`- `.pptx`- `.xlam`- `.xlsb`- `.xlsm`- `.xlsx`- `.xltm`- `.xltx`
null
CC BY-SA 3.0
null
2008-08-01T13:20:44.283
2017-01-02T03:57:33.723
2017-01-02T03:57:33.723
5,898,312
35
null
76
2
null
42
20
null
I believe the easiest way would be to follow Jeff's own advice and have a look around the existing code. Try looking at WordPress, Drupal, Joomla, and other well-known PHP-based CMS to see how their API hooks look and feel. This way you can even get ideas you may have not thought of previously to make things a little more robust. A more direct answer would be to write general files that they would "include_once" into their file that would provide the usability they would need. This would be broken up into categories and NOT provided in one MASSIVE "hooks.php" file. Be careful though, because what ends up happening is that files that they include end up having more and more dependencies and functionality improves. Try to keep API dependencies low. I.E fewer files for them to include.
null
CC BY-SA 4.0
null
2008-08-01T13:44:35.843
2021-05-29T06:04:39.960
2021-05-29T06:04:39.960
11,277,894
50
null
73
2
null
25
24
null
@Jax: The `extern "C"` thing matters, very very much. If a header file doesn't have one, then (unless it's a C++-only header file), you would have to enclose your `#include` with it: ``` extern "C" { #include <sys/socket.h> // include other similarly non-compliant header files } ``` Basically, anytime where a C++ program wants to link to C-based facilities, the `extern "C"` is vital. In practical terms, it means that the names used in external references will not be mangled, like normal C++ names would. [Reference.](http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html)
null
CC BY-SA 2.5
null
2008-08-01T13:40:16.443
2008-08-01T13:54:25.510
2008-08-01T13:54:25.510
13
13
null
71
2
null
19
80
null
Here's a general description of a technique for calculating pi that I learnt in high school. I only share this because I think it is simple enough that anyone can remember it, indefinitely, plus it teaches you the concept of "Monte-Carlo" methods -- which are statistical methods of arriving at answers that don't immediately appear to be deducible through random processes. Draw a square, and inscribe a quadrant (one quarter of a semi-circle) inside that square (a quadrant with radius equal to the side of the square, so it fills as much of the square as possible) Now throw a dart at the square, and record where it lands -- that is, choose a random point anywhere inside the square. Of course, it landed inside the square, but is it inside the semi-circle? Record this fact. Repeat this process many times -- and you will find there is a ratio of the number of points inside the semi-circle versus the total number thrown, call this ratio x. Since the area of the square is r times r, you can deduce that the area of the semi circle is x times r times r (that is, x times r squared). Hence x times 4 will give you pi. This is not a quick method to use. But it's a nice example of a Monte Carlo method. And if you look around, you may find that many problems otherwise outside your computational skills can be solved by such methods.
null
CC BY-SA 3.0
null
2008-08-01T13:37:59.723
2012-05-25T21:09:03.593
2012-05-25T21:09:03.593
63,550
49
null
81
2
null
34
15
null
I believe you have answered your own question. `System.totalMemory` gives you the total amount of memory being "used", not allocated. It is accurate that your application may only be using 20 MB, but it has 5 MB that is free for future allocations. I'm not sure whether the Adobe docs would shed light on the way that it manages memory.
null
CC BY-SA 4.0
null
2008-08-01T14:03:22.230
2020-07-24T05:51:27.653
2020-07-24T05:51:27.653
10,325,630
41
null
84
2
null
16
18
null
If you use a return type of `IEnumerable`, you can return your variable directly.
null
CC BY-SA 2.5
null
2008-08-01T14:10:55.757
2008-10-18T18:26:59.070
2008-10-18T18:26:59.070
5,469
60
null
85
1
154
null
131
68,466
What are the best practices around creating flat file database structures in PHP? A lot of more matured PHP flat file frameworks out there which I attempt to implement SQL-like query syntax which is over the top for my purposes in most cases. (I would just use a database at that point). Are there any elegant tricks out there to get good performance and features with a small code overhead?
Flat file databases
CC BY-SA 4.0
0
2008-08-01T14:19:52.510
2022-03-07T02:25:38.080
2019-11-08T09:37:38.317
2,732,762
59
[ "php", "sql", "database", "flat-file" ]
82
2
null
36
16
null
Have a DTS job (or a job that is started by a windows service) that runs at a given interval. Each time it is run, it gets information about the given table by using the system [INFORMATION_SCHEMA](http://msdn.microsoft.com/en-us/library/ms186778.aspx) tables, and records this data in the data repository. Compare the data returned regarding the structure of the table with the data returned the previous time. If it is different, then you know that the structure has changed. Example query to return information regarding all of the columns in table ABC (ideally listing out just the columns from the INFORMATION_SCHEMA table that you want, instead of using *select ** like I do here): ``` select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'ABC' ``` You would monitor different columns and INFORMATION_SCHEMA views depending on how exactly you define "changes to a table".
null
CC BY-SA 2.5
null
2008-08-01T14:06:28.560
2008-08-01T14:06:28.560
null
null
51
null
86
2
null
4
148
null
is for monetary calculations to preserve precision. is for scientific calculations that do not get affected by small differences. Since Double is a type that is native to the CPU (internal representation is stored in ), calculations made with Double perform better than Decimal (which is represented in internally).
null
CC BY-SA 4.0
null
2008-08-01T14:23:28.087
2020-12-23T23:14:39.570
2020-12-23T23:14:39.570
14,438,770
39
null
77
2
null
42
168
null
You could use an Observer pattern. A simple functional way to accomplish this: ``` <?php /** Plugin system **/ $listeners = array(); /* Create an entry point for plugins */ function hook() { global $listeners; $num_args = func_num_args(); $args = func_get_args(); if($num_args < 2) trigger_error("Insufficient arguments", E_USER_ERROR); // Hook name should always be first argument $hook_name = array_shift($args); if(!isset($listeners[$hook_name])) return; // No plugins have registered this hook foreach($listeners[$hook_name] as $func) { $args = $func($args); } return $args; } /* Attach a function to a hook */ function add_listener($hook, $function_name) { global $listeners; $listeners[$hook][] = $function_name; } ///////////////////////// /** Sample Plugin **/ add_listener('a_b', 'my_plugin_func1'); add_listener('str', 'my_plugin_func2'); function my_plugin_func1($args) { return array(4, 5); } function my_plugin_func2($args) { return str_replace('sample', 'CRAZY', $args[0]); } ///////////////////////// /** Sample Application **/ $a = 1; $b = 2; list($a, $b) = hook('a_b', $a, $b); $str = "This is my sample application\n"; $str .= "$a + $b = ".($a+$b)."\n"; $str .= "$a * $b = ".($a*$b)."\n"; $str = hook('str', $str); echo $str; ?> ``` ``` This is my CRAZY application 4 + 5 = 9 4 * 5 = 20 ``` For this example source code, you must declare all your plugins before the actual source code that you want to be extendable. I've included an example of how to handle single or multiple values being passed to the plugin. The hardest part of this is writing the actual documentation which lists what arguments get passed to each hook. This is just one method of accomplishing a plugin system in PHP. There are better alternatives, I suggest you check out the WordPress Documentation for more information.
null
CC BY-SA 4.0
null
2008-08-01T13:46:00.097
2020-02-27T07:45:37.470
2020-02-27T07:45:37.470
-1
40
null
79
1
62,853
null
50
11,396
The version of currently available through Aptana's automatic does not work with the newest version of Subversion. I see on the Subclipse website however that they have 1.4.2 out for Eclipse. So I added a [new remote update site](http://subclipse.tigris.org/update_1.4.x) to my Update manager. When I tried to install it, it told me I needed . So after much searching I found Mylyn 3.0.0 and added [another new remote update site](http://download.eclipse.org/tools/mylyn/update/e3.3) to my update manager. Then when I tried to install that, it told me I needed or equivalent. Looking at the configuration details for Aptana, it looks like it is built against eclipse 3.2.2. Does anyone know if there is a way to upgrade the version of Eclipse Aptana that is built against to 3.3.0? Or if there is some other way to get Subclipse to work with the very newest version of Subversion? I know this isn't necessarily a "programming" question, but I hope it's ok since it's highly relevant to the programming experience.
Getting Subclipse in Aptana to work with the newest release of Subversion
CC BY-SA 3.0
0
2008-08-01T13:56:33.837
2022-12-06T16:26:44.847
2016-03-10T03:47:08.200
415,755
58
[ "eclipse", "svn", "aptana", "subclipse" ]
89
2
null
79
7
null
I've had problems with JavaHL in Eclipse Ganymede, when it worked fine in Eclipse Europa. I'm not sure how Aptana is different, but try either upgrading JavaHL or switching to the pure-java SVNKit implementation within the Subclipse config.
null
CC BY-SA 2.5
null
2008-08-01T14:41:01.110
2008-08-01T14:41:01.110
null
null
null
null
87
2
null
85
13
null
One framework I'm considering would be for a blogging platform. Since just about any possible view of data you would want would be sorted by date, I was thinking about this structure: One directory per content node: ``` ./content/YYYYMMDDHHMMSS/ ``` Subdirectories of each node including ``` /tags /authors /comments ``` As well as simple text files in the node directory for pre- and post-rendered content and the like. This would allow a simple PHP [glob()](http://us3.php.net/glob) call (and probably a reversal of the result array) to query on just about anything within the content structure: ``` glob("content/*/tags/funny"); ``` Would return paths including all articles tagged "funny".
null
CC BY-SA 3.0
null
2008-08-01T14:26:22.793
2015-08-24T17:19:04.537
2015-08-24T17:19:04.537
4,551,041
59
null
93
2
null
88
4
null
From my experience, and from what I've read across the internet, the answer is "No," it is not guaranteed. It depends on CPU speed, operating system, flavor of Linux, etc.
null
CC BY-SA 2.5
null
2008-08-01T14:46:53.097
2008-08-01T15:01:13.003
2008-08-01T15:01:13.003
25
25
null
90
1
1,466,832
null
164
56,334
How do you [branch and merge](http://svnbook.red-bean.com/en/1.8/svn.branchmerge.html) with Apache Subversion using the TortoiseSVN client?
How do you branch and merge with TortoiseSVN?
CC BY-SA 3.0
0
2008-08-01T14:41:24.277
2017-08-24T17:01:23.503
2017-08-24T17:01:23.503
58
58
[ "svn", "tortoisesvn", "branch", "branching-and-merging" ]
92
2
null
90
15
null
[Version Control with Subversion](http://svnbook.red-bean.com/) A very good resource for source control in general. Not really TortoiseSVN specific, though.
null
CC BY-SA 2.5
null
2008-08-01T14:45:37.403
2008-08-01T14:45:37.403
null
null
61
null
80
1
124
null
54
6,530
I've written a database generation script in [SQL](http://en.wikipedia.org/wiki/SQL) and want to execute it in my [Adobe AIR](http://en.wikipedia.org/wiki/Adobe_Integrated_Runtime) application: ``` Create Table tRole ( roleID integer Primary Key ,roleName varchar(40) ); Create Table tFile ( fileID integer Primary Key ,fileName varchar(50) ,fileDescription varchar(500) ,thumbnailID integer ,fileFormatID integer ,categoryID integer ,isFavorite boolean ,dateAdded date ,globalAccessCount integer ,lastAccessTime date ,downloadComplete boolean ,isNew boolean ,isSpotlight boolean ,duration varchar(30) ); Create Table tCategory ( categoryID integer Primary Key ,categoryName varchar(50) ,parent_categoryID integer ); ... ``` I execute this in Adobe AIR using the following methods: ``` public static function RunSqlFromFile(fileName:String):void { var file:File = File.applicationDirectory.resolvePath(fileName); var stream:FileStream = new FileStream(); stream.open(file, FileMode.READ) var strSql:String = stream.readUTFBytes(stream.bytesAvailable); NonQuery(strSql); } public static function NonQuery(strSQL:String):void { var sqlConnection:SQLConnection = new SQLConnection(); sqlConnection.open(File.applicationStorageDirectory.resolvePath(DBPATH)); var sqlStatement:SQLStatement = new SQLStatement(); sqlStatement.text = strSQL; sqlStatement.sqlConnection = sqlConnection; try { sqlStatement.execute(); } catch (error:SQLError) { Alert.show(error.toString()); } } ``` No errors are generated, however only `tRole` exists. It seems that it only looks at the first query (up to the semicolon- if I remove it, the query fails). Is there a way to call multiple queries in one statement?
SQLStatement.execute() - multiple queries in one statement
CC BY-SA 3.0
0
2008-08-01T13:57:07.033
2018-08-27T01:12:05.427
2017-04-28T13:42:44.903
3,641,067
26
[ "apache-flex", "actionscript-3", "air" ]
98
2
null
88
63
null
Maybe. But you have bigger problems. `gettimeofday()` can result in incorrect timings if there are processes on your system that change the timer (ie, ntpd). On a "normal" linux, though, I believe the resolution of `gettimeofday()` is 10us. It can jump forward and backward and time, consequently, based on the processes running on your system. This effectively makes the answer to your question no. You should look into `clock_gettime(CLOCK_MONOTONIC)` for timing intervals. It suffers from several less issues due to things like multi-core systems and external clock settings. Also, look into the `clock_getres()` function.
null
CC BY-SA 3.0
null
2008-08-01T14:53:47.497
2012-10-14T12:28:51.043
2012-10-14T12:28:51.043
967,315
2,089,740
null
88
1
98
null
106
44,472
I am porting a game, that was originally written for the Win32 API, to Linux (well, porting the OS X port of the Win32 port to Linux). I have implemented `QueryPerformanceCounter` by giving the uSeconds since the process start up: ``` BOOL QueryPerformanceCounter(LARGE_INTEGER* performanceCount) { gettimeofday(&currentTimeVal, NULL); performanceCount->QuadPart = (currentTimeVal.tv_sec - startTimeVal.tv_sec); performanceCount->QuadPart *= (1000 * 1000); performanceCount->QuadPart += (currentTimeVal.tv_usec - startTimeVal.tv_usec); return true; } ``` This, coupled with `QueryPerformanceFrequency()` giving a constant 1000000 as the frequency, works well , giving me a 64-bit variable that contains `uSeconds` since the program's start-up. So I don't want to discover it works differently if the kernel was compiled in a certain way or anything like that. I am fine with it being non-portable to something other than Linux, however.
Is gettimeofday() guaranteed to be of microsecond resolution?
CC BY-SA 4.0
0
2008-08-01T14:36:18.640
2020-02-24T11:08:48.197
2020-02-24T11:08:48.197
7,014,431
61
[ "linux", "winapi", "visual-c++", "unix", "timer" ]
107
2
null
104
13
null
I guess in a managed environment, a leak would be you keeping an unnecessary reference to a large chunk of memory around.
null
CC BY-SA 2.5
null
2008-08-01T15:19:25.900
2008-08-01T15:19:25.900
null
null
61
null
103
2
null
13
57
null
JavaScript is the easiest way to get the client's local time. I would suggest using an [XMLHttpRequest](http://en.wikipedia.org/wiki/XMLHttpRequest) to send back the local time, and if that fails, fall back to the timezone detected based on their IP address. As far as geolocation, I've used [MaxMind GeoIP](http://www.maxmind.com/app/ip-location) on several projects and it works well, though I'm not sure if they provide timezone data. It's a service you pay for and they provide monthly updates to your database. They provide wrappers in several web languages.
null
CC BY-SA 4.0
null
2008-08-01T15:11:59.987
2018-10-13T13:07:16.667
2018-10-13T13:07:16.667
63,550
72
null
104
1
112
null
181
14,970
In .NET perspective: - [memory leak](https://en.wikipedia.org/wiki/Memory_leak)- - - -
Anatomy of a "Memory Leak"
CC BY-SA 4.0
0
2008-08-01T15:12:34.837
2018-06-08T15:37:29.390
2018-06-08T15:37:29.390
6,296,561
39
[ ".net", "performance", "memory-leaks", "com-interop" ]
111
2
null
108
39
null
I have been using the 64Bit version of TortoiseSVN for ages and I have never had issues with it on Windows 64Bit or Vista 64Bit. I am currently not aware of any other similiar SVN clients that do work on Vista. Is it possible the problem could lie within the configuration of TortoiseSVN or even the installation of Vista? Is the problem occurring on Vista native or SP 1?
null
CC BY-SA 2.5
null
2008-08-01T15:27:23.093
2008-08-01T15:27:23.093
null
null
146,270
null
110
2
null
104
7
null
I will concur with Bernard as to in .net what a mem leak would be. You could profile your application to see its memory use, and determine that if its managing a lot of memory when it should not be you could say it has a leak. In managed terms I will put my neck on the line to say it does go away once the process is killed/removed. Unmanaged code is its own beast and if a leak exists within it, it will follow a standard mem. leak definition.
null
CC BY-SA 3.0
null
2008-08-01T15:23:33.817
2015-11-30T21:14:09.740
2015-11-30T21:14:09.740
3,393,505
36
null
114
2
null
108
11
null
TortoiseSVN in combination with VisualSVN for Visual Studio.
null
CC BY-SA 3.0
null
2008-08-01T15:32:42.473
2013-11-07T16:52:15.250
2013-11-07T16:52:15.250
761,095
17
null
113
2
null
108
9
null
I'll second Diago's answer. I use TortoiseSVN on Vista x64 pretty heavily. I did upgrade directly from an older version to 1.5.2 though, and never used 1.5.1. Have you tried 1.5.2?
null
CC BY-SA 2.5
null
2008-08-01T15:32:11.337
2008-08-01T15:32:11.337
null
null
60
null
108
1
111
null
52
16,402
I've been using [TortoiseSVN](https://web.archive.org/web/20200229173754/http://tortoisesvn.tigris.org/) in a Windows environment for quite some time. It seems very feature-complete and nicely integrated into the Windows shell, and more importantly, it's fairly painless to teach to colleagues with little or no experience with source control. , since we have moved to Windows Vista 64bit, Tortoise has been very buggy and has seemed to cause lots of explorer.exe abnormalities and crashes. This has happened both with older versions of the software and the latest version (1.5.1 build 13563). I was curious if anyone has suggestions for other Subversion clients that will run on Windows (specifically Vista 64bit). Developers here use a variety of text editors so using Visual Studio or Dreamweaver for SVN is not ideal. I have heard great things about [Cornerstone](http://www.zennaware.com/cornerstone/), and would love something similar for Windows if it exists. --- I'm correlating the Vista/explorer problems with Tortoise because they normally occur when I'm using the functionality in Tortoise. Sometimes bringing up the "merge" screen will cause the GUI to start acting very strange and eventually hang or crash. I did not see 1.5.2 -- I'm installing now, maybe that will fix some of my issues.
Best Subversion clients for Windows Vista (64bit)
CC BY-SA 4.0
0
2008-08-01T15:22:29.467
2020-05-25T17:18:11.487
2020-05-25T17:18:11.487
11,262,648
72
[ "windows", "svn", "64-bit" ]
116
2
null
108
6
null
I too get explorer crashes in Vista (I'm not in the 64Bit version though). I'm using Vista Super Saijen (or whatever they are calling the most expensive version). I'm not having any bugs with Tortoise. My explorer does, however, crash about every other day (sometimes multiple times a day if it's having an "off" day). I'm not positive it's being caused by TortoiseSVN though. From what I hear, the explorer just crashes a lot in Vista... Have you tried uninstalling Tortoise and using Windows for a day or two and seeing if it still crashes? Do you restart your computer at least once a day (It seems the longer I go between restarts, the worse the crashes get)?
null
CC BY-SA 2.5
null
2008-08-01T15:34:43.873
2008-08-01T15:34:43.873
null
null
58
null
123
1
183
null
119
80,344
Is there an existing application or library in which will allow me to convert a `CSV` data file to `XML` file? The `XML` tags would be provided through possibly the first row containing column headings.
Java lib or app to convert CSV to XML file?
CC BY-SA 3.0
0
2008-08-01T16:08:52.353
2020-05-25T10:02:32.633
2015-10-27T09:34:09.503
2,553,431
78
[ "java", "xml", "csv", "data-conversion" ]
120
1
null
null
45
2,097
Does anyone have experience creating SQL-based ASP.NET site-map providers? I have the default XML file `web.sitemap` working properly with my Menu and SiteMapPath controls, but I'll need a way for the users of my site to create and modify pages dynamically. I need to tie page viewing permissions into the standard `ASP.NET` membership system as well.
ASP.NET Site Maps
CC BY-SA 4.0
0
2008-08-01T15:50:08.537
2020-09-21T19:13:30.407
2020-01-06T23:17:24.307
1,578,983
83
[ "sql", "asp.net", "xml", "sitemap" ]
19
1
531
null
351
67,439
I'm looking for the fastest way to obtain the value of Ο€, as a personal challenge. More specifically, I'm using ways that don't involve using `#define` constants like `M_PI`, or hard-coding the number in. The program below tests the various ways I know of. The inline assembly version is, in theory, the fastest option, though clearly not portable. I've included it as a baseline to compare against the other versions. In my tests, with built-ins, the `4 * atan(1)` version is fastest on GCC 4.2, because it auto-folds the `atan(1)` into a constant. With `-fno-builtin` specified, the `atan2(0, -1)` version is fastest. Here's the main testing program (`pitimes.c`): ``` #include <math.h> #include <stdio.h> #include <time.h> #define ITERS 10000000 #define TESTWITH(x) { \ diff = 0.0; \ time1 = clock(); \ for (i = 0; i < ITERS; ++i) \ diff += (x) - M_PI; \ time2 = clock(); \ printf("%s\t=> %e, time => %f\n", #x, diff, diffclock(time2, time1)); \ } static inline double diffclock(clock_t time1, clock_t time0) { return (double) (time1 - time0) / CLOCKS_PER_SEC; } int main() { int i; clock_t time1, time2; double diff; /* Warmup. The atan2 case catches GCC's atan folding (which would * optimise the ``4 * atan(1) - M_PI'' to a no-op), if -fno-builtin * is not used. */ TESTWITH(4 * atan(1)) TESTWITH(4 * atan2(1, 1)) #if defined(__GNUC__) && (defined(__i386__) || defined(__amd64__)) extern double fldpi(); TESTWITH(fldpi()) #endif /* Actual tests start here. */ TESTWITH(atan2(0, -1)) TESTWITH(acos(-1)) TESTWITH(2 * asin(1)) TESTWITH(4 * atan2(1, 1)) TESTWITH(4 * atan(1)) return 0; } ``` And the inline assembly stuff (`fldpi.c`) that will only work for x86 and x64 systems: ``` double fldpi() { double pi; asm("fldpi" : "=t" (pi)); return pi; } ``` And a build script that builds all the configurations I'm testing (`build.sh`): ``` #!/bin/sh gcc -O3 -Wall -c -m32 -o fldpi-32.o fldpi.c gcc -O3 -Wall -c -m64 -o fldpi-64.o fldpi.c gcc -O3 -Wall -ffast-math -m32 -o pitimes1-32 pitimes.c fldpi-32.o gcc -O3 -Wall -m32 -o pitimes2-32 pitimes.c fldpi-32.o -lm gcc -O3 -Wall -fno-builtin -m32 -o pitimes3-32 pitimes.c fldpi-32.o -lm gcc -O3 -Wall -ffast-math -m64 -o pitimes1-64 pitimes.c fldpi-64.o -lm gcc -O3 -Wall -m64 -o pitimes2-64 pitimes.c fldpi-64.o -lm gcc -O3 -Wall -fno-builtin -m64 -o pitimes3-64 pitimes.c fldpi-64.o -lm ``` Apart from testing between various compiler flags (I've compared 32-bit against 64-bit too because the optimizations are different), I've also tried switching the order of the tests around. But still, the `atan2(0, -1)` version still comes out on top every time.
What is the fastest way to get the value of Ο€?
CC BY-SA 4.0
0
2008-08-01T05:21:22.257
2022-10-19T20:48:46.340
2019-05-15T01:33:48.730
3,768,871
13
[ "performance", "algorithm", "language-agnostic", "unix", "pi" ]
99
2
null
88
9
null
> The actual resolution of gettimeofday() depends on the hardware architecture. Intel processors as well as SPARC machines offer high resolution timers that measure microseconds. Other hardware architectures fall back to the system’s timer, which is typically set to 100 Hz. In such cases, the time resolution will be less accurate. I obtained this answer from [High Resolution Time Measurement and Timers, Part I](http://web.archive.org/web/20160711223333/http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=272)
null
CC BY-SA 3.0
null
2008-08-01T14:55:08.477
2017-09-12T18:12:53.697
2017-09-12T18:12:53.697
6,761,181
25
null
124
2
null
80
20
null
I wound up using this. It is a kind of a hack, but it actually works pretty well. The only thing is you have to be very careful with your semicolons. : D ``` var strSql:String = stream.readUTFBytes(stream.bytesAvailable); var i:Number = 0; var strSqlSplit:Array = strSql.split(";"); for (i = 0; i < strSqlSplit.length; i++){ NonQuery(strSqlSplit[i].toString()); } ```
null
CC BY-SA 4.0
null
2008-08-01T16:09:47.687
2018-08-27T01:12:05.427
2018-08-27T01:12:05.427
8,708,364
26
null
127
2
null
126
65
null
This has religious war potential, but it seems to me that if you're using a getter/setter, you should use it internally as well - using both will lead to maintenance problems down the road (e.g. somebody adds code to a setter that to run every time that property is set, and the property is being set internally w/o that setter being called).
null
CC BY-SA 2.5
null
2008-08-01T16:13:47.600
2008-08-01T16:32:17.110
2008-08-01T16:32:17.110
35
35
null
128
2
null
126
20
null
It depends on how the property is used. For example, say you have a student object that has a name property. You could use your Get method to pull the name from the database, if it hasn't been retrieved already. This way you are reducing unnecessary calls to the database. Now let's say you have a private integer counter in your object that counts the number of times the name has been called. You may want to not use the Get method from inside the object because it would produce an invalid count.
null
CC BY-SA 2.5
null
2008-08-01T16:19:04.283
2008-08-01T16:19:04.283
null
null
26
null
133
2
null
123
4
null
This may be too basic or limited of a solution, but couldn't you do a [String.split()](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)) on each line of the file, remembering the result array of the first line to generate the XML, and just spit each line's array data out with the proper XML elements padding each iteration of a loop?
null
CC BY-SA 4.0
null
2008-08-01T16:31:43.430
2020-05-25T10:02:32.633
2020-05-25T10:02:32.633
11,262,648
59
null
135
2
null
129
8
null
Rolling your own PHP solution will certainly work though I'm not sure if there is a good way to automatically duplicate the schema from one DB to the other (maybe this was your question). If you are just copying data, and/or you need custom code anyway to convert between modified schemas between the two DB's, I would recommend using PHP 5.2+ and the PDO libraries. You'll be able to connect using PDO ODBC (and use MSSQL drivers). I had a lot of problems getting large text fields and multi-byte characters from MSSQL into PHP using other libraries.
null
CC BY-SA 2.5
null
2008-08-01T16:36:42.080
2008-08-01T16:36:42.080
null
null
72
null
129
1
null
null
90
96,578
I've been banging my head against `SQL Server 2005` trying to get a lot of data out. I've been given a database with nearly 300 tables in it and I need to turn this into a MySQL database. My first call was to use bcp but unfortunately it doesn't produce valid CSV - strings aren't encapsulated, so you can't deal with any row that has a string with a comma in it (or whatever you use as a delimiter) and I would still have to hand write all of the create table statements, as obviously CSV doesn't tell you anything about the data types. What would be better is if there was some tool that could connect to both SQL Server and MySQL, then do a copy. You lose views, stored procedures, trigger, etc, but it isn't hard to copy a table that only uses base types from one DB to another... is it? Does anybody know of such a tool? I don't mind how many assumptions it makes or what simplifications occur, as long as it supports integer, float, datetime and string. I have to do a lot of pruning, normalising, etc. anyway so I don't care about keeping keys, relationships or anything like that, but I need the initial set of data in fast!
How to export data from SQL Server 2005 to MySQL
CC BY-SA 3.0
0
2008-08-01T16:22:42.420
2020-07-29T02:35:05.697
2015-10-10T10:25:12.217
4,800,955
48
[ "mysql", "sql-server", "csv", "sql-server-2005", "bcp" ]
141
2
null
129
6
null
Another tool to try would be the [SQLMaestro suite](http://www.sqlmaestro.com). It is a little tricky nailing down the precise tool, but they have a variety of tools, both free and for purchase that handle a wide variety of tasks for multiple database platforms. I'd suggest trying the Data Wizard tool first for MySQL, since I believe that will have the proper "import" tool you need.
null
CC BY-SA 4.0
null
2008-08-01T16:47:54.927
2020-07-29T01:51:50.080
2020-07-29T01:51:50.080
10,325,630
71
null
109
1
2,585
null
68
6,074
Recently our site has been deluged with the resurgence of the [Asprox botnet](https://en.wikipedia.org/wiki/Asprox_botnet) [SQL injection](http://en.wikipedia.org/wiki/SQL_injection) attack. Without going into details, the attack attempts to execute SQL code by encoding the [T-SQL](http://en.wikipedia.org/wiki/Transact-SQL) commands in an ASCII encoded BINARY string. It looks something like this: ``` DECLARE%20@S%20NVARCHAR(4000);SET%20@S=CAST(0x44004500...06F007200%20AS%20NVARCHAR(4000));EXEC(@S);-- ``` I was able to decode this in SQL, but I was a little wary of doing this since I didn't know exactly what was happening at the time. I tried to write a simple decode tool, so I could decode this type of text without even touching [SQL Server](http://en.wikipedia.org/wiki/Microsoft_SQL_Server). The main part I need to be decoded is: ``` CAST(0x44004500...06F007200 AS NVARCHAR(4000)) ``` I've tried all of the following commands with no luck: ``` txtDecodedText.Text = System.Web.HttpUtility.UrlDecode(txtURLText.Text); txtDecodedText.Text = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(txtURLText.Text)); txtDecodedText.Text = Encoding.Unicode.GetString(Encoding.Unicode.GetBytes(txtURLText.Text)); txtDecodedText.Text = Encoding.ASCII.GetString(Encoding.Unicode.GetBytes(txtURLText.Text)); txtDecodedText.Text = Encoding.Unicode.GetString(Convert.FromBase64String(txtURLText.Text)); ``` What is the proper way to translate this encoding without using SQL Server? Is it possible? I'll take VB.NET code since I'm familiar with that too. --- Okay, I'm sure I'm missing something here, so here's where I'm at. Since my input is a basic string, I started with just a snippet of the encoded portion - 4445434C41 (which translates to DECLA) - and the first attempt was to do this... ``` txtDecodedText.Text = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(txtURL.Text)); ``` ...and all it did was return the exact same thing that I put in since it converted each character into is a byte. I realized that I need to parse every two characters into a byte manually since I don't know of any methods yet that will do that, so now my little decoder looks something like this: ``` while (!boolIsDone) { bytURLChar = byte.Parse(txtURLText.Text.Substring(intParseIndex, 2)); bytURL[intURLIndex] = bytURLChar; intParseIndex += 2; intURLIndex++; if (txtURLText.Text.Length - intParseIndex < 2) { boolIsDone = true; } } txtDecodedText.Text = Encoding.UTF8.GetString(bytURL); ``` Things look good for the first couple of pairs, but then the loop balks when it gets to the "4C" pair and says that the string is in the incorrect format. Interestingly enough, when I step through the debugger and to the GetString method on the byte array that I was able to parse up to that point, I get ",-+" as the result. How do I figure out what I'm missing - do I need to do a "direct cast" for each byte instead of attempting to parse it?
Decoding T-SQL CAST in C#/VB.NET
CC BY-SA 4.0
null
2008-08-01T15:23:05.190
2019-02-10T22:11:00.017
2019-01-20T13:49:56.720
567,854
71
[ "c#", "sql", "vb.net", "ascii", "hex" ]
139
2
null
126
14
null
> Am I just going overboard here? Perhaps ;) Another approach would be to utilize a private/protected method to actually do the getting (caching/db/etc), and a public wrapper for it that increments the count: PHP: ``` public function getName() { $this->incrementNameCalled(); return $this->_getName(); } protected function _getName() { return $this->name; } ``` and then from within the object itself: PHP: ``` $name = $this->_getName(); ``` This way you can still use that first argument for something else (like sending a flag for whether or not to used cached data here perhaps).
null
CC BY-SA 2.5
null
2008-08-01T16:43:30.880
2008-08-01T16:43:30.880
null
null
72
null
142
2
null
126
6
null
Well, it seems with C# 3.0 properties' default implementation, the decision is taken for you; you HAVE to set the property using the (possibly private) property setter. I personally only use the private member-behind when not doing so would cause the object to fall in an less than desirable state, such as when initializing or when caching/lazy loading is involved.
null
CC BY-SA 2.5
null
2008-08-01T16:56:55.830
2008-08-01T16:56:55.830
null
null
42
null
143
2
null
126
5
null
As stated in some of the comments: Sometimes you should, sometimes you shouldn't. The great part about private variables is that you are able to see all the places they are used when you change something. If your getter/setter does something you need, use it. If it doesn't matter you decide. The opposite case could be made that if you use the getter/setter and somebody changes the getter/setter they have to analyze all the places the getter and setter is used internally to see if it messes something up.
null
CC BY-SA 2.5
null
2008-08-01T17:01:27.240
2008-08-01T17:01:27.240
null
null
86
null
145
1
null
null
60
5,254
Does anyone know of a good way to compress or decompress files and folders in C# quickly? Handling large files might be necessary.
Compressing / Decompressing Folders & Files
CC BY-SA 3.0
0
2008-08-01T17:13:08.933
2020-03-18T11:24:20.170
2018-12-25T14:13:03.880
9,752,662
87
[ "c#", ".net", "file", "compression" ]
134
1
206
null
39
1,433
I have a pretty standard table set-up in a current application using the [.NET](https://en.wikipedia.org/wiki/.NET_Framework) [XSD](https://en.wikipedia.org/wiki/XML_Schema_%28W3C%29) `DataSet` and `TableAdapter` features. My `contracts` table consists of some standard contract information, with a column for the `primary department`. This column is a [foreign key](https://en.wikipedia.org/wiki/Foreign_key) to my `Departments` table, where I store the basic `department name`, `id`, `notes`. This is all setup and functioning in my [SQL Server](https://en.wikipedia.org/wiki/Microsoft_SQL_Server). When I use the XSD tool, I can drag both tables in at once and it auto detects/creates the foreign key I have between these two tables. This works great when I'm on my main page and am viewing contract data. However, when I go to my administrative page to modify the department data, I typically do something like this: ``` Dim dtDepartment As New DepartmentDataTable() Dim taDepartment As New DepartmentTableAdapter() taDepartment.Fill(dtDepartment) ``` However, at this point an exception is thrown saying to the effect that there is a foreign key reference broken here, I'm guessing since I don't have the `Contract DataTable` filled. How can I fix this problem? I know I can simply remove the foreign key from the XSD to make things work fine, but having the additional integrity check there and having the XSD schema match the SQL schema in the database is nice.
XSD DataSets and ignoring foreign keys
CC BY-SA 4.0
null
2008-08-01T16:33:38.183
2019-06-01T01:56:45.287
2019-06-01T01:56:45.287
10,221,765
71
[ ".net", "database", "xsd" ]
151
2
null
145
22
null
I've always used the SharpZip Library. [Here's a link](http://sharpdevelop.net/OpenSource/SharpZipLib/Download.aspx)
null
CC BY-SA 3.0
null
2008-08-01T17:30:56.277
2012-12-04T20:29:28.010
2012-12-04T20:29:28.010
1,525,840
44
null
148
2
null
146
7
null
Is the play link a link to the actual mp3 file or to some javascript code that pops up a player? If the latter, you can easily add your own logging code in there to track the number of hits to it. If the former, you'll need something that can track the web server log itself and make that distinction. My hosting plan comes with webalizer, which does this nicely.
null
CC BY-SA 2.5
null
2008-08-01T17:24:24.290
2008-08-01T17:24:24.290
null
null
71
null
149
2
null
145
10
null
As of .Net 1.1 the only available method is reaching into the java libraries. [Using the Zip Classes in the J# Class Libraries to Compress Files and Data with C#](https://learn.microsoft.com/en-us/archive/msdn-magazine/2003/june/using-jsharp-class-libraries-to-compress-files-and-data-with-csharp) Not sure if this has changed in recent versions.
null
CC BY-SA 4.0
null
2008-08-01T17:28:24.253
2019-12-24T08:08:12.950
2019-12-24T08:08:12.950
951,001
80
null
147
2
null
42
36
null
The and method is the most commonly used, but there are other things you can do. Depending on the size of your app, and who your going to allow see the code (is this going to be a FOSS script, or something in house) will influence greatly how you want to allow plugins. kdeloach has a nice example, but his implementation and hook function is a little unsafe. I would ask for you to give more information of the nature of php app your writing, And how you see plugins fitting in. +1 to kdeloach from me.
null
CC BY-SA 2.5
null
2008-08-01T17:23:43.777
2008-08-01T17:23:43.777
null
null
146,637
null
153
2
null
146
13
null
You could even set up an Apache .htaccess directive that converts *.mp3 requests into the querystring dubayou is working with. It might be an elegant way to keep the direct request and still be able to slipstream log function into the response.
null
CC BY-SA 2.5
null
2008-08-01T17:42:04.723
2008-08-01T17:42:04.723
null
null
59
null
126
1
127
null
105
23,701
What is the "purist" or "correct" way to access an object's properties from within an object method that is not a getter/setter method? I know that from outside of the object you should use a getter/setter, but from within would you just do: Java: ``` String property = this.property; ``` PHP: ``` $property = $this->property; ``` or would you do: Java: ``` String property = this.getProperty(); ``` PHP: ``` $property = $this->getProperty(); ``` Forgive me if my Java is a little off, it's been a year since I programmed in Java... It seems people are assuming I am talking about private or protected variables/properties only. When I learned OO I was taught to use getters/setters for every single property even if it was public (and actually I was told never to make any variable/property public). So, I may be starting off from a false assumption from the get go. It appears that people answering this question are maybe saying that you should have public properties and that those don't need getters and setters, which goes against what I was taught, and what I was talking about, although maybe that needs to be discussed as well. That's probably a good topic for a different question though...
How would you access Object properties from within an object method?
CC BY-SA 2.5
0
2008-08-01T16:10:30.337
2021-07-04T20:26:15.617
2010-01-20T08:27:13.130
202,431
58
[ "java", "php", "oop", "theory" ]
146
1
152
null
89
21,381
I have a website that plays mp3s in a flash player. If a user clicks 'play' the flash player automatically downloads an mp3 and starts playing it. Is there an easy way to track how many times a particular song clip (or any binary file) has been downloaded? --- > Is the play link a link to the actual mp3 file or to some javascript code that pops up a player?If the latter, you can easily add your own logging code in there to track the number of hits to it.If the former, you'll need something that can track the web server log itself and make that distinction. My hosting plan comes with Webalizer, which does this nicely. It's a javascript code so that answers that. However, it would be nice to know how to track downloads using the other method (without switching hosts).
How do I track file downloads
CC BY-SA 4.0
0
2008-08-01T17:14:58.337
2020-07-29T02:40:25.280
2019-06-04T09:25:21.993
6,556,397
30
[ "php", "apache", "logging", "download", "analytics" ]
155
2
null
108
8
null
I used to have lots of Explorer crashes (on 32-bit) caused by Tortoise. They seem to have gone away since I used the Include/Exclude path settings in the "Icon Overlays" configuration of TSVN. Constraining icon overlays to specific directories where I keep my source made this much more stable.
null
CC BY-SA 2.5
null
2008-08-01T17:47:54.727
2008-08-01T17:47:54.727
null
null
9
null
112
2
null
104
112
null
The best explanation I've seen is in Chapter 7 of the free [Foundations of Programming e-book](http://codebetter.com/karlseguin/2008/06/25/foundations-of-programming-ebook/). Basically, in a memory leak occurs when referenced objects are rooted and thus cannot be garbage collected. This occurs accidentally when you hold on to references beyond the intended scope. You'll know that you have leaks when you start getting OutOfMemoryExceptions or your memory usage goes up beyond what you'd expect ( has nice memory counters). Understanding 's memory model is your best way of avoiding it. Specifically, understanding how the garbage collector works and how references work β€” again, I refer you to chapter 7 of the e-book. Also, be mindful of common pitfalls, probably the most common being events. If object is registered to an event on object , then object will stick around until object disappears because holds a reference to . The solution is to unregister your events when you're done. Of course, a good memory profile will let you see your object graphs and explore the nesting/referencing of your objects to see where references are coming from and what root object is responsible ([red-gate ants profile](http://www.red-gate.com/products/ants_memory_profiler/index.htm), JetBrains dotMemory, [memprofiler](http://memprofiler.com/) are really good choices, or you can use the text-only and , but I'd strongly recommend a commercial/visual product unless you're a real guru). I believe unmanaged code is subject to its typical memory leaks, except that shared references are managed by the garbage collector. I could be wrong about this last point.
null
CC BY-SA 4.0
null
2008-08-01T15:28:12.543
2018-05-14T20:34:56.370
2018-05-14T20:34:56.370
7,232,508
34
null
158
2
null
146
30
null
Use your httpd log files. Install [http://awstats.sourceforge.net/](http://awstats.sourceforge.net/)
null
CC BY-SA 3.0
null
2008-08-01T17:51:55.407
2012-05-07T01:43:59.980
2012-05-07T01:43:59.980
null
70
null
160
2
null
129
59
null
The best way that I have found is the [MySQL Migration Toolkit](http://www.mysql.com/products/tools/migration-toolkit/) provided by MySQL. I have used it successfully for some large migration projects.
null
CC BY-SA 2.5
null
2008-08-01T17:54:08.163
2008-08-01T17:54:08.163
null
null
17
null
163
1
170
null
101
9,425
Stack Overflow has a subversion version number at the bottom: > svn revision: 679 I want to use such automatic versioning with my `.NET Web Site/Application`, Windows Forms, WPD projects/solutions. How do I implement this?
How do I sync the SVN revision number with my ASP.NET web site?
CC BY-SA 3.0
0
2008-08-01T18:00:13.830
2020-05-25T03:59:07.680
2015-12-29T06:27:21.560
3,787,519
83
[ ".net", "asp.net", "svn", "versioning" ]
154
2
null
85
81
null
Well, what is the nature of the flat databases. Are they large or small. Is it simple arrays with arrays in them? if its something simple say userprofiles built as such: ``` $user = array("name" => "bob", "age" => 20, "websites" => array("example.com","bob.example.com","bob2.example.com"), "and_one" => "more"); ``` and to save or update the for that user. ``` $dir = "../userdata/"; //make sure to put it bellow what the server can reach. file_put_contents($dir.$user['name'],serialize($user)); ``` and to load the for the user ``` function &get_user($name){ return unserialize(file_get_contents("../userdata/".$name)); } ``` but again this implementation will vary on the application and nature of the database you need.
null
CC BY-SA 4.0
null
2008-08-01T17:45:06.513
2022-03-07T02:25:38.080
2022-03-07T02:25:38.080
146,637
146,637
null
152
2
null
146
43
null
The funny thing is I wrote a php media gallery for all my musics 2 days ago. I had a similar problem. I'm using [http://musicplayer.sourceforge.net/](http://musicplayer.sourceforge.net/) for the player. And the playlist is built via php. All music requests go to a script called xfer.php?file=WHATEVER ``` $filename = base64_url_decode($_REQUEST['file']); header("Cache-Control: public"); header('Content-disposition: attachment; filename='.basename($filename)); header("Content-Transfer-Encoding: binary"); header('Content-Length: '. filesize($filename)); // Put either file counting code here, either a db or static files // readfile($filename); //and spit the user the file function base64_url_decode($input) { return base64_decode(strtr($input, '-_,', '+/=')); } ``` And when you call files use something like: ``` function base64_url_encode($input) { return strtr(base64_encode($input), '+/=', '-_,'); } ``` [http://us.php.net/manual/en/function.base64-encode.php](http://us.php.net/manual/en/function.base64-encode.php) If you are using some JavaScript or a flash player (JW player for example) that requires the actual link of an mp3 file or whatever, you can append the text "&type=.mp3" so the final link becomes something like: "www.example.com/xfer.php?file=34842ffjfjxfh&type=.mp3". That way it looks like it ends with an mp3 extension without affecting the file link.
null
CC BY-SA 4.0
null
2008-08-01T17:33:58.750
2020-07-29T02:40:25.280
2020-07-29T02:40:25.280
10,325,630
146,637
null

StackOverflow Posts Markdown

StackOverflow Logo

Dataset Summary

This dataset contains all posts submitted to StackOverflow before the 14th of June 2023 formatted as Markdown text.
The dataset contains ~60 Million posts, totaling ~35GB in size and ~65 billion characters of text.
The data is sourced from Internet Archive StackExchange Data Dump.

Dataset Structure

Each record corresponds to one post of a particular type. Original ordering from the data dump is not exactly preserved due to parallelism in the script used to process the data dump. The markdown content of each post is contained in the Body field. The license for a particular post is contained in the ContentLicense field.

Data Fields

{
  Id: long,
  PostTypeId: long, // 1=Question, 2=Answer, 3=Orphaned tag wiki, 4=Tag wiki excerpt, 5=Tag wiki, 6=Moderator nomination, 7=Wiki Placeholder, 8=Privilige Wiki
  AcceptedAnswerId: long | null, // only present if PostTypeId=1
  ParentId: long | null, // only present if PostTypeId=2
  Score: long,
  ViewCount: long | null,
  Body: string | null,
  Title: string | null,
  ContentLicense: string | null,
  FavoriteCount: long | null,
  CreationDate: string | null,
  LastActivityDate: string | null,
  LastEditDate: string | null,
  LastEditorUserId: long | null,
  OwnerUserId: long | null,
  Tags: array<string> | null
}

Also consider the StackExchange Datadump Schema Documentation, as all fields have analogs in the original dump format.

How to use?

from datasets import load_dataset

# predownload full dataset
ds = load_dataset('mikex86/stackoverflow-posts', split='train')

# dataset streaming (will only download the data as needed)
ds = load_dataset('mikex86/stackoverflow-posts', split='train', streaming=True)

for sample in iter(ds): print(sample["Body"])

How is the text stored?

The original Data Dump formats the "Body" field as HTML, using tags such as <code>, <h1>, <ul>, etc. This HTML format has been converted to Markdown.

Markdown format

For reference, this post on StackOverflow is formatted as follows:

Title: Make React useEffect hook not run on initial render

According to the docs:

​> `componentDidUpdate()` is invoked immediately after updating occurs. This method is not called for the initial render.

We can use the new `useEffect()` hook to simulate `componentDidUpdate()`, but it seems like `useEffect()` is being ran after every render, even the first time. How do I get it to not run on initial render?

As you can see in the example below, `componentDidUpdateFunction` is printed during the initial render but `componentDidUpdateClass` was not printed during the initial render.

​`​`​`
function ComponentDidUpdateFunction() {
  const [count, setCount] = React.useState(0);
  React.useEffect(() => {
    console.log(""componentDidUpdateFunction"");
  });

  return (
    <div>
      <p>componentDidUpdateFunction: {count} times</p>
      <button
        onClick={() => {
          setCount(count + 1);
        }}
      >
        Click Me
      </button>
    </div>
  );
}
​`​`​`

rest of the post omitted for brevity

Details on the HTML to Markdown conversion

Using Jsoup, the original Body field was converted into a Jsoup Document. The child nodes (has special meaning in context of Jsoup) of this document were recursively traversed in a depth-first order.

Jsoup defines .text() as follows:

... the normalized, combined text of this element and all its children. Whitespace is normalized and trimmed. For example, given HTML <p>Hello <b>there</b> now! </p>, p.text() returns "Hello there now!"

Jsoup defines a Node as follows:

The base, abstract Node model. Elements, Documents, Comments etc are all Node instances.

Additionally the existence of the TextNode should be noted, which represents floating text inside an HTML document that is not itself an HTML element. Thus this text tag <p>Hello<code>World</code></p> would have two Jsoup child nodes TextNode(value="Hello") and Element(tag="code", value="World"). The value field of a TextNode contains the free standing text without any further treatment (no whitespace stripping, etc.)

Traversing Rules

  • When ecountering a html tag for which a rule exists, children are not further traversed, unless explicitly stated otherwise.

  • When encountering an <a> tag, [${element.text()}](${element.attr("href")}) is emitted.

  • When encountering an <h1> tag, \n# ${element.text()}\n\n is emitted.

  • When encountering an <h2> tag, \n## ${element.text()}\n\n is emitted.

  • When encountering an <h3> tag, \n### ${element.text()}\n\n is emitted.

  • When encountering an <h4> tag, \n#### ${element.text()}\n\n is emitted.

  • When encountering an <h5> tag, \n##### ${element.text()}\n\n is emitted.

  • When encountering an <h6> tag, \n###### ${element.text()}\n\n is emitted.

  • When encountering a <code> tag, `${element.text()}`is emitted

  • When encountering a <pre> tag and said element has a <code> child tag, ​`​`​`\n${element.text()}`\n​`​`​`\n is emitted.

  • When encountering a <pre> tag and said element does not have a <code> child tag, children are traversed further.

  • When encountering an <li> tag, - is emitted and children are traversed further.

  • When encountering a <blockquote> tag, > is emitted and children are traversed further.

  • When encountering an <hr> tag, \n---\n\n is emitted

  • When encountering an <img> tag, ![${element.attr("alt")}](${element.attr("src")}) is emitted.

  • When encountering a <table> tag

    • \n| is emitted
    • For each element of element.select("th")
      • ${element.text()} | is emitted
    • After the loop \n| is emitted
    • For each element of element.select("th")
      • For each character of the th.text()
        • - is emitted
      • After the loop over each character of th | is emitted
    • \n is emitted
    • For each element of element.select("tr") with more than one children of tag type td
      • | is emitted
      • For each element of element.select("td")
        • ${td.text()} | is emitted
      • After the loop over <td> elements, \n is emitted
    • After the loop over <tr> elements, \n is emitted
  • When encountering a jsoup TextNode, ${node.attr(node.nodeName())} (which is equivalent to accessing the private field node.value) is emitted.

Downloads last month
1,693