text stringlengths 0 30.5k | title stringclasses 1
value | embeddings listlengths 768 768 |
|---|---|---|
calculate the computing resources (CPU, RAM, disk space, and network bandwidth) that are necessary to support current and future usage levels. | [
0.3158905506134033,
0.34764689207077026,
-0.042471613734960556,
0.3505917191505432,
0.5473935008049011,
0.3566138446331024,
-0.2150615155696869,
-0.17493011057376862,
0.2346503734588623,
-0.736944317817688,
-0.2639559805393219,
0.4614209830760956,
-0.12670336663722992,
-0.05160675197839737... | |
Here is an example of what I've got going on:
```
CREATE TABLE Parent (id BIGINT NOT NULL,
PRIMARY KEY (id)) ENGINE=InnoDB;
CREATE TABLE Child (id BIGINT NOT NULL,
parentid BIGINT NOT NULL,
PRIMARY KEY (id),
KEY (parentid),
CONSTRAINT fk_parent FOREIGN KEY (parentid) REFERENCES Parent (id) ON DELETE CASCADE) ENGINE=InnoDB;
CREATE TABLE Uncle (id BIGINT NOT NULL,
parentid BIGINT NOT NULL,
childid BIGINT NOT NULL,
PRIMARY KEY (id),
KEY (parentid),
KEY (childid),
CONSTRAINT fk_parent_u FOREIGN KEY (parentid) REFERENCES Parent (id) ON DELETE CASCADE,
CONSTRAINT fk_child FOREIGN KEY (childid) REFERENCES Child (id)) ENGINE=InnoDB;
```
Notice | [
-0.37721139192581177,
0.08585550636053085,
0.3255806863307953,
0.06037985160946846,
0.07791230827569962,
0.4935136139392853,
0.12582533061504364,
-0.220847487449646,
-0.47262266278266907,
-0.3624565303325653,
0.08331795036792755,
0.06904023885726929,
-0.36675572395324707,
0.579309463500976... | |
there is no ON DELETE CASCADE for the Uncle-Child relationship; i.e. deleting a Child does not delete its Uncle(s) and vice-versa.
When I have a Parent and an Uncle with the same Child, and I delete the Parent, it *seems* like InnoDB should be able to just "figure it out" and let the cascade ripple through the whole family (i.e. deleting the Parent deletes the Uncle and the Child as well). However, instead, I get the following:
```
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`cascade_test/uncle`, CONSTRAINT `fk_child` FOREIGN KEY (`childid`) REFERENCES `child` | [
-0.21191935241222382,
0.23192857205867767,
0.22783944010734558,
0.13139283657073975,
0.2859189510345459,
0.35700175166130066,
0.4844411611557007,
-0.24958065152168274,
-0.1831321269273758,
-0.34555163979530334,
-0.110807403922081,
0.05571915581822395,
-0.22067782282829285,
0.65991401672363... | |
(`id`))
```
InnoDB is trying to cascade-delete the Child before the Uncle(s) that refer to it.
Am I missing something? Is this *supposed* to fail for some reason I don't understand? Or is there some trick to making it work (or is it a bug in MySQL)?
The parent deletion is triggering the child deletion as you stated and I don't know why it goes to the child table before the uncle table. I imagine you would have to look at the dbms code to know for sure, but im sure there is an algorithm that picks which tables to cascade to first.
The system | [
0.10391562432050705,
0.3338002860546112,
0.15686474740505219,
0.03798438236117363,
0.018146993592381477,
0.21005798876285553,
0.43809574842453003,
-0.0345332957804203,
-0.14276188611984253,
-0.33702409267425537,
-0.046615902334451675,
0.08829987794160843,
-0.464957058429718,
0.610036730766... | |
does not really 'figure out' stuff the way you imply here and it is just following its constraint rules. The problem is the schema you created in that it encounters a constraint that will not let it pass further.
I see what you are saying.. if it hit the uncle table first it would delete the record and then delete the child (and not hit the uncle cascade from the child deletion). But even so, I don't think a schema would be set up to rely on that kind of behavior in reality. I think the only way to know | [
0.09022572636604309,
-0.12916560471057892,
-0.06534771621227264,
0.4392721354961395,
0.33470842242240906,
-0.17331284284591675,
0.21131494641304016,
-0.21143190562725067,
-0.682995080947876,
-0.11114315688610077,
0.3381262421607971,
0.3131585717201233,
-0.3471185266971588,
0.37867558002471... | |
for sure what is going on is to look through the code or get one of the mysql/postgresql programmers in here to say how it processes fk constraints. | [
0.035532835870981216,
0.4286503195762634,
0.09421562403440475,
0.22596541047096252,
0.07369263470172882,
-0.35070279240608215,
0.26748448610305786,
0.22002890706062317,
-0.4520745277404785,
-0.27293190360069275,
0.2765250504016876,
0.21142084896564484,
-0.2007487565279007,
0.06989330798387... | |
If user input is inserted without modification into an SQL query, then the application becomes vulnerable to [SQL injection](https://stackoverflow.com/a/332367/), like in the following example:
```php
$unsafe_variable = $_POST['user_input'];
mysql_query("INSERT INTO `table` (`column`) VALUES ('$unsafe_variable')");
```
That's because the user can input something like `value'); DROP TABLE table;--`, and the query becomes:
```
INSERT INTO `table` (`column`) VALUES('value'); DROP TABLE table;--')
```
What can be done to prevent this from happening?
The *correct* way to avoid SQL injection attacks, no matter which database you use, is to **separate the data from SQL**, so that data stays data and will **never be interpreted** as commands by the SQL parser. It is | [
-0.04599727317690849,
0.2952118515968323,
0.36653560400009155,
-0.16817566752433777,
0.2635580897331238,
-0.08485658466815948,
0.3667674958705902,
-0.2596093714237213,
-0.020206045359373093,
-0.4087055027484894,
-0.2610960900783539,
0.521224856376648,
-0.5053844451904297,
0.269403398036956... | |
possible to create an SQL statement with correctly formatted data parts, but if you don't *fully* understand the details, you should always **use prepared statements and parameterized queries.** These are SQL statements that are sent to and parsed by the database server separately from any parameters. This way it is impossible for an attacker to inject malicious SQL.
You basically have two options to achieve this:
1. Using [**PDO**](http://php.net/manual/en/book.pdo.php) (for any supported database driver):
```php
$stmt = $pdo->prepare('SELECT * FROM employees WHERE name = :name');
$stmt->execute([ 'name' => $name ]);
foreach ($stmt as $row) {
// Do something with $row
}
```
2. Using [**MySQLi**](http://php.net/manual/en/book.mysqli.php) (for | [
0.13727182149887085,
0.043228376656770706,
0.16416382789611816,
0.06259912252426147,
-0.23234713077545166,
-0.07183139771223068,
0.2737603187561035,
-0.47207343578338623,
0.005166693590581417,
-0.5731709599494934,
-0.23831278085708618,
0.5490407347679138,
-0.3710300028324127,
-0.1287434548... | |
MySQL):
```php
$stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?');
$stmt->bind_param('s', $name); // 's' specifies the variable type => 'string'
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
// Do something with $row
}
```
If you're connecting to a database other than MySQL, there is a driver-specific second option that you can refer to (for example, `pg_prepare()` and `pg_execute()` for PostgreSQL). PDO is the universal option.
---
Correctly setting up the connection
-----------------------------------
#### PDO
Note that when using **PDO** to access a MySQL database *real* prepared statements are **not used by default**. To fix this you have to disable the emulation of prepared statements. An example | [
-0.05046137422323227,
-0.1847163885831833,
0.4339193105697632,
0.04315134137868881,
-0.19643738865852356,
0.09176097810268402,
0.16610175371170044,
-0.2810460031032562,
-0.13851800560951233,
-0.6344953775405884,
-0.47451603412628174,
0.5914129018783569,
-0.29223987460136414,
-0.01981825940... | |
of creating a connection using **PDO** is:
```php
$dbConnection = new PDO('mysql:dbname=dbtest;host=127.0.0.1;charset=utf8mb4', 'user', 'password');
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
```
In the above example, the error mode isn't strictly necessary, **but it is advised to add it**. This way PDO will inform you of all MySQL errors by means of throwing the `PDOException`.
What is **mandatory**, however, is the first `setAttribute()` line, which tells PDO to disable emulated prepared statements and use *real* prepared statements. This makes sure the statement and the values aren't parsed by PHP before sending it to the MySQL server (giving a possible attacker no chance to inject malicious SQL).
Although you can set the | [
-0.014864617958664894,
-0.043751418590545654,
0.4857023358345032,
0.040018223226070404,
-0.04795312508940697,
-0.141190305352211,
0.3670382499694824,
-0.2275044471025467,
-0.04213099926710129,
-0.8311896920204163,
-0.3625180423259735,
0.41380074620246887,
-0.5249749422073364,
0.14849212765... | |
`charset` in the options of the constructor, it's important to note that 'older' versions of PHP (before 5.3.6) [silently ignored the charset parameter](http://php.net/manual/en/ref.pdo-mysql.connection.php) in the DSN.
#### Mysqli
For mysqli we have to follow the same routine:
```php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); // error reporting
$dbConnection = new mysqli('127.0.0.1', 'username', 'password', 'test');
$dbConnection->set_charset('utf8mb4'); // charset
```
---
Explanation
-----------
The SQL statement you pass to `prepare` is parsed and compiled by the database server. By specifying parameters (either a `?` or a named parameter like `:name` in the example above) you tell the database engine where you want to filter on. Then when you call `execute`, the prepared statement is combined with | [
0.16229304671287537,
0.02337571606040001,
0.48747196793556213,
-0.057789552956819534,
-0.11870517581701279,
-0.03077392280101776,
0.23443345725536346,
-0.40422213077545166,
0.020559079945087433,
-0.6201044917106628,
-0.11311367899179459,
0.4126911759376526,
-0.5386314392089844,
0.039257850... | |
the parameter values you specify.
The important thing here is that the parameter values are combined with the compiled statement, not an SQL string. SQL injection works by tricking the script into including malicious strings when it creates SQL to send to the database. So by sending the actual SQL separately from the parameters, you limit the risk of ending up with something you didn't intend.
Any parameters you send when using a prepared statement will just be treated as strings (although the database engine may do some optimization so parameters may end up as numbers too, of course). In the example | [
0.3123207986354828,
-0.00004458318653632887,
0.15224450826644897,
0.291148841381073,
-0.2638199031352997,
-0.05480843782424927,
0.4281098544597626,
-0.1621163934469223,
-0.26517385244369507,
-0.24509893357753754,
0.14068736135959625,
0.6608599424362183,
-0.5756303668022156,
-0.098724447190... | |
above, if the `$name` variable contains `'Sarah'; DELETE FROM employees` the result would simply be a search for the string `"'Sarah'; DELETE FROM employees"`, and you will not end up with [an empty table](http://xkcd.com/327/).
Another benefit of using prepared statements is that if you execute the same statement many times in the same session it will only be parsed and compiled once, giving you some speed gains.
Oh, and since you asked about how to do it for an insert, here's an example (using PDO):
```php
$preparedStatement = $db->prepare('INSERT INTO table (column) VALUES (:column)');
$preparedStatement->execute([ 'column' => $unsafeValue ]);
```
---
Can prepared statements be used for dynamic | [
-0.07067912817001343,
0.09905827790498734,
-0.11028005927801132,
-0.1796749383211136,
-0.26834678649902344,
0.03798302635550499,
0.3883439898490906,
-0.5211719870567322,
-0.2619657814502716,
-0.2945461869239807,
-0.1666923612356186,
0.5204818844795227,
-0.4160662293434143,
0.07788206636905... | |
queries?
----------------------------------------------------
While you can still use prepared statements for the query parameters, the structure of the dynamic query itself cannot be parametrized and certain query features cannot be parametrized.
For these specific scenarios, the best thing to do is use a whitelist filter that restricts the possible values.
```
// Value whitelist
// $dir can only be 'DESC', otherwise it will be 'ASC'
if (empty($dir) || $dir !== 'DESC') {
$dir = 'ASC';
}
``` | [
-0.2617974877357483,
0.14556066691875458,
0.3881619870662689,
0.27624884247779846,
-0.06509442627429962,
0.09768594801425934,
0.3504333198070526,
-0.1966560035943985,
-0.13857552409172058,
-0.4077892005443573,
-0.23668129742145538,
0.6453317403793335,
-0.4290415346622467,
0.277537733316421... | |
I was going to ask a question here about whether or not my design for some users/roles database tables was acceptable, but after some research I came across this question:
[What is the best way to handle multiple permission types?](/questions/1451/what-is-the-best-way-to-handle-multiple-permission-types)
It sounds like an innovative approach, so instead of a many-to-many relationship users\_to\_roles table, I have multiple permissions defined as a single decimal (int data type I presume). That means all permissions for a single user are in one row. It probably won't make sense until you read the other question and answer
I can't get my brain around this one. Can someone | [
-0.0010792877292260528,
-0.12864036858081818,
0.16464680433273315,
0.347703754901886,
0.030706942081451416,
0.2037939429283142,
-0.23064477741718292,
-0.404608815908432,
-0.3145144581794739,
-0.46863269805908203,
0.40538305044174194,
0.48451974987983704,
-0.14029794931411743,
0.08619746565... | |
please explain the conversion process? It sounds "right", but I'm just not getting how I convert the roles to a decimal before it goes in the db, and how it gets converted back when it comes out of the db. I'm using Java, but if you stubbed it out, that would be cool as well.
Here is the original answer in the off chance the other question gets deleted:
"Personally, I sometimes use a flagged enumeration of permissions. This way you can use AND, OR, NOT and XOR bitwise operations on the enumeration's items.
```
[Flags]
public enum Permission
{
VIEWUSERS = 1, | [
0.07530749589204788,
0.012094119563698769,
0.1066972017288208,
0.07887072116136551,
-0.07335802912712097,
0.04976973310112953,
0.045109935104846954,
-0.2372293770313263,
-0.037384189665317535,
-0.5892320871353149,
-0.12990863621234894,
0.6499367356300354,
-0.1360834240913391,
-0.1498058140... | |
// 2^0 // 0000 0001
EDITUSERS = 2, // 2^1 // 0000 0010
VIEWPRODUCTS = 4, // 2^2 // 0000 0100
EDITPRODUCTS = 8, // 2^3 // 0000 1000
VIEWCLIENTS = 16, // 2^4 // 0001 0000
EDITCLIENTS = 32, // 2^5 // 0010 0000
DELETECLIENTS = 64, // 2^6 // 0100 0000
}
```
Then, you can combine several permissions using the AND bitwise operator.
For example, if a user can view & edit users, the binary result of the operation is 0000 0011 | [
-0.0806189775466919,
0.042063210159540176,
0.4960784316062927,
-0.025456057861447334,
0.16851232945919037,
0.2030164748430252,
0.215379998087883,
-0.35857847332954407,
-0.2420135736465454,
-0.6183318495750427,
-0.3041732609272003,
0.6368436813354492,
-0.3125069737434387,
0.0096276300027966... | |
which converted to decimal is 3.
You can then store the permission of one user into a single column of your DataBase (in our case it would be 3).
Inside your application, you just need another bitwise operation (OR) to verify if a user has a particular permission or not."
You use bitwise operations. The pseudo-code would be something like:
```
bool HasPermission(User user, Permission permission) {
return (user.Permission & permission) != 0;
}
void SetPermission(User user, Permission permission) {
user.Permission |= permission;
}
void ClearPermission(User user, Permission permission) {
user.Permission &= ~permission;
}
```
Permission is the enum type defined in | [
0.10777360200881958,
0.3604545593261719,
0.4370196461677551,
0.039835117757320404,
0.14414091408252716,
0.17596136033535004,
-0.2936477065086365,
-0.37181830406188965,
-0.0754430964589119,
-0.2924901843070984,
-0.12739628553390503,
0.3243671953678131,
-0.04732831194996834,
0.02161070518195... | |
your post, though whatever type it is needs to be based on an integer-like type. The same applies to the User.Permission field.
If those operators (&, |=, and &=) don't make sense to you, then read up on bitwise operations (bitwise AND and bitwise OR). | [
0.1377115100622177,
-0.08148008584976196,
0.24367830157279968,
0.2481444627046585,
0.0191535335034132,
-0.17582149803638458,
0.2314969003200531,
0.16804127395153046,
0.206045463681221,
-0.5908002257347107,
-0.3207407295703888,
0.3373230993747711,
-0.48082780838012695,
0.016691716387867928,... | |
so, I'm running Apache on my laptop.
If I go to "localhost", I get the page that says,
> If you can see this, it means that the installation of the Apache web server software on this system was successful. You may now add content to this directory and replace this page.
except, I can't add content and replace that page.
I can click on its links, and that works fine.
First of all, there's not even an "index.html" document in that directory. If I try to directly access one that I created with localhost/index.html, I get "the request URL was not found on | [
0.5023044943809509,
0.2614217698574066,
0.392135888338089,
0.050704967230558395,
-0.08260204643011093,
-0.410045325756073,
0.5278079509735107,
0.3567447066307068,
-0.2954084873199463,
-0.7314989566802979,
0.14566010236740112,
0.49118369817733765,
-0.13574883341789246,
0.42002299427986145,
... | |
the server." So, I'm not even sure where that page is coming from. I've searched for words in that page under the apache directory, and nothing turns up. It seems to redirect somewhere.
Just as a test, I KNOW that it loads localhost/manual/index.html (doesn't matter what that is) so I tried to replace that with something I've written, and I received the message
> The server encountered an internal error or misconfiguration and was unable to complete your request.
The error log says,
> [Fri Sep 12 20:27:54 2008] [error] [client 127.0.0.1] Syntax error in type map, no ':' in C:/Program Files/Apache | [
0.02695971541106701,
0.23379498720169067,
0.4899393618106842,
0.09333720058202744,
-0.32490986585617065,
-0.21078430116176605,
0.8676927089691162,
-0.031219713389873505,
-0.25054025650024414,
-0.5362076759338379,
-0.36018818616867065,
0.36743634939193726,
-0.18007878959178925,
0.2974600195... | |
Group/Apache2/manual/index.html for header \r\n
But, that page works fine if I open directly with a browser.
so, basically, I don't know what I don't know here. I'm not sure what apache is looking for. I'm not sure if the error is in my config file, my html page, or what.
Oh, and the reason I want to open this using apache is (mainly) because I'm trying to test some php, so I'm trying to get apache to run locally.
Thanks.
"By default, your pages should be placed in the "C:\Program Files\Apache Group\Apache2\htdocs" folder for Apache 2.0 and the "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs" | [
0.27277374267578125,
0.3831069767475128,
0.41913115978240967,
-0.12802158296108246,
-0.5916862487792969,
-0.44288137555122375,
0.3289996385574341,
-0.2603740096092224,
-0.14087826013565063,
-0.5410944819450378,
-0.07060035318136215,
0.4411959648132324,
-0.20095954835414886,
-0.030565412715... | |
folder for Apache 2.2. When your site is ready, simply delete the existing files in the folder and replace them with those you want to test."
From [here](http://www.thesitewizard.com/apache/install-apache-2-windows.shtml). | [
0.5704542398452759,
-0.055341389030218124,
0.31246912479400635,
0.03773171454668045,
-0.090827576816082,
-0.8080160617828369,
0.24418295919895172,
0.012821938842535019,
-0.03859151154756546,
-0.4245310127735138,
-0.49634620547294617,
0.505194365978241,
-0.3953607976436615,
-0.2047436535358... | |
I have always wondered how people update a previous line in a command line. a great example of this is when using the wget command in linux. It creates an ASCII loading bar of sorts that looks like this:
> [======> ] 37%
and of course the loading bar moves and the percent changes, But it doesn't make a new line. I cannot figure out how to do this. Can someone point me in the right direction?
There are two ways I know of to do this:
* Use the backspace escape character ('\b') to erase your line
* Use the `curses` package, if your programming | [
0.4130004048347473,
0.036469049751758575,
0.06920599192380905,
-0.0931776911020279,
0.003687160322442651,
0.0820329561829567,
0.4601425528526306,
0.08560991287231445,
-0.09710835665464401,
-0.8097251653671265,
0.007420762442052364,
0.5652092099189758,
-0.26600608229637146,
0.26821351051330... | |
language of choice has bindings for it.
And a Google revealed [ANSI Escape Codes](http://en.wikipedia.org/wiki/ANSI_escape_code), which appear to be a good way. For reference, here is a function in C++ to do this:
```
void DrawProgressBar(int len, double percent) {
cout << "\x1B[2K"; // Erase the entire current line.
cout << "\x1B[0E"; // Move to the beginning of the current line.
string progress;
for (int i = 0; i < len; ++i) {
if (i < static_cast<int>(len * percent)) {
progress += "=";
} else { | [
-0.3732272982597351,
-0.1882503479719162,
0.3142978250980377,
-0.2103899121284485,
-0.18485766649246216,
0.30257007479667664,
0.19694429636001587,
-0.11839968711137772,
-0.09810575097799301,
-0.6872363686561584,
-0.3111856281757355,
0.14542840421199799,
-0.45632392168045044,
-0.04762472584... | |
progress += " ";
}
}
cout << "[" << progress << "] " << (static_cast<int>(100 * percent)) << "%";
flush(cout); // Required.
}
``` | [
-0.05874522775411606,
-0.015529723837971687,
0.4695259630680084,
-0.4089396893978119,
0.2299494743347168,
0.24115462601184845,
0.17756453156471252,
-0.3815350830554962,
0.1307257115840912,
-0.7578314542770386,
-0.1973433643579483,
0.4010566473007202,
-0.23012857139110565,
-0.04043767601251... | |
Every sample that I have seen uses static XML in the xmldataprovider source, which is then used to databind UI controls using XPath binding.
Idea is to edit a dynamic XML (structure known to the developer during coding), using the WPF UI.
Has anyone found a way to load a dynamic xml string (for example load it from a file during runtime), then use that xml string as the XmlDataprovider source?
Code snippets would be great.
Update: To make it more clear,
Let's say I want to load an xml string I received from a web service call. I know the structure of | [
0.6616354584693909,
-0.1376822143793106,
0.3660806119441986,
0.18128550052642822,
-0.2069295197725296,
-0.07828567922115326,
-0.16020645201206207,
-0.23464351892471313,
0.09246433526277542,
-0.6740995645523071,
0.17092575132846832,
0.33234503865242004,
-0.2708776891231537,
0.15305806696414... | |
the xml. So I databind it to WPF UI controls on the WPF Window. How to make this work? All the samples over the web, define the whole XML inside the XAML code in the XmlDataProvider node. This is not what I am looking for. I want to use a xml string in the codebehind to be databound to the UI controls.
Here is some code I used to load a XML file from disk and bind it to a TreeView. I removed some of the normal tests for conciseness. The XML in the example is an OPML file.
```
XmlDataProvider provider = | [
0.25886815786361694,
0.15286900103092194,
0.5486329793930054,
0.09757751226425171,
-0.1379142701625824,
-0.37999120354652405,
-0.19964860379695892,
-0.255872905254364,
-0.17792074382305145,
-0.7202436923980713,
-0.09831194579601288,
0.4574635326862335,
-0.4559444785118103,
0.13913719356060... | |
new XmlDataProvider();
if (provider != null)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(fileName);
provider.Document = doc;
provider.XPath = "/opml/body/outline";
FeedListTreeView.DataContext = provider;
}
``` | [
0.24141108989715576,
-0.28017109632492065,
0.9325346946716309,
-0.2576208710670471,
0.2367517501115799,
0.07967615872621536,
-0.035864733159542084,
-0.3835573196411133,
-0.3172166347503662,
-0.9249565005302429,
-0.43229442834854126,
0.40364551544189453,
-0.3978147804737091,
0.2419877201318... | |
I've been working through [Practical Common Lisp](http://gigamonkeys.com/book) and as an exercise decided to write a macro to determine if a number is a multiple of another number:
`(defmacro multp (value factor)
`(= (rem ,value ,factor) 0))`
so that :
`(multp 40 10)`
evaluates to true whilst
`(multp 40 13)`
does not
The question is does this macro [leak](http://gigamonkeys.com/book/macros-defining-your-own.html#plugging-the-leaks) in some way? Also is this "good" Lisp? Is there already an existing function/macro that I could have used?
Siebel gives an extensive rundown (for simple cases anyway) of possible sources of leaks, and there aren't any of those here. Both `value` and `factor` are evaluated only | [
0.33018195629119873,
0.15467189252376556,
0.3029678463935852,
-0.14104054868221283,
0.06451521813869476,
-0.28098949790000916,
0.4641066789627075,
-0.3222787082195282,
-0.19875937700271606,
-0.2005307972431183,
0.21216340363025665,
0.7218902111053467,
-0.31306692957878113,
-0.1332658082246... | |
once and in order, and `rem` doesn't have any side effects.
This is not good Lisp though, because there's no reason to use a macro in this case. A function
```
(defun multp (value factor)
(zerop (rem value factor)))
```
is identical for all practical purposes. (Note the use of `zerop`. I think it makes things clearer in this case, but in cases where you need to highlight, that the value you're testing might still be meaningful if it's something other then zero, `(= ... 0)` might be better) | [
-0.10545695573091507,
0.06258934736251831,
0.30253955721855164,
-0.5157386064529419,
-0.08270767331123352,
-0.2853042483329773,
0.2873859107494354,
-0.1812712550163269,
-0.1055048331618309,
-0.5644099116325378,
-0.32406824827194214,
0.6824781894683838,
-0.33628860116004944,
-0.159190639853... | |
Is there a way to change the appearance of an icon (ie. contrast / luminosity) when I hover the cursor, without requiring a second image file (or without requiring a hidden portion of the image)?
[Here's some good information about image opacity and transparency with CSS](http://www.w3schools.com/css/css_image_transparency.asp).
So to make an image with opacity 50%, you'd do this:
```
<img src="image.png" style="opacity: 0.5; filter: alpha(opacity=50)" />
```
The **opacity:** part is how Firefox does it, and it's a value between 0.0 and 1.0. **filter:** is how IE does it, and it's a value from 0 to 100. | [
-0.19666330516338348,
-0.05374521389603615,
0.694279134273529,
-0.18090702593326569,
-0.26867231726646423,
0.06636857241392136,
0.03385794162750244,
-0.38886672258377075,
-0.13556507229804993,
-0.7646849751472473,
0.053284045308828354,
0.6657692790031433,
-0.25144240260124207,
-0.376283764... | |
I have a little problem with a Listview.
I can load it with listview items fine, but when I set the background color it doesn't draw the color all the way to the left side of the row [The listViewItems are loaded with ListViewSubItems to make a grid view, only the first column shows the error]. There is a a narrow strip that doesn't paint. The width of that strip is approximately the same as a row header would be if I had a row header.
If you have a thought on what can be done to make the background draw | [
0.529361367225647,
-0.1837930977344513,
0.22880882024765015,
-0.03871887922286987,
-0.12892845273017883,
0.042302779853343964,
0.33006468415260315,
0.17102433741092682,
-0.22784222662448883,
-0.7130300402641296,
0.41535380482673645,
0.8130862712860107,
-0.37010520696640015,
-0.052658818662... | |
I'd love to hear it.
Now just to try a new idea, I'm offering a ten vote bounty for the first solution that still has me using this awful construct of a mess of a pseudo grid view. [I love legacy code.]
**Edit:**
Here is a sample that exhibits the problem.
```
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ListView lv = new ListView();
lv.Dock = System.Windows.Forms.DockStyle.Fill; | [
0.5000250339508057,
-0.10997659713029861,
0.7235148549079895,
-0.3478822112083435,
0.23304755985736847,
-0.0453965999186039,
0.21437494456768036,
-0.16850431263446808,
-0.3532755970954895,
-0.7732453346252441,
-0.2315741926431656,
0.7551783919334412,
-0.19510769844055176,
0.088073804974555... | |
lv.FullRowSelect = true;
lv.GridLines = true;
lv.HideSelection = false;
lv.Location = new System.Drawing.Point(0, 0);
lv.TabIndex = 0;
lv.View = System.Windows.Forms.View.Details;
lv.AllowColumnReorder = true;
this.Controls.Add(lv);
lv.MultiSelect = true;
ColumnHeader ch = new ColumnHeader(); | [
-0.18050605058670044,
-0.40031635761260986,
1.1649492979049683,
-0.34930941462516785,
0.08698586374521255,
0.17002657055854797,
0.10086380690336227,
-0.44519898295402527,
-0.26239335536956787,
-0.6635715365409851,
-0.43634480237960815,
0.21858352422714233,
-0.5179486870765686,
-0.115725569... | |
ch.Name = "Foo";
ch.Text = "Foo";
ch.Width = 40;
ch.TextAlign = HorizontalAlignment.Left;
lv.Columns.Add(ch);
ColumnHeader ch2 = new ColumnHeader();
ch.Name = "Bar";
ch.Text = "Bar";
ch.Width = 40;
ch.TextAlign = HorizontalAlignment.Left; | [
-0.27106043696403503,
0.4164811372756958,
0.9092354774475098,
-0.6077438592910767,
-0.14218322932720184,
0.43483754992485046,
0.18813569843769073,
-0.014335333369672298,
-0.1438090205192566,
-0.12404227256774902,
-0.733462929725647,
0.3270220160484314,
-0.3683541715145111,
-0.0645634382963... | |
lv.Columns.Add(ch2);
lv.BeginUpdate();
for (int i = 0; i < 3; i++)
{
ListViewItem lvi = new ListViewItem("1", "2");
lvi.BackColor = Color.Black;
lvi.ForeColor = Color.White;
lv.Items.Add(lvi);
} | [
0.16769152879714966,
-0.3387417495250702,
0.9769347310066223,
-0.6640737652778625,
0.025676222518086433,
0.5904505252838135,
0.2000712752342224,
-0.41315600275993347,
-0.38545462489128113,
-0.5477129220962524,
-0.31850680708885193,
0.22456488013267517,
-0.5784317255020142,
0.14016294479370... | |
lv.EndUpdate();
}
}
```
Ah! I see now :}
You want hacky? I present unto you the following:
```
...
lv.OwnerDraw = true;
lv.DrawItem += new DrawListViewItemEventHandler( lv_DrawItem );
...
void lv_DrawItem( object sender, DrawListViewItemEventArgs e )
{
Rectangle foo = e.Bounds;
foo.Offset( -10, 0 );
e.Graphics.FillRectangle( new SolidBrush( e.Item.BackColor ), foo );
e.DrawDefault = true;
}
```
For a more inventive - and no less hacky - approach, you could try utilising the background image | [
0.18050996959209442,
-0.3131248950958252,
0.9068747758865356,
-0.2930130958557129,
-0.006957371719181538,
0.3280552923679352,
-0.012746944092214108,
-0.4087793827056885,
-0.08010324090719223,
-0.5821332335472107,
-0.16259357333183289,
0.6202568411827087,
-0.46181368827819824,
-0.1728393435... | |
of the ListView ;) | [
0.13089272379875183,
0.002531761769205332,
0.2531358003616333,
-0.06205545738339424,
-0.0014398220228031278,
0.02482074312865734,
0.3797079622745514,
-0.07548173516988754,
-0.0897803008556366,
-0.5209727883338928,
-0.4749395251274109,
0.8221685886383057,
-0.11876431107521057,
0.15838733315... | |
If I start a process via Java's [ProcessBuilder](http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html) class, I have full access to that process's standard in, standard out, and standard error streams as Java `InputStreams` and `OutputStreams`. However, I can't find a way to seamlessly connect those streams to `System.in`, `System.out`, and `System.err`.
It's possible to use `redirectErrorStream()` to get a single `InputStream` that contains the subprocess's standard out and standard error, and just loop through that and send it through my standard out—but I can't find a way to do that and let the user type into the process, as he or she could if I used the | [
0.16114522516727448,
0.20344671607017517,
0.2739507555961609,
-0.22976301610469818,
0.03176836669445038,
0.30314743518829346,
0.20375491678714752,
-0.26865798234939575,
-0.2197873592376709,
-0.8072623014450073,
-0.06292128562927246,
0.3177073001861572,
-0.062017772346735,
0.384414941072464... | |
C `system()` call.
This appears to be possible in Java SE 7 when it comes out—I'm just wondering if there's a workaround now. Bonus points if the result of [`isatty()`](http://www.opengroup.org/onlinepubs/009695399/functions/isatty.html) in the child process carries through the redirection.
You will need to copy the [Process](http://java.sun.com/javase/6/docs/api/java/lang/Process.html) out, err, and input streams to the System versions. The easiest way to do that is using the [IOUtils](http://commons.apache.org/io/api-release/org/apache/commons/io/IOUtils.html) class from the Commons IO package. The [copy method](http://commons.apache.org/io/api-release/org/apache/commons/io/IOUtils.html#copy%28java.io.InputStream,%20java.io.OutputStream%29) looks to be what you need. The copy method invocations will need to be in separate threads.
Here is the basic code:
```
// Assume you already have a processBuilder all | [
0.20160934329032898,
0.016119690611958504,
0.5938324928283691,
-0.16054406762123108,
0.3804547190666199,
0.13972420990467072,
-0.007219685707241297,
-0.27909132838249207,
-0.14453759789466858,
-0.5209107995033264,
-0.3406605124473572,
0.5283178091049194,
-0.20013919472694397,
0.16462597250... | |
configured and ready to go
final Process process = processBuilder.start();
new Thread(new Runnable() {public void run() {
IOUtils.copy(process.getOutputStream(), System.out);
} } ).start();
new Thread(new Runnable() {public void run() {
IOUtils.copy(process.getErrorStream(), System.err);
} } ).start();
new Thread(new Runnable() {public void run() {
IOUtils.copy(System.in, process.getInputStream());
} } ).start();
``` | [
0.22637993097305298,
-0.4604487717151642,
0.8167839050292969,
0.007449793163686991,
0.46005576848983765,
0.2673691213130951,
0.031282395124435425,
0.005480071529746056,
-0.28117015957832336,
-0.7922501564025879,
-0.5319951772689819,
0.5018011927604675,
-0.2796061933040619,
0.40526470541954... | |
If all of my `__init__.py` files are empty, do I have to store them into version control, or is there a way to make `distutils` create empty `__init__.py` files during installation?
Is there a reason you want to *avoid* putting empty `__init__.py` files in version control? If you do this you won't be able to `import` your packages from the source directory wihout first running distutils.
If you really want to, I suppose you can create `__init__.py` in `setup.py`. It has to be *before* running `distutils.setup`, so `setup` itself is able to find your packages:
```
from distutils import setup
import os
for path in [my_package_directories]: | [
0.43020275235176086,
0.11934932321310043,
0.284579336643219,
-0.11191409826278687,
0.3171619772911072,
-0.2307104766368866,
0.2414780855178833,
-0.06300017237663269,
-0.3739149272441864,
-0.8546899557113647,
-0.23229752480983734,
0.7502155303955078,
-0.29640236496925354,
0.1561583280563354... | |
filename = os.path.join(pagh, '__init__.py')
if not os.path.exists(filename):
init = open(filename, 'w')
init.close()
setup(
...
)
```
but... what would you gain from this, compared to having the empty `__init__.py` files there in the first place? | [
0.11994349211454391,
-0.05495180934667587,
0.33199360966682434,
-0.08238958567380905,
0.2948260009288788,
-0.1212920993566513,
0.24593307077884674,
-0.11921663582324982,
-0.20038363337516785,
-0.6880210041999817,
-0.2200959473848343,
0.47563058137893677,
-0.17073294520378113,
0.15330411493... | |
What experience can you share about using multiple AJAX libraries?
There are useful features in Prototype, some in jQuery, the Yahoo library, etc. Is it possible to include all libraries and use what you want from each, do they generally all play nicely together with name spaces, etc. For the sake of speed is there a practical limit to the size/number of libraries to include or is this negligible? Are there pairs that work particularly well together (e.g. Prototype/Scriptaculous) or pairs that don't?
You could use all those libraries, but I highly recommend against it. Downloading and executing that much JavaScript will | [
0.4566824436187744,
-0.015464975498616695,
-0.23097991943359375,
0.4112987220287323,
-0.282703161239624,
-0.20031216740608215,
0.01632186770439148,
-0.00011237557191634551,
-0.23955892026424408,
-0.9104965925216675,
0.26939719915390015,
0.5693928599357605,
-0.21512477099895477,
-0.31696581... | |
most likely choke the browser and slow down your user's experience. It would be much better from a user's perspective and a developer's to pick one. Less context/architecture switching and less code to maintain.
Like other answers have said, most don't conflict.
See Yahoo!'s [Exceptional Performance](http://developer.yahoo.com/performance/) site for more info. | [
-0.036339472979307175,
0.103777676820755,
0.02549811825156212,
0.3267436921596527,
-0.1195683628320694,
0.09753770381212234,
0.3884134590625763,
0.14208917319774628,
0.1411900371313095,
-0.5595372915267944,
-0.18094025552272797,
0.3758947253227234,
-0.01885494589805603,
-0.0018568056402727... | |
I'm writing a pretty straightforward `e-commerce app` in **asp.net**, do I need to use transactions in my stored procedures?
Read/Write ratio is about 9:1
Many people ask - do I need transactions? Why do I need them? When to use them?
The answer is simple: use them all the time, unless you have a very good reason not to (for instance, don't use atomic transactions for "long running activities" between businesses). The default should always be yes. You are in doubt? - use transactions.
Why are transactions beneficial? They help you deal with crashes, failures, data consistency, error handling, they help you write simpler | [
0.2022048830986023,
0.3423841893672943,
0.3683088421821594,
0.23306603729724884,
0.16638483107089996,
-0.004262859467417002,
0.16473013162612915,
0.03978666290640831,
-0.3124851584434509,
-0.609812319278717,
-0.0678781196475029,
0.6218463778495789,
-0.31464576721191406,
-0.4004096090793609... | |
code etc. And the list of benefits will continue to grow with time.
Here is some more info from <http://blogs.msdn.com/florinlazar/> | [
0.4712235927581787,
-0.17303922772407532,
0.3088319003582001,
0.3865325152873993,
0.21627101302146912,
-0.14216609299182892,
0.12688490748405457,
0.14684917032718658,
-0.3261181712150574,
-0.27481532096862793,
-0.26830148696899414,
0.4681989252567291,
-0.022069156169891357,
0.1727901697158... | |
As part of a JavaScript Profiler for IE 6/7 I needed to load a custom debugger that I created into IE. I got this working fine on XP, but couldn't get it working on Vista (full story here: <http://damianblog.com/2008/09/09/tracejs-v2-rip/>).
The call to GetProviderProcessData is failing on Vista. Anyone have any suggestions?
Thanks,
Damian
```
// Create the MsProgramProvider
IDebugProgramProvider2* pIDebugProgramProvider2 = 0;
HRESULT st = CoCreateInstance(CLSID_MsProgramProvider, 0, CLSCTX_ALL, IID_IDebugProgramProvider2, (void**)&pIDebugProgramProvider2);
if(st != S_OK) {
return st;
}
// Get the IDebugProgramNode2 instances running in this process
AD_PROCESS_ID processID;
processID.ProcessId.dwProcessId = GetCurrentProcessId();
processID.ProcessIdType = AD_PROCESS_ID_SYSTEM;
CONST_GUID_ARRAY engineFilter;
engineFilter.dwCount = 0;
PROVIDER_PROCESS_DATA processData;
st = pIDebugProgramProvider2->GetProviderProcessData(PFLAG_GET_PROGRAM_NODES|PFLAG_DEBUGGEE, 0, processID, engineFilter, &processData);
if(st != S_OK) { | [
-0.20795473456382751,
0.21547266840934753,
0.8239588737487793,
-0.02752898819744587,
-0.19136156141757965,
0.13111458718776703,
0.5870680809020996,
-0.4527234435081482,
-0.22072704136371613,
-0.6540696620941162,
-0.234964057803154,
0.5972989201545715,
-0.5625371932983398,
0.334237515926361... | |
ShowError(L"GPPD Failed", st);
pIDebugProgramProvider2->Release();
return st;
}
```
It would help to know what the error result was.
Possible problems I can think of:
If your getting permission denied, your most likely missing some requried [Privilege](http://msdn.microsoft.com/en-us/library/aa375728(VS.85).aspx) in your ACL. New ones are sometimes not doceumented well, check the latest Platform SDK headers to see if any new ones that still out. It may be that under vista the Privilege is not assigned my default to your ACL any longer.
If your getting some sort of Not Found type error, then it may be 32bit / 64bit problem. Your debbugging | [
0.6076547503471375,
0.2182096540927887,
0.3166942894458771,
0.1295144110918045,
-0.06979838758707047,
-0.15505023300647736,
0.45927441120147705,
-0.23917965590953827,
0.006242414470762014,
-0.4276069402694702,
0.04043680429458618,
0.6528285145759583,
-0.18245720863342285,
0.283647775650024... | |
API may only be available under 64bit COM on vista 64. The 32bit/64bit interoperation can be very confusing. | [
0.1584995836019516,
-0.03548909351229668,
0.24979929625988007,
0.15872302651405334,
0.3001866638660431,
0.0223669596016407,
0.1280057579278946,
0.13312368094921112,
0.005064233671873808,
-0.5940518379211426,
-0.011413520202040672,
0.7099334001541138,
-0.3077246844768524,
0.0951726883649826... | |
From my experience with [OpenID](http://en.wikipedia.org/wiki/OpenID), I see a number of significant downsides:
**Adds a [Single Point of Failure](http://en.wikipedia.org/wiki/Single_Point_of_Failure) to the site**
It is not a failure that can be fixed by the site even if detected. If the OpenID provider is down for three days, what recourse does the site have to allow its users to login and access the information they own?
**Takes a user to another sites content and every time they logon to your site**
Even if the OpenID provider does not have an error, the user is re-directed to their site to login. The login page | [
0.20207901298999786,
0.15587010979652405,
0.5195364356040955,
-0.019132550805807114,
0.07751299440860748,
-0.36932572722435,
0.6105408072471619,
0.15557371079921722,
-0.26234567165374756,
-0.7988247871398926,
-0.5630302429199219,
0.3853604197502136,
-0.06545288115739822,
0.4473489224910736... | |
has content and links. So there is a chance a user will actually be drawn away from the site to go down the Internet rabbit hole.
Why would I want to send my users to another company's website?
**Adds a non-trivial amount of time to the signup**
To sign up with the site a new user is forced to read a new standard, chose a provider, and signup. Standards are something that the technical people should agree to in order to make a user experience frictionless. They are not something that should be thrust on the users.
**It is a | [
0.8545128703117371,
0.1636136919260025,
0.556084930896759,
0.2958933413028717,
-0.0017221472226083279,
-0.5357931852340698,
0.13049453496932983,
0.16570793092250824,
-0.23606152832508087,
-0.534113347530365,
-0.03301427140831947,
0.21955017745494843,
0.21857720613479614,
0.0429613217711448... | |
Phisher's Dream**
OpenID is incredibly insecure and stealing the person's ID as they log in is trivially easy. [ taken from David Arno's [Answer](https://stackoverflow.com/questions/60436/what-is-the-benefit-of-using-only-openid-authentication-on-a-site#173467) below ]
---
For all of the downside, the one upside is to allow users to have fewer logins on the Internet. If a site has opt-in for OpenID then users who want that feature can use it.
**What I would like to understand is:**
What benefit does a site get for making OpenID **mandatory**?
The list of downsides misses the most obvious one: it is a phisher's dream. OpenID is incredibly insecure and stealing the person's ID | [
0.43161752820014954,
0.021279528737068176,
-0.026224441826343536,
0.21340180933475494,
0.1454233080148697,
-0.2603127658367157,
0.4660942554473877,
0.2494940608739853,
0.1076069176197052,
-0.586436927318573,
-0.23644042015075684,
0.2391679286956787,
-0.5208109021186829,
-0.1414987295866012... | |
as they log in is trivially easy.
Matt Sheppard hits the nail on the head as to the answer though:the benefit of only using OpenID is that it involves less hassle for the site creator as there are no usernames and passwords to handle and no user account creation code required. | [
0.2536517083644867,
0.04429185017943382,
0.08661414682865143,
0.169784814119339,
0.008092381060123444,
-0.04719573259353638,
0.5972656607627869,
0.11098421365022659,
-0.11911433190107346,
-0.8775738477706909,
-0.3351016640663147,
0.4279106557369232,
-0.16619181632995605,
-0.005521863698959... | |
I am using jQuery. I call a JavaScript function with next html:
```
<li><span><a href="javascript:uncheckEl('tagVO-$id')">$tagname</a></span></li>
```
I would like to remove the `li` element and I thought this would be easy with the `$(this)` object. This is my JavaScript function:
```
function uncheckEl(id) {
$("#"+id+"").attr("checked","");
$("#"+id+"").parent("li").css("color","black");
$(this).parent("li").remove(); // This is not working
retrieveItems();
}
```
But `$(this)` is undefined. Any ideas?
Try something like this (e.g. to hide the `<li>`):
```
function unCheckEl(id, ref) {
(...)
$(ref).parent().parent().hide(); // this should | [
0.20229965448379517,
0.07355112582445145,
0.42017510533332825,
-0.2599789500236511,
-0.023558510467410088,
-0.17754718661308289,
0.32838791608810425,
-0.3544403314590454,
-0.11226920783519745,
-0.7072845101356506,
-0.25088611245155334,
0.48460328578948975,
-0.4431420862674713,
0.1135731711... | |
be your <li>
}
```
And your link:
```
<a href="javascript:uncheckEl('tagVO-$id', \$(this))">
```
`$(this)` is not present inside your function, because how is it supposed to know where the action is called from? You pass no reference in it, so `$(this)` could refer to everything but the `<a>`. | [
0.13576093316078186,
-0.12681719660758972,
0.4111345112323761,
-0.22944167256355286,
0.044326383620500565,
-0.2058844417333603,
0.34089136123657227,
-0.1881927251815796,
0.13122935593128204,
-0.4531630575656891,
-0.45042893290519714,
0.6030338406562805,
-0.5022469162940979,
-0.215088605880... | |
Is it possible to to take a screenshot of a webpage with JavaScript and then submit that back to the server?
I'm not so concerned with browser security issues. etc. as the implementation would be for [HTA](http://msdn.microsoft.com/en-us/library/ms536471(vs.85).aspx). But is it possible?
I have done this for an HTA by using an ActiveX control. It was pretty easy to build the control in VB6 to take the screenshot. I had to use the keybd\_event API call because SendKeys can't do PrintScreen. Here's the code for that:
```
Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal | [
-0.19544965028762817,
0.02637183666229248,
0.3233821392059326,
-0.1734694242477417,
-0.13885723054409027,
-0.12544716894626617,
0.11271028965711594,
-0.020059874281287193,
-0.28522998094558716,
-0.7135295271873474,
-0.10109779238700867,
0.4695855379104614,
-0.2608085870742798,
-0.114771910... | |
dwExtraInfo As Long)
Public Const CaptWindow = 2
Public Sub ScreenGrab()
keybd_event &H12, 0, 0, 0
keybd_event &H2C, CaptWindow, 0, 0
keybd_event &H2C, CaptWindow, &H2, 0
keybd_event &H12, 0, &H2, 0
End Sub
```
That only gets you as far as getting the window to the clipboard.
Another option, if the window you want a screenshot of is an HTA would be to just use an XMLHTTPRequest to send the DOM nodes to the server, then create the screenshots server-side. | [
0.04693366214632988,
-0.4749339520931244,
0.5774583220481873,
-0.06801241636276245,
-0.07960612326860428,
-0.0038008533883839846,
0.21602749824523926,
-0.16124872863292694,
-0.05385865643620491,
-0.9350150227546692,
-0.20033490657806396,
0.46684151887893677,
-0.23109184205532074,
0.2755971... | |
I had an idea I was mulling over with some colleagues. None of us knew whether or not it exists currently.
The Basic Premise is to have a system that has 100% uptime but can become more efficient dynamically.
> **Here is the scenario:**
>
> \* So we hash out a system quickly to a
> specified set of interfaces, it has
> zero optimizations, yet we are
> confident that it is 100% stable
> though *(dubious, but for the sake of
> this scenario please play
> along)*
> | [
-0.03299294039607048,
0.015433098189532757,
0.4909501373767853,
0.16379773616790771,
0.31727370619773865,
0.0476037934422493,
0.07667603343725204,
0.04048960655927658,
-0.08601495623588562,
-0.7635399699211121,
0.20735520124435425,
0.4733782708644867,
-0.2968789041042328,
-0.00737610273063... | |
> \* We then profile
> the original classes, and start to
> program replacements for the
> bottlenecks.
>
>
> \* The original and the replacement are initiated simultaneously and
> synchronized.
>
>
> \* An original is allowed to run to completion: if a replacement hasn´t
> completed it is vetoed by the system
> as a replacement for the
> original.
>
>
> \* A replacement must always return the same value as the original, for a
> specified number | [
0.35644665360450745,
-0.17362309992313385,
0.25813499093055725,
0.15727929770946503,
0.11049921065568924,
-0.007087290287017822,
0.39512521028518677,
-0.2919309735298157,
-0.27233123779296875,
-0.5219607949256897,
-0.4907712936401367,
0.5407937169075012,
-0.26386404037475586,
0.23054412007... | |
of times, and for a
> specific range of values, before it is
> adopted as a replacement for the
> original.
>
>
> \* If exception occurs after a replacement is adopted, the system
> automatically tries the same operation
> with a class which was superseded by
> it.
**Have you seen a similar concept in practise?** *Critique Please ...*
> **Below are comments written after the initial question in regards to
> posts:**
>
>
> \* The system demonstrates a Darwinian approach to system evolution.
> | [
0.19338014721870422,
0.03194285184144974,
-0.1683281809091568,
-0.010706583969295025,
-0.011591317132115364,
0.10191097110509872,
0.36726629734039307,
0.056124720722436905,
-0.004812086001038551,
-0.7792564630508423,
-0.075060173869133,
0.3630739450454712,
-0.4444819688796997,
0.2982293665... | |
>
> \* The original and replacement would run in parallel not in series.
>
>
> \* Race-conditions are an inherent issue to multi-threaded apps and I
> acknowledge them.
I believe this idea to be an interesting theoretical debate, but not very practical for the following reasons:
1. To make sure the new version of the code works well, you need to have superb automatic tests, which is a goal that is very hard to achieve and one that many companies fail to develop. You can only go on with implementing the system | [
0.5568453669548035,
0.34458792209625244,
0.22216081619262695,
0.08332084119319916,
0.24257831275463104,
-0.19118934869766235,
0.4462602436542511,
-0.059603940695524216,
-0.023888198658823967,
-0.8208372592926025,
-0.10320968925952911,
0.7085955739021301,
-0.3891099691390991,
-0.23483106493... | |
after such automatic tests are in place.
2. The whole point of this system is performance tuning, that is - a specific version of the code is replaced by a version that supersedes it in performance. For most applications today, performance is of minor importance. Meaning, the overall performance of most applications is adequate - just think about it, you probably rarely find yourself complaining that "this application is excruciatingly slow", instead you usually find yourself complaining on the lack of specific feature, stability issues, UI issues etc. Even when you do complain about slowness, it's usually an overall slowness of | [
-0.06310578435659409,
0.10032970458269119,
0.2122996747493744,
0.32407137751579285,
0.02295384369790554,
-0.2903861105442047,
0.5045019388198853,
0.0069671617820858955,
-0.12159351259469986,
-0.6911602020263672,
-0.3114592432975769,
0.6161255240440369,
-0.24662739038467407,
-0.029414542019... | |
your system and not just a specific applications (there are exceptions, of course).
3. For applications or modules where performance is a big issue, the way to improve them is usually to identify the bottlenecks, write a new version and test is independently of the system first, using some kind of benchmarking. Benchmarking the new version of the entire application might also be necessary of course, but in general I think this process would only take place a very small number of times (following the 20%-80% rule). Doing this process "manually" in these cases is probably easier and more cost-effective than | [
0.33997872471809387,
0.10022696852684021,
0.2714296877384186,
0.2953431010246277,
0.19706125557422638,
-0.18236854672431946,
0.46363598108291626,
-0.2563864588737488,
-0.10148747265338898,
-0.6447385549545288,
-0.028663303703069687,
0.7404202222824097,
-0.009578671306371689,
-0.40034273266... | |
the described system.
4. What happens when you add features, fix non-performance related bugs etc.? You don't get any benefit from the system.
5. Running the two versions in conjunction to compare their performance has far more problems than you might think - not only you might have race conditions, but if the input is not an appropriate benchmark, you might get the wrong result (e.g. if you get loads of small data packets and that is in 90% of the time the input is large data packets). Furthermore, it might just be impossible (for example, if the actual code changes the | [
0.234727680683136,
0.0062276148237288,
0.3730297386646271,
0.4812638759613037,
0.06623334437608719,
-0.103671133518219,
0.27697834372520447,
-0.22646619379520416,
-0.23017734289169312,
-0.5733241438865662,
-0.07573865354061127,
0.5455212593078613,
-0.17626361548900604,
0.06574370712041855,... | |
data, you can't run them in conjunction).
The only "environment" where this sounds useful and actually "a must" is a "genetic" system that generates new versions of the code by itself, but that's a whole different story and not really widely applicable... | [
0.5565176010131836,
0.0011426550336182117,
-0.05021606385707855,
0.6402313709259033,
0.2470337599515915,
-0.3022945821285248,
0.2541045546531677,
-0.18378297984600067,
-0.13091157376766205,
-0.08552327007055283,
-0.12230031192302704,
0.25817373394966125,
-0.3695630133152008,
0.159957945346... | |
Say I have:
```
void Render(void(*Call)())
{
D3dDevice->BeginScene();
Call();
D3dDevice->EndScene();
D3dDevice->Present(0,0,0,0);
}
```
This is fine as long as the function I want to use to render is a function or a `static` member function:
```
Render(MainMenuRender);
Render(MainMenu::Render);
```
However, I really want to be able to use a class method as well since in most cases the rendering function will want to access member variables, and Id rather not make the class instance global, e.g.
```
Render(MainMenu->Render);
```
However I really have no idea how to do this, and still allow functions and `static` member functions to be used.
There are a lot | [
-0.051228117197752,
0.23047763109207153,
0.7384635806083679,
-0.2689518928527832,
-0.15204188227653503,
0.012936878949403763,
0.20028093457221985,
-0.10501065105199814,
-0.04213009029626846,
-0.6305713057518005,
-0.24038396775722504,
0.6922730207443237,
-0.2527695596218109,
0.4313504397869... | |
of ways to skin this cat, including templates. My favorite is [Boost.function](http://www.boost.org/doc/libs/1_36_0/doc/html/function.html) as I've found it to be the most flexible in the long run. Also read up on [Boost.bind](http://www.boost.org/doc/libs/1_36_0/libs/bind/bind.html) for binding to member functions as well as many other tricks.
It would look like this:
```
#include <boost/bind.hpp>
#include <boost/function.hpp>
void Render(boost::function0<void> Call)
{
// as before...
}
Render(boost::bind(&MainMenu::Render, myMainMenuInstance));
``` | [
-0.09439757466316223,
-0.06464315950870514,
0.5141134858131409,
-0.5322611927986145,
-0.27377599477767944,
0.1805226355791092,
0.1715635359287262,
-0.23191383481025696,
0.03209434077143669,
-0.9092907309532166,
0.10424574464559555,
0.8273322582244873,
-0.5467222929000854,
-0.23982071876525... | |
From [this post](https://stackoverflow.com/questions/60419/do-i-really-need-to-use-transactions-in-stored-procedures-mssql-2005). One obvious problem is scalability/performance. What are the other problems that transactions use will provoke?
Could you say there are two sets of problems, one for long running transactions and one for short running ones? If yes, how would you define them?
EDIT: Deadlock is another problem, but data inconsistency might be worse, depending on the application domain. Assuming a transaction-worthy domain (banking, to use the canonical example), deadlock possibility is more like a cost to pay for ensuring data consistency, rather than a problem with transactions use, or you would disagree? If so, what other solutions would you | [
-0.008334029465913773,
0.009031214751303196,
0.15842412412166595,
0.2885133922100067,
0.15250825881958008,
-0.27062520384788513,
-0.11864233762025833,
0.06301861256361008,
-0.6071428656578064,
-0.35128509998321533,
-0.08493851870298386,
0.6069826483726501,
-0.3236697316169739,
0.1522679477... | |
use to ensure data consistency which are deadlock free?
It depends a lot on the transactional implementation inside your database and may also depend on the transaction isolation level you use. I'm assuming "repeatable read" or higher here. Holding transactions open for a long time (even ones which haven't modified anything) forces the database to hold on to deleted or updated rows of frequently-changing tables (just in case you decide to read them) which could otherwise be thrown away.
Also, rolling back transactions can be really expensive. I know that in MySQL's InnoDB engine, rolling back a big transaction can take | [
0.21243877708911896,
-0.09296691417694092,
0.1429489254951477,
0.2327277958393097,
0.009999236091971397,
-0.2624979019165039,
0.028572119772434235,
0.1827782839536667,
-0.5030220150947571,
-0.4141070544719696,
0.004181878641247749,
0.6407568454742432,
-0.05599299073219299,
0.16181020438671... | |
FAR longer than committing it (we've seen a rollback take 30 minutes).
Another problem is to do with database connection state. In a distributed, fault-tolerant application, you can't ever really know what state a database connection is in. Stateful database connections can't be maintained easily as they could fail at any moment (the application needs to remember what it was in the middle of doing it and redo it). Stateless ones can just be reconnected and have the (atomic) command re-issued without (in most cases) breaking state. | [
0.08797633647918701,
-0.10986185818910599,
0.017246156930923462,
0.4598616361618042,
0.2260521650314331,
-0.4194241762161255,
0.4662240445613861,
0.014029809273779392,
-0.2946567237377167,
-0.4281025528907776,
-0.17171534895896912,
0.19625453650951385,
0.015730977058410645,
0.3514367341995... | |
When you use Zedgraph for linegraphs and set IsSmooth to true, the lines are nicely curved instead of having hard corners/angles.
While this looks much better for most graphs -in my humble opinion- there is a small catch. The smoothing algorithm makes the line take a little 'dive' or 'bump' before going upwards or downwards.
In most cases, if the datapoint are themselves smooth, this isn't a problem, but if your datapoints go from say 0 to 15, the 'dive' makes the line go under the x-axis, which makes it seems as though there are some datapoints below zero (which is | [
-0.10725464671850204,
-0.42656704783439636,
0.6458216905593872,
0.20863083004951477,
-0.3468396067619324,
0.23532117903232574,
0.27484363317489624,
0.07638966292142868,
-0.2841893136501312,
-0.6806848645210266,
0.018230829387903214,
0.2609895169734955,
-0.062073297798633575,
-0.00724022882... | |
not the case).
How can I fix this (prefably easily ;)
No simple answer for this. Keeping the tension near zero will be your simplest solution.
ZedGraph uses GDI's DrawCurve tension parameter to apply smoothness, which is probably Hermite Interpolation. You can try to implement your own Cosine Interpolation, which will keep local extremes because of its nature. You can look at the this link to see why:
<http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/interpolation/>
EDIT: Website is down. Here is a cached version of the page:
<http://web.archive.org/web/20090920093601/http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/interpolation/> | [
-0.1283513903617859,
-0.450173556804657,
0.5035034418106079,
0.1698242872953415,
-0.26700350642204285,
-0.023569144308567047,
0.40666624903678894,
-0.49287575483322144,
-0.3461153209209442,
-0.41800278425216675,
0.27735134959220886,
0.5165602564811707,
-0.3356539011001587,
0.21310366690158... | |
I want something that looks like a file handle but is really backed by an in-memory buffer to use for I/O redirects. How can I do this?
It's not possible without modifying the compiler. This is because Handle is an abstract data type, not a typeclass. | [
0.38500380516052246,
0.18878832459449768,
0.04303417727351189,
0.09571732580661774,
-0.033617325127124786,
-0.11459376662969589,
0.07622777670621872,
-0.06645039469003677,
0.08550235629081726,
-0.5076540112495422,
0.17880016565322876,
0.46754613518714905,
-0.20286458730697632,
0.2666579186... | |
Backgrounder:
The [PIMPL Idiom](http://en.wikipedia.org/wiki/Opaque_pointer) (Pointer to IMPLementation) is a technique for implementation hiding in which a public class wraps a structure or class that cannot be seen outside the library the public class is part of.
This hides internal implementation details and data from the user of the library.
When implementing this idiom why would you place the public methods on the pimpl class and not the public class since the public classes method implementations would be compiled into the library and the user only has the header file?
To illustrate, this code puts the `Purr()` implementation on the impl class and wraps it | [
0.41204383969306946,
-0.2876453697681427,
0.1816447377204895,
0.047407057136297226,
0.026061588898301125,
-0.09646563231945038,
0.2728284001350403,
-0.1204070970416069,
-0.4507300853729248,
-0.14056777954101562,
-0.3400055468082428,
-0.02707246132194996,
-0.6897140741348267,
0.200617119669... | |
as well.
**Why not implement Purr directly on the public class?**
```c++
// header file:
class Cat {
private:
class CatImpl; // Not defined here
CatImpl *cat_; // Handle
public:
Cat(); // Constructor
~Cat(); // Destructor
// Other operations... | [
-0.06768783181905746,
-0.3155286908149719,
0.3966045379638672,
-0.2698339521884918,
-0.05802828073501587,
0.18396306037902832,
0.23951688408851624,
-0.125572070479393,
-0.022507494315505028,
-0.27085280418395996,
-0.443221777677536,
0.7386086583137512,
-0.7997127771377563,
-0.0550945587456... | |
Purr();
};
// CPP file:
#include "cat.h"
class Cat::CatImpl {
Purr();
... // The actual implementation can be anything
};
Cat::Cat() {
cat_ = new CatImpl;
}
Cat::~Cat() {
delete cat_;
}
Cat::Purr(){ cat_->Purr(); }
CatImpl::Purr(){
printf("purrrrrr");
}
```
* Because you want `Purr()` to be able to use private members of `CatImpl`. `Cat::Purr()` would not be allowed such an access without a `friend` declaration.
* Because you then don't mix responsibilities: one class implements, one class forwards. | [
-0.45465877652168274,
-0.28061071038246155,
0.7081947922706604,
-0.28676414489746094,
0.042553238570690155,
0.0929480791091919,
0.30973199009895325,
-0.39479485154151917,
-0.13218629360198975,
-0.5328004956245422,
-0.42809829115867615,
0.5646997690200806,
-0.6841329336166382,
0.01211217418... | |
Using C# .NET 2.0, I have a composite data class that does have the `[Serializable]` attribute on it. I am creating an `XMLSerializer` class and passing that into the constructor:
```
XmlSerializer serializer = new XmlSerializer(typeof(DataClass));
```
I am getting an exception saying:
> There was an error reflecting type.
Inside the data class there is another composite object. Does this also need to have the `[Serializable]` attribute, or by having it on the top object, does it recursively apply it to all objects inside?
Look at the inner exception that you are getting. It will tell you which field/property it is having trouble serializing.
You | [
0.09482879936695099,
0.1783839613199234,
0.1133333221077919,
-0.16555331647396088,
-0.028595127165317535,
-0.1574467420578003,
0.02443503402173519,
-0.19740405678749084,
-0.3290777802467346,
-0.4982134699821472,
-0.059774886816740036,
0.5043851137161255,
-0.6253747344017029,
0.047026533633... | |
can exclude fields/properties from xml serialization by decorating them with the [`[XmlIgnore]`](https://learn.microsoft.com/en-us/dotnet/api/system.xml.serialization.xmlignoreattribute) attribute.
`XmlSerializer` does not use the [`[Serializable]`](https://learn.microsoft.com/en-us/dotnet/api/system.serializableattribute) attribute, so I doubt that is the problem. | [
0.3432779312133789,
0.051693979650735855,
0.37679654359817505,
0.12750037014484406,
0.004471003543585539,
-0.3933103680610657,
0.12723520398139954,
-0.13462147116661072,
-0.29137012362480164,
-0.3652738630771637,
-0.3809553384780884,
0.3602207601070404,
-0.37020397186279297,
0.421704739332... | |
On a PHP-based web site, I want to send users a download package after they have filled out a short form. The site-initiated download should be similar to sites like download.com, which say "your download will begin in a moment."
A couple of **possible approaches** I know about, and browser compatibility (based on a quick test):
**1) Do a `window.open` pointing to the new file.**
```
- FireFox 3 blocks this.
- IE6 blocks this.
- IE7 blocks this.
```
**2) Create an iframe pointing to the new file.**
```
- FireFox 3 seems to think this is OK. (Maybe it's because | [
0.24062034487724304,
-0.01541315671056509,
0.4700823724269867,
-0.0323149710893631,
-0.2795189619064331,
-0.46821075677871704,
0.229573592543602,
0.025970539078116417,
-0.08733955025672913,
-0.7560053467750549,
-0.40499410033226013,
0.5787688493728638,
-0.24306505918502808,
-0.039620850235... | |
I already accepted it once?)
- IE6 blocks this.
- IE7 blocks this.
How can I do this so that at least these three browsers will not object?
```
Bonus: is there a method that doesn't require browser-conditional statements?
(I believe that download.com employs both methods conditionally, but I can't get either one to work.)
**Responses and Clarifications:**
```
Q: "Why not point the current window to the file?"
A: That might work, but in this particular case, I want to show them some other content while their download starts - for example, "would you like to donate to this | [
0.5752661824226379,
-0.16200627386569977,
0.49583950638771057,
0.017369214445352554,
-0.12879541516304016,
-0.1406158059835434,
-0.03494475409388542,
-0.11484014242887497,
-0.10967781394720078,
-0.4973768889904022,
-0.03264252841472626,
0.3943900763988495,
-0.08273256570100784,
0.188287615... | |
project?"
```
**UPDATE: I have abandoned this approach. See my answer below for reasons.**
You can also do a meta refresh, which most browsers support. Download.com places one in a noscript tag.
```
<meta http-equiv="refresh" content="5;url=/download.php?doc=123.zip"/>
``` | [
0.6418588757514954,
-0.26186293363571167,
0.26925474405288696,
0.22225943207740784,
0.09999744594097137,
-0.2042076736688614,
0.3406560719013214,
-0.1396542340517044,
-0.3798500597476959,
-0.5212741494178772,
-0.2716158330440521,
0.48922181129455566,
-0.043617863208055496,
0.06647212058305... | |
I wondered if anyone had successfully managed, or knew how to automate the Safari web browser on the Windows platform.
Ideally I would like to automate Safari in a similar way to using [mshtml](http://msdn.microsoft.com/en-us/library/aa741317.aspx) for Internet Explorer. Failing that a way to inject JavaScript into the running process would also be fine. I've used the JavaScript injection method to automate Firefox via the [jssh](http://www.croczilla.com/jssh) plug-in.
I'm looking to automate the browser using .Net to enhance an existing automation framework [WatiN](http://watin.sourceforge.net/)
**Edit**: Whilst I think selenium might be a great choice for automating Safari in certain scenarios, I would like to use a solution | [
0.2658631205558777,
0.173295795917511,
0.11144784837961197,
-0.14765511453151703,
-0.20315253734588623,
0.024716436862945557,
0.42628714442253113,
-0.1365111768245697,
-0.3454459011554718,
-0.609684944152832,
-0.14669793844223022,
0.7897918224334717,
-0.44083109498023987,
-0.05892518535256... | |
that does not require installing software on the server i.e. Selenium Core or an intermediate proxy server in the case of Selenium Remote Control.
**Update: 23-03-2009**:
Whilst I've not yet found a way to automate Safari, I have found a way to automate Webkit inside of Chrome. If you run Chrome using the --remote-shell-port=9999 command line switches (ref: <http://www.ericdlarson.com/misc/chrome_command_line_flags.html>) you can send javascript to the browser.
Once connected to the remote debug seesion
* Send **debug()** to attach to the current tab
* Send any javascript command using **print**, i.e. print document.window.location.href
We've used this method to add [Chrome support to WatiN](http://watin.svn.sourceforge.net/viewvc/watin/trunk/src/Core/Native/Chrome/)
you might check my post | [
0.11531982570886612,
0.12605515122413635,
0.6052282452583313,
-0.18388688564300537,
-0.4280107319355011,
-0.11667083948850632,
0.39256325364112854,
-0.16689425706863403,
-0.27176085114479065,
-0.5809420347213745,
-0.061162594705820084,
0.48841458559036255,
-0.3128204047679901,
0.0437963865... | |
here where I am using the method described above to automate Chrome in C#
<http://markcz.wordpress.com/2012/02/18/automating-chrome-browser-from-csharp/>
Martin | [
0.14207106828689575,
0.3537592887878418,
0.3070581555366516,
-0.3425387740135193,
-0.06484547257423401,
-0.04846416786313057,
0.38330671191215515,
-0.18330995738506317,
-0.44310903549194336,
-0.5356545448303223,
-0.18718041479587555,
0.4877713620662689,
-0.1014554500579834,
0.0090492833405... | |
I need to replace all WinAPI calls of the
* CreateFile,
* ReadFile,
* SetFilePointer,
* CloseHandle
with my own implementation (which use low-level file reading via Bluetooth).
The code, where functions will be replaced, is Video File Player and it already works with the regular hdd files.
It is also needed, that Video Player still can play files from HDD, if the file in the VideoPlayer input is a regular hdd file.
What is the best practice for such task?
I suggest that you follow these steps:
1. Write a set of wrapper functions, e.g MyCreateFile, MyReadFile, etc, that initially just call the corresponding API and pass the same | [
0.3829970359802246,
-0.20867979526519775,
0.6689004898071289,
0.1860627681016922,
-0.02294740080833435,
-0.44366639852523804,
-0.05840522050857544,
-0.24360163509845734,
0.1492055207490921,
-0.8074362874031067,
-0.15652962028980255,
0.9122606515884399,
-0.2567625641822815,
0.09894251823425... | |
arguments along, unmodified.
2. Use your text editor to search for all calls to the original APIs, and replace these with calls to your new wrapper functions.
3. Test that the application still functions correctly.
4. Modify the wrapper functions to suit your own purposes.
Note that CreateFile is a macro which expands to either CreateFileW or CreateFileA, depending on whether UNICODE is defined. Consider using LPCTSTR and the [TCHAR functions](http://msdn.microsoft.com/en-us/library/c426s321%28VS.80%29.aspx) so that your application can be built as either ANSI or Unicode.
Please don't use #define, as suggested in other responses here, as this will just lead to maintenance problems, and as Maximilian correctly | [
0.023200297728180885,
-0.03314503654837608,
0.6331748366355896,
0.04426116123795509,
0.030483772978186607,
0.3875240683555603,
0.1979570984840393,
-0.23286928236484528,
-0.09851156920194626,
-0.4317700266838074,
-0.1752222776412964,
0.7114883065223694,
-0.32731279730796814,
-0.125490680336... | |
points out, it's not a best-practice. | [
0.3772090673446655,
0.4563794434070587,
0.016744334250688553,
0.007957828231155872,
0.1715097725391388,
-0.23933713138103485,
0.4879140257835388,
-0.15465393662452698,
0.21821996569633484,
-0.20586097240447998,
0.202478289604187,
0.47797390818595886,
0.46729451417922974,
-0.083999447524547... | |
Is global memory initialized in C++? And if so, how?
(Second) clarification:
When a program starts up, what is in the memory space which will become global memory, prior to primitives being initialized? I'm trying to understand if it is zeroed out, or garbage for example.
The situation is: can a singleton reference be set - via an `instance()` call, prior to its initialization:
```
MySingleton* MySingleton::_instance = NULL;
```
and get two singleton instances as a result?
See my C++ quiz on on multiple instances of a singleton...
Yes global primitives are initialized to NULL.
Example:
```
int x;
int main(int argc, char**argv)
{
assert(x == 0);
int y;
//assert(y | [
-0.2953883111476898,
-0.06388162821531296,
0.15181371569633484,
0.17025181651115417,
0.03094729408621788,
-0.03784940019249916,
0.07429331541061401,
0.12602785229682922,
-0.4091639518737793,
-0.33973929286003113,
-0.25399065017700195,
0.590319037437439,
-0.11314956843852997,
0.247038230299... | |
== 0); <-- wrong can't assume this.
}
```
You cannot make any assumptions about classes, structs, arrays, blocks of memory on the heap...
It's safest just to always initialize everything. | [
0.030424712225794792,
0.12935148179531097,
-0.2407556027173996,
-0.09034360945224762,
0.03043871931731701,
-0.3975731432437897,
0.3349001705646515,
-0.12397845834493637,
0.0823076143860817,
-0.5783973932266235,
-0.23003754019737244,
0.3842238485813141,
-0.291882187128067,
0.087523311376571... | |
is it possible to display ⇓ entity in ie6? It is being display in every browser but not IE 6.I am writing markup such as:
```
<span>⇓</span>
```
According to [this page](https://web.archive.org/web/20080221144246/http://www.ackadia.com:80/web-design/character-code/character-code-symbols.php), that symbol doesn't show in IE6 at all.
```
Symbol Character Numeric Description
⇓ ⇓ ⇓ Down double arrow - - * Doesn't show with MS IE6
```
If you really need that particular symbol, you may just have to go for a small graphic of the arrow - not an ideal solution, but if you need it to | [
0.1144973486661911,
0.15328854322433472,
0.45876747369766235,
-0.07465403527021408,
-0.10169561952352524,
0.01199960708618164,
0.35631778836250305,
-0.08413814008235931,
-0.1461750715970993,
-0.8204287886619568,
-0.06276477873325348,
0.3621945381164551,
-0.205916166305542,
-0.0016087588155... | |
display in IE6 then that may be your only option. | [
0.24797500669956207,
-0.14866527915000916,
0.35541194677352905,
0.1367155909538269,
-0.03669968247413635,
-0.2672766447067261,
0.14282973110675812,
0.3427664041519165,
-0.2794788181781769,
-0.9192652702331543,
-0.044938769191503525,
0.6424462199211121,
0.02952275052666664,
-0.0314830169081... | |
What guidelines do you follow to improve the general quality of your code? Many people have rules about how to write C++ code that (supposedly) make it harder to make mistakes. I've seen people *insist* that every `if` statement is followed by a brace block (`{...}`).
I'm interested in what guidelines other people follow, and the reasons behind them. I'm also interested in guidelines that you think are rubbish, but are commonly held. Can anyone suggest a few?
To get the ball rolling, I'll mention a few to start with:
* Always use braces after every `if` / `else` statement (mentioned above). The | [
0.920467734336853,
0.26223209500312805,
-0.43766117095947266,
-0.15104274451732635,
-0.06090148910880089,
-0.11223959177732468,
0.16627691686153412,
0.07810114324092865,
-0.21819324791431427,
-0.3696303963661194,
0.15247516334056854,
0.5102243423461914,
-0.32713496685028076,
-0.27356234192... | |
rationale behind this is that it's not always easy to tell if a single statement is actually one statement, or a preprocessor macro that expands to more than one statement, so this code would break:
```
// top of file:
#define statement doSomething(); doSomethingElse
// in implementation:
if (somecondition)
doSomething();
```
but if you use braces then it will work as expected.
* Use preprocessor macros for conditional compilation ONLY. preprocessor macros can cause all sorts of hell, since they don't allow C++ scoping rules. | [
0.3466987907886505,
0.06063246354460716,
-0.11181919276714325,
-0.06482072919607162,
0.06715220212936401,
-0.251467764377594,
0.5898790955543518,
-0.20701199769973755,
-0.26857784390449524,
-0.4341179430484772,
-0.13271020352840424,
0.6157910227775574,
-0.4753611981868744,
-0.0265641957521... | |
I've run aground many times due to preprocessor macros with common names in header files. If you're not careful you can cause all sorts of havoc!
Now over to you.
A few of my personal favorites:
Strive to write code that is [const correct](http://www.parashift.com/c++-faq-lite/const-correctness.html). You will enlist the compiler to help weed out easy to fix but sometimes painful bugs. Your code will also tell a story of what you had in mind at the time you wrote it -- valuable for newcomers or maintainers once you're gone.
Get out of the memory management business. Learn to use smart pointers: `std::auto_ptr`, `std::tr1::shared_ptr` (or `boost::shared_ptr`) | [
0.31510111689567566,
0.6297152638435364,
-0.07060793042182922,
0.3071267008781433,
0.2200595736503601,
-0.1963070034980774,
0.5473819375038147,
0.2836625277996063,
-0.3924836814403534,
-0.7717309594154358,
0.016634758561849594,
0.6568259596824646,
0.11088588833808899,
0.2671090364456177,
... | |
and `boost::scoped_ptr`. Learn the differences between them and when to use one vs. another.
You're probably going to be using the Standard Template Library. Read the [Josuttis book](https://rads.stackoverflow.com/amzn/click/com/0201379260). Don't just stop after the first few chapters on containers thinking that you know the STL. Push through to the good stuff: algorithms and function objects. | [
0.1260022073984146,
-0.10605381429195404,
-0.028714299201965332,
0.015549763105809689,
-0.17161321640014648,
-0.19876742362976074,
0.06637200713157654,
-0.04659789055585861,
-0.2585400640964508,
-0.48367413878440857,
-0.20930799841880798,
0.6454334855079651,
-0.18473897874355316,
-0.314079... | |
Can you have a multicolumn listview control where one of the columns is a checkbox? Example code or links would be greatly appreciated.
I am using visual studio 2005
Allan Anderson created a custom control to let you do this.
You can find it here: <http://www.codeproject.com/KB/list/aa_listview.aspx>
Here's some example code for that control:
```
GlacialList mylist = new GlacialList();
mylist.Columns.Add( "Column1", 100 ); // this can also be added
// through the design time support
mylist.Columns.Add( "Column2", 100 );
mylist.Columns.Add( "Column3", 100 );
mylist.Columns.Add( "Column4", 100 );
GLItem item;
item = this.glacialList1.Items.Add( "Atlanta Braves" );
item.SubItems[1].Text | [
-0.0022839682642370462,
0.028009872883558273,
0.319000244140625,
-0.028957979753613472,
-0.2729250192642212,
0.15424363315105438,
0.48403501510620117,
-0.23338378965854645,
-0.5468919277191162,
-0.6364827156066895,
0.16692394018173218,
0.30534839630126953,
-0.7210559844970703,
-0.026954745... | |
= "8v";
item.SubItems[2].Text = "Live";
item.SubItems[2].BackColor = Color.Bisque;
item.SubItems[3].Text = "MLB.TV";
item = this.glacialList1.Items.Add( "Florida Marlins" );
item.SubItems[1].Text = "";
item.SubItems[2].Text = "Delayed";
item.SubItems[2].BackColor = Color.LightCoral;
item.SubItems[3].Text = "Audio";
item.SubItems[1].BackColor = Color.Aqua; // set the background
// of this particular subitem ONLY
item.UserObject = myownuserobjecttype; // set a private user object
item.Selected = true; // set this item to selected state
item.SubItems[1].Span = 2; // set this sub item to span 2 spaces
ArrayList selectedItems = mylist.SelectedItems;
// get list of selected items
``` | [
0.21214139461517334,
-0.49443691968917847,
0.6700838208198547,
0.005041373893618584,
0.3039948046207428,
-0.016034182161092758,
0.26602619886398315,
-0.31641289591789246,
-0.4472469985485077,
-0.5126013159751892,
-0.5267645120620728,
0.457019180059433,
-0.3753195106983185,
0.31486436724662... | |
What is the best way for me to determine a controller variable's value during execution?
For example, is there a way I can insert a break in the code, and cause the value of the variable to be output to the screen (or the log)?
Yes. The easiest way is to raise the value as a string. Like so: `raise @foo.to_s`
Or, you can install the debugger (`gem install ruby-debug`), and then start the development server with the `--debugger` flag. Then, in your code, call the `debugger` instruction.
Inside the debugger prompt, you have many commands, including `p` to print the value of a | [
0.5715388655662537,
-0.12593697011470795,
0.12442431598901749,
-0.0005509123438969254,
0.08569145202636719,
-0.025880135595798492,
0.12531770765781403,
-0.2057800143957138,
-0.12796375155448914,
-0.3976503312587738,
-0.161073237657547,
0.845750629901886,
-0.23707041144371033,
0.24226798117... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.