Interested in What the "<<" Does

Interested in what the does

For an array << is the append method. It adds an item to the end of the array.

So in your specific case when you call setup with a block the Proc object made from the block is stored in @setups.

Note: as sbeam points out in his comment, because << is a method, it can do different things depending on the type of object it is called on e.g. concatenation on strings, bit shifting on integers etc.

See the "ary << obj → ary" documentation.

SQL Server to Excel 2007 - New Lines

Try running this macro on the worksheet. (Right click the worksheet tab and click "View Code" to summon the VB IDE.)

Sub FixNewlines()
For Each Cell In UsedRange
Cell.FormulaR1C1 = Replace(Cell.FormulaR1C1, Chr(13), "")
Next Cell
End Sub

Parse a file using C++, load the value to a structure

You can do something like this:

std::string line;
std::map<std::string, std::string> props;
std::ifstream file("foo.txt");
while(std::getline(file, line)) {
std::string token;
std::istringstream tokens(line);
while(tokens >> token) {
std::size_t pos = token.find('=');
if(pos != std::string::npos) {
props[token.substr(0, pos)] = token.substr(pos + 1);
}
}

/* work with those keys/values by doing properties["name"] */
Line l(props["pc"], props["ct"], ...);

/* clear the map for the next line */
props.clear();
}

i hope it's helpful. Line can be like this:

struct Line { 
std::string pc, ct;
Line(std::string const& pc, std::string const& ct):pc(pc), ct(ct) {

}
};

now that works only if the delimiter is a space. you can make it work with other delimiters too. change

while(tokens >> token) {

into for example the following, if you want to have a semicolon:

while(std::getline(tokens, token, ';')) {

actually, it looks like you have only integers as values, and whitespace as delimiters. you might want to change

    std::string token;
std::istringstream tokens(line);
while(tokens >> token) {
std::size_t pos = token.find('=');
if(pos != std::string::npos) {
props[token.substr(0, pos)] = token.substr(pos + 1);
}
}

into this then:

    int value;
std::string key;
std::istringstream tokens(line);
while(tokens >> std::ws && std::getline(tokens, key, '=') &&
tokens >> std::ws >> value) {
props[key] = value;
}

std::ws just eats whitespace. you should change the type of props to

std::map<std::string, int> props;

then too, and make Line accept int instead of std::string's. i hope this is not too much information at once.

Meta Recruiting SQL -- Join Part 1

SELECT product_family,
SUM(units_sold) as total_units_sold,
CAST(SUM(CASE WHEN s.promotion_id IS NOT 0 then units_sold * 1.0 ELSE 0 END) AS NUMERIC) /
CAST(SUM(CASE WHEN s.promotion_id = 0 THEN units_sold * 1.0 ELSE 0 END) as NUMERIC) as ratio_units_sold_with_promo_to_sold_without_promo
FROM products p
JOIN product_classes c ON c.product_class_id = p.product_class_id
JOIN sales s ON s.product_id = p.product_id
GROUP BY product_family
ORDER BY total_units_sold ASC;

Sample Image

Redis: Does it make sense to use only shards if I'm not interested in HA?

Yes you can.

About HA, you have to be sure you define/know what is the application behaviour if this shard is becoming not available. (dataloss, service unavailable, ...)

On the replica-read, without having information about your application it is hard to tell; but most of the time a Redis instance (shard) is enough to deal with lot of load. A very "short" rules is, that a shard can deal with 25Gb of data, 25.000 operations/seconds with a sub-ms latency without any problem. Obviously this depends of the type of operations, data and command your are doing; it could be a lot more ops/sec if you do basic set/get.

And usually when we have more than this, we use Clustering to distribute the load.

So before going into the "replica-read" route (that I am trying to avoid as much as possible), take a look to your application, do some benchmark on a single shard: and you will probably see that everything is ok (at least from the workload point of view, but you will have a SPOF if you do not replicate)

CSS Conventions / Code Layout Models

Natalie Down of ClearLeft fame produced a really great slide show covering this topic and more http://natbat.net/2008/Sep/28/css-systems/

Download the PDF as it includes a lot more information than the slide show. I'd recommend this to CSS devs of all skill levels.

PHP: Calculating months and interest rate. Is this solution correct? It does work

No, it is wrong.

$mesesEnAnios = (($tYear - $fYear) -1) * 12;

That is for example: (2013 - 2012 - 1) = 0

0 * 12 = 0, while its obvious 12.

Then you do

$mesesScattered = (12 - $fMonth) + $tMonth;

So, lets say we have 05-2013 (month - year) and 05-2012. The result should be: 12 months. Lets assume you fixed the first line I pointed out, we get 12 months from that. On your second line, you get 12 - 5, which is 7. Result 7+12 = 19.. which is again obvious wrong.

To make it easy, ill just give you the code..

$months = (($tYear - $fYear ) * 12) + ($tMonth- $fMonth);

You first check if there are any extra's years and do this amount * 12 for the 12 months we have. 0 years give 0 months, 1 year gives 12 months etc. After that we check the months. If the first value is 8 months and the second value is 6 months, we have 2 months in total and add this value on top of the value we got from the years calculation.

That is the month part, for the other part I cannot help you since I do not know the calculation. Yet assuming you have 0 experience in math and PHP (like you said), I would recommend to manually calculate it, and compare it with the result from the script.



Related Topics



Leave a reply



Submit