Hacker Newsnew | past | comments | ask | show | jobs | submit | 1337Coder's commentslogin

If anyone is curious about the luhn algorithm, here is one I made in C# from the example in the question:

static bool IsValidLuhn(string numbers) { if (numbers == null) throw new ArgumentNullException("number", "number must have a value.");

var allNumbers = numbers .Where((c) => c >= '0' && c <= '9') .Reverse() .Select((c, i) => (i % 2 == 1) ? ((Convert.ToInt32(c) - 48) * 2).ToString() : c.ToString());

return allNumbers.Count() > 0 ? allNumbers.Aggregate((x, y) => x + y).Sum((c) => Convert.ToInt32(c) - 48) % 10 == 0 : false; }

Edit: Can sum one link me to HackerNews markdown?


I also did one in javascript (i've requested it be ammended to the accepted response but we'll see how it reviews) anyway here it is:

  function validateCC(ccNumber) {
    var ccNumber = ccNumber.replace(/ /g, '');

    console.log(
      /^3[4|7]\d{13}/.test(ccNumber) ? 'AMEX' :
      /^6011\d{12}/.test(ccNumber) ? 'Discover' :
      /^5[1-5]\d{14}/.test(ccNumber) ? 'MasterCard' :
      /^4[\d{12}|\d{15}]/.test(ccNumber) ? 'Visa' : 'Unknown',
      ccNumber,
      ccNumber.split('').reverse()
        .map(function (v, i) { return v * (1 + i % 2) })
        .reduce(function (agg, v) { return agg + v; }, '').split('')
        .reduce(function (agg, v) { return agg + +v; }, 0) % 10 === 0 ? '(valid)' : '(invalid)');
  }
btw to markup simply append 2 spaces to the front of the newline


While your code may be fine, I find it weird to see functional operations in the same expression as the ASCII code '0' (48). It is a very weird juxtaposition of abstractions.


For anyone trying to go to the Erik Meijer link, the correct url is: http://channel9.msdn.com/Series/C9-Lectures-Erik-Meijer-Func...

I think vasquez put an extra right angle bracket by mistake.


Thanks. I did fix it soon after posting, but guess the incorrect one could be cached for a while.


This is the exact reason I created this: https://privatemsg.matthew-dove.com/


Where can I grab source code?


Last weekend when the NSA news was a big deal, I was angry, I wanted my privacy back. I use all the standard stuff (like opt-out, Ghostery, etc). Using https for my emails with Google is great, unless they just send my plain text data to the NSA on request. So I looked around for a safe way to email. OMG was it hard. I had to install all kinds of stuff, find out how it works, and alot of them required the receiver of the message to also have said software. Yeah, if its that hard, no thanks. So I made this in one weekend. Alas I didn't have SSL (encryption) on my domain. And it took a week to change servers, get a dedicated IP and install the SSL. Anyway here it is. Create your message, send your friend the link to your message however you normally would, and they (only them) can see the message. No Google saving your data, and once your message has been viewed its deleted. Nothing for the NSA to even ask for. I realise the message creator is geared towards web developers, version two would ideally contain a more friendly text editor.


From what I see:

* everything is done server side -> trust issues

* no encryption, just indexed by a hash -> that means the messages are not store encrypted on the server

I would recommend people stay away from your solution, and instead use something like Zerobin: http://sebsauvage.net/paste/ It encrypts everything using SJCL, and if I am worried with the server sending me a modified version of the JS code, I can still keep the code on my own computer but use it to send to the server.


Yes, it is encrypted on the server. That hash is just a key to get your message. Its not the message itself.



Well would you believe that it is not uncommon for one or two people to die on a cruise? I went on a 10 day cruise a few years ago and three people died on it. They chucked 'em in the fridge and carried on the trip like it was normal.


Yeah, that makes sense. The US annual death rate is 8.39 per 1000[1]. The newest ship in Carnival's inventory holds up to 3,690 passengers[2]. I can't find crew capacity, but some googling suggests there ought to be more than 1000 crew on a loaded cruise that size.

