News for hackers. Stuff that matters.

i2

Re:Ask HN: Founders, what's your lifestyle like? on Saturday February 21, 2015 @03:20PM (#9086728)
I bet it's no more than ten minutes on a busy day, between 6:30 and 7:30, between coffee and thinking about work. Meditation is hard when you have something to do and must do it. Meditation is an Eastern thing and it doesn't play well with the Western values.
Re:DIY: kernel panic OS X and iOS in 10 LOC on Saturday February 21, 2015 @01:50PM (#9086419)
It was quite common for the Linux kernel to panic, 15 years or so ago. I bet that even now it is much easier to make Linux panic than Darwin. HN became way too passive-aggressive in recent years... :(
Re:DIY: kernel panic OS X and iOS in 10 LOC on Saturday February 21, 2015 @05:01AM (#9085195)
A very nice reminder that there's no such thing as code without bugs.
Re:Software in 2014 on Thursday January 09, 2014 @08:10AM (#7030212)
Except it is, because your code doesn't work:

  > [10, 1, 5, 1, 10, 10, 1, 5, 5, 5, 10].sort(byNum)
  > [10, 10, 5, 1, 10, 1, 1, 5, 5, 5, 10]
The right way is

  > function byNum(a, b) { return a - b; }
The same can be done with Python lambdas:

  >>> ZERO = lambda f: lambda x: x
  >>> FIVE = lambda f: lambda x: f(f(f(f(f(x)))))
  >>> to_int = lambda f: f(lambda x: x+1)(0)
  ... etc.
Re:A DSL in 5 Languages: Ruby, Python, PHP, C#, Java on Tuesday August 03, 2010 @01:51PM (#1572014)
You can make it without any 'weaknesses' in Python:

  collection = Transaction.search(
      order_id__starts_with='a2d',
      customer_website__ends_with='.com',
      billing__first_name__exact='John',
      status__in=[
        Transaction.Status.Authorized,
        Transaction.Status.Settled
      ],
      amount__between=("10.00", "20.00")
  )
the implementation could look like this:

  def search(**kwargs):
      for arg, value in kwargs.items():
          action = arg.split('__')
          attr = getattr(self, action[0])
          if len(action) == 2:
              method = getattr(attr, action[1])
              method(value)
          etc.
          .....
EDIT: removed unneeded quotes, thanks for correction, postfuturist