Interesting Numeric Pattern

>>> for i in range(1,31):
...     print('  ' + '1'*30)
...     print('x ' + '1'*i)
...     print('= ' + str(int('1'*30) * int('1'*i)))
...     print()
...
  111111111111111111111111111111
x 1
= 111111111111111111111111111111

  111111111111111111111111111111
x 11
= 1222222222222222222222222222221

  111111111111111111111111111111
x 111
= 12333333333333333333333333333321

  111111111111111111111111111111
x 1111
= 123444444444444444444444444444321

  111111111111111111111111111111
x 11111
= 1234555555555555555555555555554321

  111111111111111111111111111111
x 111111
= 12345666666666666666666666666654321

  111111111111111111111111111111
x 1111111
= 123456777777777777777777777777654321

  111111111111111111111111111111
x 11111111
= 1234567888888888888888888888887654321

  111111111111111111111111111111
x 111111111
= 12345678999999999999999999999987654321

  111111111111111111111111111111
x 1111111111
= 123456790111111111111111111110987654321

  111111111111111111111111111111
x 11111111111
= 1234567901222222222222222222220987654321

  111111111111111111111111111111
x 111111111111
= 12345679012333333333333333333320987654321

  111111111111111111111111111111
x 1111111111111
= 123456790123444444444444444444320987654321

  111111111111111111111111111111
x 11111111111111
= 1234567901234555555555555555554320987654321

  111111111111111111111111111111
x 111111111111111
= 12345679012345666666666666666654320987654321

  111111111111111111111111111111
x 1111111111111111
= 123456790123456777777777777777654320987654321

  111111111111111111111111111111
x 11111111111111111
= 1234567901234567888888888888887654320987654321

  111111111111111111111111111111
x 111111111111111111
= 12345679012345678999999999999987654320987654321

  111111111111111111111111111111
x 1111111111111111111
= 123456790123456790111111111110987654320987654321

  111111111111111111111111111111
x 11111111111111111111
= 1234567901234567901222222222220987654320987654321

  111111111111111111111111111111
x 111111111111111111111
= 12345679012345679012333333333320987654320987654321

  111111111111111111111111111111
x 1111111111111111111111
= 123456790123456790123444444444320987654320987654321

  111111111111111111111111111111
x 11111111111111111111111
= 1234567901234567901234555555554320987654320987654321

  111111111111111111111111111111
x 111111111111111111111111
= 12345679012345679012345666666654320987654320987654321

  111111111111111111111111111111
x 1111111111111111111111111
= 123456790123456790123456777777654320987654320987654321

  111111111111111111111111111111
x 11111111111111111111111111
= 1234567901234567901234567888887654320987654320987654321

  111111111111111111111111111111
x 111111111111111111111111111
= 12345679012345679012345678999987654320987654320987654321

  111111111111111111111111111111
x 1111111111111111111111111111
= 123456790123456790123456790110987654320987654320987654321

  111111111111111111111111111111
x 11111111111111111111111111111
= 1234567901234567901234567901220987654320987654320987654321

  111111111111111111111111111111
x 111111111111111111111111111111
= 12345679012345679012345679012320987654320987654320987654321

TypeError: list indices must be integers

You start your day, happily working with dictionaries…Life is good.

>>> mydict = {'key-a': 'value-a', 'key-b': 'value-b'}
>>> mydict['key-a']
'value-a'

All of a sudden, storm clouds appear. Your dictionary variable accidentally gets assigned a list, and life is no longer good!

>>> mydict = {'key-a': 'value-a', 'key-b': 'value-b'}
>>> mydict['key-a']
'value-a'
>>> mydict = []
>>> mydict['key-a']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: list indices must be integers

The error message "TypeError: list indices must be integers" is generated when you attempt to use a non-int for a index inside the [] operator.

By the way, almost the same message is used if you do this with a tuple:

TypeError: tuple indices must be integers

nginx restart error

Was playing around with nginx on Centos 5 (EPEL package).

Most of the time I ran:

service nginx restart

I would get this message in the /var/log/nginx/error.log file:

panic: MUTEX_LOCK (22) [op.c:352].

After some hunting around, it appears to be a known bug in nginx (perhaps perl in nginx?)… Anyway, a simple workaround is to do this:

service nginx stop
service nginx start

Or, simply edit /etc/init.d/nginx, and add the sleep 1 line:

51 restart() {
52     configtest || return $?
53     stop
54     sleep 1
55     start
56 }

Nice workround!

Great article on Python super, __mro__, and attributes

I highly recommend reading this excellent writeup on Python super(), python __mro__, python attributes, and more.

It is Copyright © 2005-2009 Shalabh Chaturvedi

http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html#method-resolution-order

Is it just me, or does this get old?

Hi Darryll,

If I have to say no again, you will officially be a nuisance. Have a great day, and best wishes with your endeavors.

Best Regards,

Jason Garber
Senior Systems Engineer
AppCove, Inc.

On Tue, Jan 12, 2010 at 10:35 AM, Darryll ——— wrote:

Jason,

I don’t mean to be a nuisance, but I wanted to try one more time to see if you, or someone you could direct me to would have a couple of minutes to discuss how my company can increase your access to working capital, a process which the Wall St. Journal calls, ‘An idea whose time has come.’ Just reply to my email, or contact me at the number below and I’ll follow up with you.

Best,

Darryll ——–
504———–

Google’s Lack of Customer Support

Perhaps it’s because Google hasn’t had “traditional customers” en mass for so long? Perhaps it’s because Google is 99% full of techno-geeks that are very focused on technology? Perhaps it’s just a lack of management’s vision?

Regardless of the reason, it’s hard to dispute that Google, Inc. lacks in Customer Service. Most recent post I saw was this Computer World article on the Nexus One fiasco.  Or just search google for the issue.

In my own experience with Google at work, I’ve had horrible, terrible, and just downright non-existent support on critical issues with Google Apps and Google Enterprise Support (both of which we are a paying customer).

A 7 day response time is about as good as a 700 day response time in today’s business world.  A phone number which we pay to have access to that is not answered in a time of need?  Unanswered requests by email and web forms?

Google has figured out how to manage vast quantites of talent to produce a wide array of successful products.  But if they continue to ignore their paying customers, it will take a toll on them that will be beyond repair.

If Google is reading this, remember that bad word of mouth is 100 times as fast spreading as good word of mouth.  I encourage you, Mr. Schmidt, to apply a resonable fraction of your vast resources to create the best customer service experience in the world.   Then, you will truly, do no evil.

Python 3 bytes indexing returns integers!

While converting a bunch of werkzeug code to Python 3.1, I ran into an issue with one of the bytes objects that was previously a string.

The line of code in question was originally this:

if value and value[0] == value[-1] == b'"':
   ...

If value is something, and the first and last characters are a quote character, then…

However, as it turns out, the bytes object is actually a list of integers in the range of 0-255.

So when you use an indexing operation on a byte, you actually get an integer back. For example:

>>> x = b'Hello World'
>>> x[0]
72

>>> x = 'Hello World'
>>> x[0]
'H'

Big difference, eh?