Friday 24 December 2010

iPod Touch photos

I've got a few minutes before I head off to play squeeze in the metro door with the rest of the sardines on my way to People's Square, so here's the rest of my iPod Touch pictures. When I got this doodad, I thought "coo, a portable camera thingy so I don't have to lug around my Canon." But really, it is a super-heavy music player, a grainy camera, and a small screen that isn't near big enough to use for any real purpose comfortably. My cheap Sansa Clip music player that I got off Woot.com weighs a tenth as much, if that. Anyway, here's the pictures.

Work provides lunch to workers in offices in every country. One of the most popular is the Thai restaurant, and the rice goes before I get there (I wait until the queue is gone). Here's a grainy picture of whatever I scraped together from what was left, there was one spoonful of rice left. But there was coriander this day, which was a bonus and is not usually there.

2010-12-20 - Work lunch - Thaihouse

Walking to Burger King to meet a friend, I passed this Christmas tee-pee celebrating native Americans or something.

2010-12-20 - Jingan Temple - 01 - Lit teepee or something 2010-12-20 - Jingan Temple - 02 - Lit teepee or something

And at Burger King, they were late so I ordered something. So many things on the menu, and nothing satisfies.

2010-12-20 - Burger King - Spicy burger meal

Power Restaurant

This place is just outside the subway stop where I live. I got a bit tired of the mutton kebabs that were sold on the street there, and decided to wander in. They do not speak English and the menu is written in Chinese characters.

2010-12-19 - Power Restaurant - 01 - Menu Front 2010-12-19 - Power Restaurant - 02 - Menu Back

They give you a number and your receipt, and you go sit at a table to wait for what you ordered.

2010-12-24 - Power Restaurant - 01 - Table number

First my dumplings arrived. I have no idea how to eat these, often they are filled with juice and it squirts all over my chopstick hand. Still, at least that's better than squirting all over my clothes :-)

2010-12-24 - Power Restaurant - 02 - Delicious fried pork something

Then my "delicious fried pork something" arrived. I call it that, because I began drawing the characters on my receipt into my iPod app and that's as far as I got. It wasn't easy, the receipt is as grainy as these iPod pictures.

2010-12-24 - Power Restaurant - 03 - Dumplings

Power is cheap and tasty. I plan on stopping there often, but I'm going to try and spoil my dinner less. Looking at the below receipt, the dumplings were 4 RMB and the pork something was 6 RMB.

2010-12-24 - Power Restaurant - 04 - Receipt

Anyway, I have to stop posting pictures and get to studying my Mandarin vocabulary for the night and then head out to People's Square to meet up.

Supermarket snacks

I bought several snacks at either the supermarket down the road, or the corner store that is situated mid-block across the road.

100% something blueberry drink. I hope it's 100% blueberry juice.

2010-12-18 - Blueberry Juice

Blueberry yogurt. Better than a packet of potato chips, for sure.

2010-12-13 - Snacks - 01 - Blueberry Yogurt

And an innards shot so you can see the level of fruitiness.

2010-12-13 - Snacks - 02 - Blueberry Yogurt

Noodle Bar

Unspectacular hamburgers are par for the course in Shanghai. And nowhere do they make a more unspectacular hamburger than at Carls' Jr. Sure they make worse ones at McDonalds and Burger King, but I want something I appreciate eating more than I appreciate the idea of what it could have been. I often walk out of Carls' Jr and look at the noodle bars nearby and think how I should have gone there. So, this one day I zigged left to the Noodle Bar when I would have otherwise zagged right into Carls' Jr.

2010-12-04 - Noodle Bar - 01 - Restaurant

This is not my hand. But it is the menu on the wall beside the entrance to this restaurant.

2010-12-04 - Noodle Bar - 02 - Outside Menu

The ordered dish. It was okay, but it was just noodles in soupy water. You can get those out of a packet and cook them up in two minutes at home thanks to Maggi. Throw in some gristly meat and Robert is your father's brother.

