https://alpha.app.net/riyad/post/13415752
Tag: Insights
ADN: “kölsche” Lebensart
https://alpha.app.net/riyad/post/12917180
ADN: The Essence of Oriental Discipline
https://alpha.app.net/riyad/post/12658687
Das A und O
OH im Islamologie-Seminar:
lā ilāha illā ʾLLĀH, muḥammadun rasūlu ʾLLĀH, ist das A und O!
… Ich fand’s lustig. 😀
Schizophrenics Were Right, Probably, Maybe, Hopefully Not …
An interesting article on how schizophrenics’ thoughts that they are controlled by an outside power or living in a world crafted for them has become a matter of possibility for all of us – or “how reality caught up with paranoid delusions.” Exploring advances in technology, its ubiquity and the way we consume it, we assume we perceive an altered *cough* enriched and augmented version of the world around us. We silently ignore that this allows us to be easily toyed with and manipulated without us necessarily noticing it.
This is an interesting phenomenon that is not widely known and mostly ignored. But the matter of the fact is that if you have two computers, side-by-side, open up your browser and search for the exact same thing, you won’t get the same list of results. The same happens on social networks: try looking for a non-person and compare the results and their order.
Search gurus will tell you this is the magic of “personalized results” and finding things “most interesting to you” … but what they don’t tell you is that this comes at the price of having the possibility of doing a global and unbiased search.
Any search you do is biased, by the region you are accessing the internet from (continent, country, city), your internet history, your search history, your language preferences, time of day … basically anything quantifiably different will alter your search results. You can’t (even if you try) do a unfiltered, repeatable and global search on the internet. And anything you click in those already tailored results will only reinforce your perceived “interest.”
Eli Pariser also talks about this in his “Beware online filter bubbles” Ted Talk where he quotes Google’s Eric Schmidt:
It will be very hard for people to watch or consume something that has not in some sense been tailored for them.
— Eric Schmidt, Google
So, what would prevent any of those search providers from manipulating results deliberately? Actually, pretty much nothing. The amount of manipulation they would have to do e.g. to influence voter preferences in an already close election would probably be too little to be noticed and it wouldn’t even be illegal. So that’s why people like Bruce Schneier demand regulation for secret algorithms that have become part of our infrastructure.
One thing is clear: it can’t stay the way it is now.
OK … enough dystopic thoughts for today. 😛
Update 2013-12-08:
Seems like reality caught up already. Case in point: South Korea.
What is Net Neutrality and why is it important?
If you have never heard of net neutrality or don’t know why it’s important, watch this video!
Summing Booleans For Fun And Profit
I came up with a IMHO nice piece of code while working with and getting to know Python.
incomplete_items = [
item.quantity_ordered > item.quantity_delivered for item in order.items
]
if any(incomplete_items):
do_something()
This feels clean and obvious. It might not be very efficient though. :/
has_incomplete_items = sum(
item.quantity_ordered > item.quantity_delivered for item in order.items
)
if has_incomplete_items:
do_something()
Doing it this way can be more efficient, since it can leverage generators and doesn’t need to go through the list again with
any
. But using
sum
over booleans feels hackish and non-obvious … 🙁
MagicMock With Spec
Thanks to @immoralist I’ve learned a new Python testing trick. I didn’t know about the “spec” argument for MagicMock. m(
Let’s see an example:
from mock import MagicMock
class SomeModel(object):
foo = "f**"
bar = "b**"
m = MagicMock(spec=SomeModel)
Here we create a mock object which mimics the interface of
SomeModel
as we would expect, returning mock values for things we access.
>>> m.foo <MagicMock name='mock.foo' id='4506756880'> >>> m.bar <MagicMock name='mock.bar' id='4506754192'>
Let’s see what happens if we call something else:
>>> m.baz
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../env/lib/python2.7/site-packages/mock.py", line 658, in __getattr__
raise AttributeError("Mock object has no attribute %r" % name)
AttributeError: Mock object has no attribute 'baz'
It will fail loudly while a mock object without a spec would have returned a mock value as it did in the previous example.
But the magic doesn’t end there. You can still set additional attributes/methods “by hand” and have them not fail even if they aren’t part of the original spec.
>>> m.baz = "bazzzzz" >>> m.baz 'bazzzzz'
Learning new things makes me happy. 😀
Tripping Over Property Setters in Python
In Python there is a simple way to make methods behave like properties using the @property decorator. But this only covers the getter side of things. What if you want to have a setter function for this “property”? Well there is a way. 🙂
Consider the following example:
import json
class SomeModel(object):
_foo = '{"foo":["bar", "baz"]}'
@property
def foo(self):
return json.loads(self._foo)
@foo.setter
def foo_setter(self, new_value):
self._foo = json.dumps(new_value)
m = SomeModel()
Now you can use the
foo()
method like a property.
>>> m.foo
{u'foo': [u'bar', u'baz']}
This is a simple way to have a property contain a JSON string but access it as a Python dict, doing (de-)serialization on the fly.
So what if you want to set the value using a dict?
>>> m.foo = ["foo", "bar"] Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: can't set attribute
This is can easily trip up even seasoned Python developers. I’ve read code that did exactly this and I (as a novice) had to find out why the code failed. m(
The solution is quite simple … but “non-obvious” (as in: I wouldn’t have thought of that without consulting the docs) 🙁
@foo.setter
def foo(self, new_value)
self._foo = json.dumps(new_value)
Notice the method name? The setter and the getter methods have to have the same name!
A Rainbow of Thoughts
[…] His vast, mild head overhung by a canopy of vapor, engendered by his incommunicable contemplations, and that vapor—as you will sometimes see it—glorified by a rainbow as if Heaven itself had put its seal upon his thoughts. For, d’ye see, rainbows do not visit the clean air; they only irradiate vapor. And so, through all the thick mists of the dim doubts in my mind, divine intuitions now and then shoot, enkindling my fog with a heavenly ray. And for this I thank God; for all have doubts; but doubts or denials, few along with them, have intuitions.
— H. Melville, 1851, Moby-Dick, Chapter 85
I can’t express how much this last sentiment resonated with me … this is exactly the feeling when you’re looking for a solution to a problem for days and in one moment: there it is; the solution laid out so clearly … when God lifts the cloak of ignorance for a second, allowing you an insight into what seemed incomprehensible just moments ago … a flash of insight sparking, kindling further thoughts … fearing it will dim out before it can be burned into memory … *sigh* those moments -.-