小编Mik*_*ter的帖子

从.bash_profile获取目录中的所有文件

我需要允许几个应用程序附加到系统变量(在这种情况下为$ PYTHONPATH).我正在考虑指定一个目录,每个应用程序都可以添加一个模块(例如.bash_profile_modulename).在〜/ .bash_profile中尝试过类似的东西:

find /home/mike/ -name ".bash_profile_*" | while read FILE; do
source "$FILE"
done;
Run Code Online (Sandbox Code Playgroud)

但它似乎不起作用.

bash shell scripting

43
推荐指数
3
解决办法
3万
查看次数

Meteor docs中的messages-count示例如何工作?

无法从文档中充分理解这个例子......我尝试了一些不同的方式运行它,以便我可以观察它是如何工作的,等等.

你怎么订阅这个?我们可以包含使这项工作所需的客户端代码吗?

有一个名为messages-count?的集合?是一个Room消息集合?我们可以在示例中包含集合定义吗?

有关这方面的任何提示都会很棒!

注意:这是最初发布此问题时出现的代码(2012年5月).它现在更简单了.

// server: publish the current size of a collection
Meteor.publish("messages-count", function (roomId) {
  var self = this;
  var uuid = Meteor.uuid();
  var count = 0;

  handle = Room.find({room_id: roomId}).observe({
    added: function (doc, idx) {
      count++;
      self.set("messages-count", uuid, "count", count);
      self.flush();
    },
    removed: function (doc, idx) {
      count--;
      self.set("messages-count", uuid, "count", count);
      self.flush();
    }
    // don't care about moved or changed
  });

  // remove data and turn off observe …
Run Code Online (Sandbox Code Playgroud)

javascript publish-subscribe mongodb meteor

41
推荐指数
1
解决办法
8298
查看次数

使Django模型中的瞬态(非数据库)属性可用于模板

我的一个模型具有未存储在数据库中的属性.视图和模型级别的一切都很好,但我似乎无法在模板中显示这些"非数据库"属性.

下面是一些示例代码,一个反映实际问题域的人工示例,用于演示不需要的行为.

风景:

def odometer(request):
    cars = Car.objects.all()
    for car in cars:
        car.read_meters()
    context = {'cars': cars}
    return render_to_response('odometer.html', context)
Run Code Online (Sandbox Code Playgroud)

型号:

class Car(models.Model):
    name = models.CharField(_('name'), max_length=100, unique=True)

    def read_meters(self):
        for meter in self.meter_set.all():
            meter.read()

    def __unicode__(self):
        return '%s' % self.name

class Meter(models.Model):
    name = models.CharField(_('name'), max_length=100)
    car = models.ForeignKey(Car)

    difference = 0
    previous = 0
    changed = False

    def read(self):
        # this is completely artificial. in the real application we would interface with the hardware
        # meter to get …
Run Code Online (Sandbox Code Playgroud)

oop django django-models

10
推荐指数
1
解决办法
5753
查看次数