2010-12-04 - Noodle Bar - 03 - Dish

Marks and Spencer christmas cake

A good piece of christmas cake and a cup of tea are my favourite part of Christmas. What better way to celebrate whatever it was the pagans did that was covered up with whatever it is that Jesus was supposed to have done. Christmas cake however, is not easy to find in Shanghai. However, wandering around Marks and Spencer to buy some socks and check out western sized shoes, I caught sight of a stack of these and chucked one in my basket.

2010-12-04 - Marks and Spencer - 01 - Christmas Cake

It was okay. In my book, finding a good christmas cake is rare, so finding one that is edible with the help of the royal icing that it has to be partly comprised of is better than nothing.
2010-12-04 - Marks and Spencer - 02 - Christmas Cake Slice
I went back last weekend, but they were sold out and only had some bullshit tree cake or some such thing.

Junk food update

I bought another batch of random items to snack on several weeks back.

2010-12-07 - Junk Food - 01 - Overview

The dried fruits were very cheap, like around 3 RMB a packet. In an ideal world, these would be unflavoured and would taste like the dried fruit they actually are. But in a world of Chinese taste preferences, these taste like.. they're coated in some.. well I don't know how to describe it. Kind of like a mix of floor cleaner and armpit, if I were to just pick a description that went for measuring the lack of appeal the flavour has for me.
2010-12-07 - Junk Food - 02 - Dried fruits

Now dried fish unflavoured is also good. But when you coat it in sugarish flavour, and other stuff, then it's just semi-moist feeling dried fish with sugarish flavour. The packet on the left was relatively untainted by flavouring.. so was less disappointing.
2010-12-07 - Junk Food - 03 - Dried fish

I like snacking on Sunmaid dried raisins. What's not to like with a mouthful of sugar in some form of carbohydrate? These were pretty innocuous, and I ate a mouthful before biffing the packet.
2010-12-07 - Junk Food - 04 - Sultanas

Chinese Character Learning

Managed to find a large cheapish pad of gridded paper for practicing my chinese characters on, at the supermarket over the road. Strangely for all the school stationary, there's nothing approaching the grid paper we have in European countries to learn mathematics on.

2010-12-09 - Hanzi Writing Paper

Christmas Present

The company I work for gives excellent Christmas presents. The first year I worked for them, they bought me a plane ticket home (pretty much from the antipodes of NZ). In subsequent years, the presents have been an Xbox of some sorts (swapped for in-store credit to get a Nintendo DS), a coffee machine (subsequently given to a friend unused when I left the country), a Playstation 3 (given to my brother as an Xmas present) and this year the following geegaw.

2010-12-24 - Employer Christmas Present
Employees were given the chance to upgrade (at personal cost) to other Apple doodads like iPhones or iPads. I opened mine with the intent to use the camera to take photos while out and about in China. Having downloaded a free Chinese/English dictionary app, I can draw characters I see on it and work out what them mean. The office announcement suggested useful scenarios like being able to video chat with other people wherever they may be in the office.. over the office wifi. Indeed, that does sound pretty swank.

Friday 17 December 2010

Pickling

One of the use cases I have for unpickling is context-dependent whitelisting. You can easily do this by instantiating an Unpickler object and setting a replacement find_globals method on it.

        def find_global(moduleName, className):
t = namespaceSubstitutions.get((moduleName, className), None)
if t is not None:
moduleName, className = t

mod = __import__(moduleName, globals(), locals(), [])
# This won't have given us "X.B", but rather "X". So get "B" from "X".
idx = moduleName.rfind(".")
if idx != -1:
subModuleName = moduleName[idx+1:]
mod = getattr(mod, subModuleName)

obj = getattr(mod, className)
if moduleName +"."+ className in namespaceWhitelist or moduleName in namespaceWhitelist:
return obj
raise cPickle.UnpicklingError("%s.%s is not whitelisted for unpickling" %
(moduleName, className))