So if you're floating around with 4690+ people, naïvely, about 39 people should die on it every year, or one every 9.28 days.

On a 10-day cruise of that size, somebody is going to die. I bet once you control for the unusually high average age of the passengers and maybe other factors (how many drunken idiots fall over the side and drown every year?), 3 people in 10 days would be pretty normal.

[1]https://www.cia.gov/library/publications/the-world-factbook/...

[2]http://en.wikipedia.org/wiki/Carnival_Breeze


The drunken idiots falling over the side and drowning don't usually get found. As far as I remember, the odds of being found after falling off a cruise ship are really low.


I use "&" and "|" when i use enums, that act as options. I.e. var myCarExtras = Extra.Radio | Extra.PowerWindows;

Where Extra = { Radio = 1, PowerWindows = 2, Tint = 4, Rims = 8 };

Then I can do: if (Tint | powerWindows) { return totalPrice + 1000; }


C# programmer? I think this is one of the nicer little features in that language.


sorry for being pedantic, but should'nt it be shouldn't?


You would think so but no. Visa etc and the banks don't want that kind of trouble. To charge cards you need a special bank account called a merchant account.

A condition of this merchant account is that if someone issues a charge-back on their creditcard, if the merchant can't prove that the card owner brought the service/product then the funds are taken directly form their merchant account by the bank and then given back to the card-holder.

This is why anti-fraud systems are so important to merchants.

Case: I steal your creditcard, I buy a tv worth $10, 000. You notice this, and chargeback the merchant. The merchant has to pay you $10, 000 and he lost teh cost price of the tv he sold me (say $7, 000).

So by accepting your stolen card as payment, the merchant just lost $17, 000!

Source: I build payment gateways.


Aren't you double-counting here? On net the merchant only loses the merchandise. The net debit to the merchant's account is zero.


correct maths are: merchant gets 10000 then returns 10000 and still has to pay 7000 to vendor for the goods. net loss is 7K, not 17K


You could also say the total loss is 10K to the merchant, assuming he has a reasonable expectation of making that 3K profit...that is getting a little abstract about it though.


Oh yes you are correct.

In this case the merchant only loses the cost to the vendor ($7,000). Good catch.


Typically there's also a fee imposed by the bank for having a chargeback.


Standard is $25, but if you are a big merchant it could be lower.


I think they're counting the loss of the merchandise. So a chargeback for a $10,000 TV would be like losing $10,000 plus whatever the cost of the TV was for the store.


But it's not. Getting paid $10k and giving it back is net zero.


Not when you could have sold the TV for $10K. This is the shoplifting issue; the shop loses both the product and the potential profit on the product.

It gets a bit existential e.g. can you lose what you never really had? But even if you fall on the NO side of that, the cost of re-obtaining a product is not zero.


The cost of re-obtaining the product is $7k, which were already accounted for. Marginal administrative costs are negligible.


But the merchant is still down a TV. Those things aren't free.


Sure. I objected to the assertion that the merchant lost $17k, which is a gross exaggeration.


Like everyone else said, it's not exactly that. It's like getting paid $10k in exchange for a TV, then giving it back but not getting the TV back in return.


$17,000 figure is correct:

1) Store buys TV (COGS = $7K): -$7K

2) Sold TV for $10K. Realized P/L: $3K

3) $10K refunded (chargeback): -$7K

4) TV is gone as well. Inventory: -$7K

5) Potential profit loss: -$3K

Total loss: (7+7+3) = $17K


1. Store buys TV. -$7000

2. Store sells TV. +$10000, subtotal: +$3000

3. Store pays chargeback. -$10000' subtotal: -$7000

You can't double count the TV, and IMO, you can't count the potential profit loss either, as that's covered once the store buys a replacement TV for inventory. There are fees on top of the above, but the store is out the COGS and fees, not double the COGS, plus the margin.


{MyScore:'1837';}


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: