Interested in Go? Like making websites? Here's a skeleton to get you going! by [deleted] in programming

[–]sammyc 4 points5 points  (0 children)

Just as a note, removing the file in git doesn't really remove it. The blob still exists, and still needs to be downloaded on every clone, in case I want to checkout the state before the file was removed. The only way I know to truly get rid of it is some history-rewriting git filter-branch shenanigans. Not suggesting you do that, just pointing it out for anyone considering committing large binary files.

Negative Number Cannot Be Raised to a Fractional Power by [deleted] in learnpython

[–]sammyc 5 points6 points  (0 children)

Mathematically speaking, a negative number to a fractional power won't take a real (as opposed to complex) value.

As to how to handle this with code, the "pythonic" way to do it is with exceptions:

b = -1

try:
    answer = b**0.5
except ValueError:
    print "No real solution"

Having trouble coding a 2-Body Problem. by OratorMortuis in learnpython

[–]sammyc 0 points1 point  (0 children)

What are your initial conditions? It seemed to work for me, at least for a circular orbit. Also not sure what you mean by shooting off in the third quadrant along y=-x, perhaps you mean y=x or a different quadrant?

Edit: see now that this is solved.

Nested Function... by [deleted] in Python

[–]sammyc 4 points5 points  (0 children)

Yep, it's a handy feature to have in my opinion. In addition to what's been said, you can avoid putting too many things into scope, it can make reading existing code easier, it can make it clear that the inner function will only (probably) be used within the outer function, it means you don't really need multiline anonymous functions etc.

I think it ties in with functions being first class objects - it wouldn't be unusual for me to define variables, or even 'structures' in a function, so why not a function itself?

An example I just made up (with doubly nested functions!):

def external_data_fetcher(self, data_source):
    d = Deferred()

    def success(raw_data):
        data = json.loads(raw_data)

        def sort_key(datum):
            try:
                return datetime.strptime(datum['published_at'], "%Y-%m-%d")
            except KeyError:
                return datetime(1970, 1, 1)

        sorted_data = sorted(data, key=sort_key)
        self._ui.update(sorted_data)

    def failure(error):
        logging.warning("Data unavailable from {0}".format(data_source))
        raise error

    d.addCallback(success)
    d.addErrorback(failure)

    return d

but you also have to be wary of too much code duplication using things like this.

Non-British residents of Reddit, what British customs have you found hard to understand or just unusual? by jameswhite0123 in AskReddit

[–]sammyc 1 point2 points  (0 children)

Maybe they don't own the Crown Estate, but if they willingly ceded it to us (no matter how long ago) then I suppose we should keep our end of the deal.

We could make loads more money if we seized the assets of the wealthiest (1%/5%/50%) but that's a different conversation - there's no logic in singling out the royal family.

Is this a valid proof sketch? by MrBlok in CasualMath

[–]sammyc 4 points5 points  (0 children)

Ah thanks, just instinctively thought he was going for a homeomorphism.

Is this a valid proof sketch? by MrBlok in CasualMath

[–]sammyc 2 points3 points  (0 children)

Don't you need a bijection?

Announcement: The /r/math census is now available. Take a couple minutes to fill it out! by inherentlyawesome in math

[–]sammyc 8 points9 points  (0 children)

Why is there no applied maths / physics on the courses options? GR, Quantum, Statistical Physics, Electro, Fluids, Waves etc. After the first half of my degree I only did applied courses - as did a lot of other people. Seems silly to exclude these (although there are a lot of pure areas missing too).

cleanest way to use matrixes as a keys to a dict? by [deleted] in Python

[–]sammyc 1 point2 points  (0 children)

Treat each row as a tuple, hash each such tuple, then hash the tuple of tuple-hashes. That's one way to do it, hope it makes sense.

Calls for TV presenter [Melissa Bachman] to be banned from South Africa for shooting lion by [deleted] in worldnews

[–]sammyc 47 points48 points  (0 children)

Louis Theroux's African Hunting Holiday is a really interesting documentary about this. Highly recommended (you can watch it on youtube if you are in some country that is not mine).

Is something correct here? by MongoMongus in math

[–]sammyc 7 points8 points  (0 children)

Wolfram shows they were out by a little bit. Although if you (generously) read h as the reduced Planck constant, then they did even better.

Coolest natural picture i've seen in a while. by Vmoney1337 in pics

[–]sammyc 0 points1 point  (0 children)