unpickler = cPickle.Unpickler(StringIO(packet))
unpickler.find_global = find_global

return unpickler.load()
This allows a whitelist to be enforced for specific cases where unpickling is done, perhaps for objects coming over the wire, but not for objects read from disk.

Another use case I have, this time for pickling, is to transform objects that are being pickled into forms that are compatible with whatever is unpickling them. Let's say your server application is built using a complicated and heavyweight framework that whatever machine it is running on literally groans at the effort of having to do so. Let's call it Twifted [1]. Your client application however has to be extremely lightweight, and doesn't have all the need for functionality that the server application does. So in order to make programming on the server more natural, you allow programmers to send objects in handy Twifted form over the wire to the client. Perhaps as return values from your RPC calls.

In order to do this, you hook into pickling. Now copyreg.pickle allows you to install global functions that can transform objects before they get pickled. But you want to do it on a case by case basis. It needs to be done for the objects that get sent over the wire, but not for the ones that go to disk. But the Pickler object doesn't have a friendly overridable function to allow you to do this, in much the same way find_globals does for Unpickler.

This is one possibility:
reducers = {}

def register_pickle_convertor(source_type, convertor_func):
global reducers
# Use the limited copy_reg API to do a trial install and to validate its correctness.
copy_reg.pickle(source_type, convertor_func)
# Now unregister it directly, because there is no API to do this.
del copy_reg.dispatch_table[source_type]

# Put the validated reducer in our back pocket for use as required.
print "Registered sake RPC convertor for objects of type %r" % source_type
reducers[source_type] = convertor_func

def modified_cPickle_dumps(obj):
global reducers
copy_reg.dispatch_table.update(reducers)
try:
return cPickle.dumps(obj, cPickle.HIGHEST_PROTOCOL)
finally:
# Remove our influence.
for source_type in reducers:
del copy_reg.dispatch_table[source_type]
I haven't put that much thought into it, but I'd like to find a better solution.

[1] I've never used Twisted, and the choice of this name has no bearing on all the suggestions to do so that I have ignored over the years.

Thursday 16 December 2010

unittest.py quirk

Now I am using Python 2.7, and whatever form of unittest module that comes with it. Maybe this is fixed over in the (still not relevant to me) 3.x branches. Anyway, oftentimes I will create some simple mocking in the setUp method of my test case, and then the test method will error in a way that is unrelated to my mocking. But error handling of tests happens before tearDown is called and it will collide with my mocking, so instead of finding out about what test failed I find out about this collision.

It goes something like this.

class MyTESTSSSS(unittest.TestCase):
def setUp(self):
self.oldOpen = open
__builtin__.open = ReplacementOpenFunc

def testSomething(self):
1/0
Of course, that may not reproduce the problem, it's just for the purpose of illustration. Anyway, what's my point.. oh, in order to work around this, I now have to structure my tests in a way that enforces pre-error teardown.
class MyTESTSSSS(unittest.TestCase):
def setUp(self):
self.oldOpen = open
__builtin__.open = ReplacementOpenFunc

def preErrorTearDown(self):
__builtin__.open = self.oldOpen

def testSomething(self):
try:
self._testSomething()
finally:
self.preErrorTearDown()

def _testSomething(self):
1/0
Anyone else encounter this problem and take any different approaches to recovering from it?

If the answer involves a mocking framework, decorators, or context managers, then it is the wrong answer for me :-)

test_repr.py

Note to self. test_repr.py in the Python test suite does lots of long file name based tests. However, you don't need to have your source code under too many sub-directories on Windows before a test hits the path length limit and fails unwittingly. I think in my case it was c:\Users\MyName\Stackless\stackless-branches\release27-maint\release27-maint-export\release27-maint\...

Wednesday 24 November 2010

Street food dinner

I dropped by the supermarket to pick up some organic vegetables, but was short on money and too lazy to go buy some meat. And eating vegetables without meat is one of those nonsensical religious notions, so I was in a quandary.

Fortunately the first thing I saw coming out of the metro entrance, was the kebab barbecuing man. I ordered five at 2 RMB a piece, for a total of 10 RMB (~ 2 NZD). The vendor doesn't even ask me any more if I want the spicy red stuff shaken over the top of them, he just does it. Small remote control included for size perspective.

2010-11-24 - Shanghai - Street Vendor - 01 - Mutton kebabs

I was gnawing on one of the kebabs, and I spotted the bread vendor. She sells bread for 1 RMB a piece, which you can then optionally slather with chilli paste. So in order to satisfy my vegetable requirements, I ordered two for a total of 2 RMB (~ 0.4 NZD).

2010-11-24 - Shanghai - Street Vendor - 02 - Bread slathered with chilli paste

And the resulting barbequed spicy mutton chilli sandwich looks as follows.

2010-11-24 - Shanghai - Street Vendor - 03 - Mutton chilli sandwiches

Really the kebabs are best eaten hot off the barbeque, but I decided to do this on a whim instead. The most interesting part is actually seeing how they cook all these things on the spot, so I still need to take my camera out one of these nights.

Junk food update

I was at the supermarket a couple of nights ago and was lacking energy, so seeing these gummy candies at the counter I only bought them because they had probiotics and looked packed with goodness.

2010-11-21 - Shanghai - Junk Food - 01 - Yake grape candy

In fact, as each individual lolly is individually wrapped, I believe these actually legally qualify as medicine. Regardless, having eaten them all I lacked the reinvigoration I had expected to get from eating them.

2010-11-21 - Shanghai - Junk Food - 02 - Yake grape candy

In the supermarket tonight, I didn't have anything to eat and having eaten some street vendor deep fried radish lumps, I felt like my essential fats and carbs were taken care of. So surely these savoury and spicy looking squares would either be pork or tofu, providing me with protein?

2010-11-23 - Shanghai - Junk Food - 01 - Spicy rubber squares packet

Bland and tasteless, must be tofu. I did not bother eating more than a couple and even then I just ate them to get some food in my stomach. They were rubbery and oily.

2010-11-23 - Shanghai - Junk Food - 02 - Spicy rubber squares

I really need to get a smaller camera so I can take photos out and about, rather than taking them at home with my larger camera.

Tuesday 23 November 2010

Street food yet again again

I live at a non-central metro stop now, and depending on the time of day there are a range of street vendors selling different kinds of food. In the morning, there's the dude who cooks the pancake sandwich things. In the evening, there's the guy barbecuing mutton kebabs. Also in the evening are a range of other vendors, selling pieces of bread they've baked on their cart, different vegetables and meat which you can select and have cooked, various goods which are deep fried and so forth.

The key obstacle to purchasing something for me, is queuing. I am too late in life to spend time standing around waiting for something, especially in a country where they do not queue but rather crowd around. So it took me a while to get around to trying what I uneducatedly call "pancake sandwich things".

These are only sold in the morning, which is a pity because I would buy them whenever I pass!

2010-11-21 - Shanghai - Street Vendor - 01 - Pancake sandwich

The vendor basically has a large flat griddle. He breaks an egg onto it, spreads it round roughly to cover the surface. Then he breaks another egg onto it and spreads that on top to get a more consistent layer. Next he sprinkles chopped pieces of two green herbs on top, one is coriander and the other one is possibly green onion. Once the thing is cooked enough, he folds it over, breaks a crispy deep fried wafer of sorts into it. Spreads ground chilli onto it, then brown paste over that. Then folds it up, cuts it in half and you end up with the two pieces you see.

2010-11-21 - Shanghai - Street Vendor - 02 - Pancake sandwich

I've bought them twice now. Once for 3 RMB at a vendor more in the Jing'an area, and another time for 2.5 RMB at a vendor just outside my metro stop (these ones here). You would think what would define the taste would be egg and fried wafer, but really the taste that stands out if the fresh herbs, especially the sharp freshness of the coriander.

Wednesday 17 November 2010

