[python] pipeline design

Pipeline framework like assembly line in manufactory.

Image that:

  • A kind product consists of several steps to produce
  • Each step only has one worker
    • A worker can only handle one step
    • A worker can't work in parallel, must handle one by one.
    • Once the worker finished this step, he pass the product to next worker(step)
  • There are a great number of product for manufactorying.
    • In order to improve efficiency, each woker must be in full load.

Falcon: Django-like urlreverse router

The default Falcon router don't support urlreverse, but fortunately it allows us to use a costomized router.

Override the add_route, adding a aditional params name to specified url template name.

Note: Falcon version should >=0.4 to support this feature.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from falcon.routing import DefaultRouter


class ReverseRouter(DefaultRouter):
    url_map = {}

    # override add_route to add our map
    def add_route(self, uri_template, method_map, resource, name=None):
        if name:
            self.url_map[name] = uri_template
        DefaultRouter.add_route(self, uri_template, method_map, resource)

    def reverse(self, _name, **kwargs):
        '''
        reverse url
        '''
        assert _name in self.url_map, "url name: %s not in url map" % _name
        url_tmpl = self.url_map.get(_name)
        return url_tmpl.format(**kwargs)

OruxMaps 添加 Google Maps (国内源)

ruxMaps 从5.5 之后由于版权问题,就移除了Google Maps,网上已经有很多修改onlinemapsources.xml的方案了。

但是基本上都是用google.com的源,因为你懂得的原因,基本上不用科学上网,很难访问。

下面我修改了一版,是基于google.cn,在墙内下载也毫无鸭梨:

[python] os.system output out-of-order using shell pipe

t.py as below:

1
2
3
4
5
import os

print "### before ps"
os.system("ps")
print "### after ps"

logical is quite simple, if we directly run it: python t.py, output as below, nothing special:

1
2
3
4
5
6
7
### before ps
  PID TTY          TIME CMD
 1619 pts/9    00:00:00 python
 1620 pts/9    00:00:00 sh
 1621 pts/9    00:00:00 ps
18701 pts/9    00:00:00 bash
### after ps

[Android] wrong playback state when playing MIDI as Ringtone

The Problem

  1. play a MIDI file as Ringtone.
  2. check whether .isPlaying() after .play()
1
2
3
4
      Uri midiUri = Uri.parse( "/sdcard/some/path/to/example.midi");
      Ringtone ringtone = RingtoneManager.getRingtone(mContext, midiUri);
      ringtone.play();
      assertTrue("Couldn't play ringtone " + midiUri, ringtone.isPlaying());

The problems is that the last line always fails.