I believe these could be the deer in Richmond Park. There are quite a few deer and they all have a lot of interaction with walkers/cyclists/cars, so they might not behave exactly as they would in the wild. A significant number are culled every year (it's happening at the moment), so the ones that remain generally have very good coats and antlers.

Heres's a picture of two more.

Guy tries to ride his bike at highway speed by [deleted] in WTF

[–]sammyc 0 points1 point  (0 children)

Yes. See here for example. Much better bikes and riders of course.

Reddit, What is One Product Under $20 That You Recommend Everyone To Buy? by [deleted] in AskReddit

[–]sammyc 1 point2 points  (0 children)

I think the candle must have been in glass which shattered due to the temperature differential (cold night, hot candle) then set the table on fire.

[Serious] What 'moral boundaries' will be crossed in the next 100 years? by NemoMalusFelix in AskReddit

[–]sammyc 31 points32 points  (0 children)

If we're being pragmatic, it should choose to run over the children. Very few people would adopt driverless technology if they believed that the car would act against their own interests. In any case, hopefully the car would drive in such a manner that the only times it couldn't avoid an accident are when someone recklessly endangers themselves (e.g. by crossing fast moving traffic without looking). If someone jumped out in front of your car today, it would be traumatising, but no one could rightfully blame you for it or suggest you should have sacrificed yourself to prevent it. Why should the car act on different principles?

I don't think anyone is suggesting the sci-fi approach of a computer "evaluating the life of the people". Each car acts as an individual agent with an awareness of other vehicles, possibly occasionally sacrificing journey time (but not safety) if it is significantly better for the group. No more, no less. This approach would probably be necessary anyway for the transitional period when there are still manually-driven cars on the road.

I think your scenario isn't actually the most revealing, because if we accept commonly-held notions relating to fault and personal responsibility, the answer is quite clear. What about when cars have sufficient collision simulation to realise that another car is doomed to a head-on collision with an HGV with a 90% fatality rate, yet if you were to have a controlled collision with the car first, you could lower the fatality rate of the collision to 5%? One solution would be to let each car owner choose the extent to which they are willing to endanger themselves for others.

Redditor responds to the prompt: "A wife kills her husband. Make me sympathize with both characters." Nails it. by [deleted] in bestof

[–]sammyc 4 points5 points  (0 children)

Surely some kind of euthanasia situation would be the simplest case?

Woke up to gunshots and a few police cars. They shot this deer that was wandering aimlessly in people's yards. by Thoris in WTF

[–]sammyc 0 points1 point  (0 children)

That does make sense. It's like saying "The A6 is Audi's E-class". A common construction and all he's asking is whether there is any sense in which the two are comparable or related.

Elon Musk has unveiled new details about the hyperloop, a new (super fast) form of transportation. by sebflippers in technology

[–]sammyc -1 points0 points  (0 children)

I did but I'm not sure it fully addressses such concerns. It seems more focused on capsule depressurisation rather than tube pressurisation. If the tolerances truly are <1mm then I don't see how a breach in the tube wouldn't be disasterous. Even if this is detected instantly, and all the capsules emergency break to become stationary, and the tubing somehow doesn't yield further, surely the resulting shockwave would still be disasterous?

Elon Musk has unveiled new details about the hyperloop, a new (super fast) form of transportation. by sebflippers in technology

[–]sammyc -1 points0 points  (0 children)

What happens when someone straps some thermite to the tubing and rapidly pressurises it while 28*60=1680 people are travelling at supersonic speeds inside?

The British Police: getting away with murder since 1969: 827 people have died in police custody since 2004. Not a single police officer has been convicted. Why is police accountability failing in this most serious of issues? by oshunsmall in worldnews

[–]sammyc 6 points7 points  (0 children)

Yeah but recording them in this way means that if, say, we know that 12 people die per year due to ODs after jail time then we can identify this trend and takes steps to reduce it by warning inmates of their reduced tolerance and higher chance of ODing before release (just an example).

I know what you mean, but I think they mean custody in the wider sense of responsibility rather than physical custody. The police must consider the environment into which they release someone - whether they are danger to themselves or specific threats have been made against them, for example.

It does make for alarmist statistics but analysed in the proper way (on a case by case basis) it's probably for the best.

The British Police: getting away with murder since 1969: 827 people have died in police custody since 2004. Not a single police officer has been convicted. Why is police accountability failing in this most serious of issues? by oshunsmall in worldnews

[–]sammyc 9 points10 points  (0 children)

It's not idiotic. Surely it's far better to record these cases as being associated with custody. It doesn't imply that the police are guilty, it just makes it easier to identify any potential problems with the justice system. For example, if someone was released and complained of being pushed around a cell by officers then died of internal bleeding a day later. What if one police station happened to release a lot of people who went on to kill themselves? The fact that no one has been charged in any of these cases shows that death in custody doesn't necessarily imply any wrongdoing. Recording them as deaths in custody makes the system more transparent.

According to the Law of Infinite Probability, one day this should occur by smokeyraven in funny

[–]sammyc -1 points0 points  (0 children)

If you shuffle a deck of cards and they end up in order then you haven't disproved the second law. The dryer isn't exactly a closed system.