Junk food update

Another batch of fortifying non-traditional cold medicine.

2010-11-14 - Shanghai - Junk Food - 03 - Four somethings

Chocolate and coconut are two flavours which go together, so biscuits on the shelf that promise to combine both are worth trying.

2010-11-14 - Shanghai - Junk Food - 05 - Nisson Butter Coconuts Chocolate packet

Tasting nothing like coconut or chocolate, I barely ate a mouthful and threw the packet out.

2010-11-14 - Shanghai - Junk Food - 09 - Nisson Butter Coconuts Chocolate biscuit

This Glico brand seems quite reputable. Decided to buy some of their chocolate cookies.

2010-11-14 - Shanghai - Junk Food - 04 - Glico Q-Cookie Chocolate packet

I'd make a joke about how some lady left behind a container full of dog leavings which she'd been picking up, but I don't know what that would be doing here. These were okay, but too small to really satisfy.

2010-11-14 - Shanghai - Junk Food - 08 - Glico Q-Cookie Chocolate biscuits

Dried fish is always good. And they have a variety of it here in the supermarkets.

2010-11-14 - Shanghai - Junk Food - 07 - Dried fish packet

Unfortunately, this is too sweet. The sweetness takes away from the savoury taste of dried fish that makes it satisfying. And the fish tastes.. moist. Way to ruin something good fish packagers.

2010-11-14 - Shanghai - Junk Food - 11 - Dried fish

These looked like the only dried kiwifruit that is not coated in sugar.

2010-11-14 - Shanghai - Junk Food - 06 - Dried kiwifruit packet

In fact, they seem to be just dried. Although again, dried food that doesn't have the feel and texture of something dehydrated. Moist tasting again.

2010-11-14 - Shanghai - Junk Food - 10 - Dried kiwifruit pieces

Junk food update

In order to fortify oneself against the flu here, one needs to consume an abundance of energy and forget that nutrition gobble gook. Protective layers of fat are what one needs. To that end, I have been building up mine with the following items.

Haochi means delicious, so therefore these were an easy choice out of the hotel vending machine. I think they cost 6 RMB.

2010-11-07 - Shanghai - Junk food - 01 - Haochidian packet

They would be good with a cup of tea, if I could drink milky tea anymore. Not a bad flavour, but I think delicious is hopeful thinking.

2010-11-07 - Shanghai - Junk food - 02 - Haochidian biscuits

Dried apricots are always a good bet. I think this packet cost 2 RMB from the hotel vending machine, they must only refill the vending machine once a month, so it'll be another 30 days before I can eat more as the slot they are served from is now empty.

2010-11-07 - Shanghai - Junk food - 03 - Xing Pu packet

Yep, look and taste just like dried apricots even if they are called xing pu here.

2010-11-07 - Shanghai - Junk food - 04 - Xing Pu pieces

Chocolate collon, there's a joke here somewhere. Well anyway, they taste pretty good and a box is only 6 RMB from the vending machine. The filling is a little slimey for my liking.. but hey.

2010-11-07 - Shanghai - Junk food - 05 - Chocolate Collon packet

Here's what the pieces look like.

2010-11-07 - Shanghai - Junk food - 06 - Chocolate Collon pieces

One thing I like about some of the fruit drinks here in China, is that they are not just a sugar-laden fruit flavoured drink. They are also saturated with actual fruit, particles or chunks of the fruit flesh inside.

2010-11-07 - Shanghai - Junk food - 07 - Peach Juice packet

Work had these little packets with small coffee-flavoured cake things inside. So, looking for the brand in the supermarket across the road and up the stairs, here's what I found.

2010-11-14 - Shanghai - Junk Food - 01 - Lotte Capuccino packet

Not quite the same, but at least I can take heart in the way they share the wholesome sheen of the picture on the packet. The ones at work had a brown filling, less reminiscent of some rancid white cream.

2010-11-14 - Shanghai - Junk Food - 02 - Lotte Capuccino piece