小编Ale*_*ord的帖子

画布弧清除

如何覆盖HTML5画布弧?我推测这段代码可以正常工作,但它留下了一个边框,尽管事实上它的值完全相同,只是一个不同的颜色..是否有一个我不知道的边界属性?

<!DOCTYPE html>
<html>
  <head>
    <title>Test</title>
  </head>
  <body>
  <canvas id="surface" width="300" height="300"></canvas>

  <script type="text/javascript">
      var canvas = document.getElementById('surface');
      var ctx = canvas.getContext('2d');

      ctx.fillStyle = 'black';
      ctx.beginPath();
      ctx.arc(100, 100, 20, 0, Math.PI * 2, true);
      ctx.fill();

      ctx.fillStyle = 'white';
      ctx.beginPath();
      ctx.arc(100, 100, 20, 0, Math.PI * 2, true);
      ctx.fill();
  </script>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

javascript html5 canvas html5-animation

6
推荐指数
1
解决办法
5619
查看次数

ManyToManyField with through 抽象模型

这里有一个有趣的..我缩短了模型以使其更容易理解..

class Participant(Person):
    passport_number = models.IntegerField(verbose_name=_('Passport Number'), db_column=u'PassportNumber')

    class Meta:
        db_table = u'Participant'

class Journey(BaseModel):
    participants = models.ManyToManyField(Participant, related_name='%(app_label)s_%(class)s_participants', through=u'ParticipantJourney')

    class Meta:
        abstract = True

class PlaneJourney(Journey):
    flight_number = models.CharField(max_length=16, verbose_name=_('Flight Number'), db_column=u'FlightNumber')

    class Meta:
        db_table = u'PlaneJourney'

class ParticipantJourney(BaseModel):
    participant = models.ForeignKey(Participant, verbose_name=_('Participant'), db_column=u'ParticipantId')

    journey_content_type = models.ForeignKey(ContentType, related_name='journey_content_type')
    journey_object_id = models.PositiveIntegerField()
    journey = generic.GenericForeignKey('journey_content_type', 'journey_object_id') # models.ForeignKey(Journey, verbose_name=_('Journey'), db_column=u'JourneyId')

    payment_content_type = models.ForeignKey(ContentType, related_name='payment_content_type')
    payment_object_id = models.PositiveIntegerField()
    payment = generic.GenericForeignKey('payment_content_type', 'payment_object_id') # models.ForeignKey(Payment, verbose_name=_('Payment'), db_column=u'PaymentId')

    class Meta:
        db_table = u'ParticipantJourney' …
Run Code Online (Sandbox Code Playgroud)

python django many-to-many abstract django-orm

5
推荐指数
1
解决办法
2043
查看次数

并行运行Jest测试的子集

我们使用Jest来支持Node.js测试,这些测试与Postgres数据库交互以测试CRUD操作.我们目前正在通过--runInBandCLI选项以确保我们的测试是串行操作的,这样可以正常工作但显然比我们想要的慢.

现在从阅读(和以前的经验)我发现能够将测试组标记为可并行化是有用的.这可以在python中使用nose,但我似乎无法在Jest中找到语法.这可能吗?或者是否有另一种方法来加速Jest提倡的数据库(或状态限制以推广)测试?

谢谢,亚历克斯

postgresql node.js ecmascript-6

5
推荐指数
1
解决办法
788
查看次数

使用参数数组(包括多行字符串)调用 bash 函数

所以我有一个函数,我想解压参数数组以形成参数序列:

#!/usr/bin/env bash

my_func() {
    echo "IN LEN: $#"  # Gives "6" -> Should be "4"
    echo "IN: $@"  # Gives "--a 1 --b 2 3 4" -> Should be "--a 1 --b 2\n3\n4"
}


read -r -d '' MULTI << EOM
2
3
4
EOM

ARGS=("--a" "1" "--b" "$MULTI")
echo "OUT LEN: ${#ARGS[@]}"  # 4
echo "OUT: ${ARGS[@]}"  # "--a 1 --b 2\n3\n4"

my_func ${ARGS[@]}
Run Code Online (Sandbox Code Playgroud)

这个例子演示了这个问题和我的期望。也许设置有一些魔法IFS?有什么建议么?

附言。如果您需要更多上下文,请参阅我原来的问题:处理可选函数参数

bash

0
推荐指数
1
解决办法
797
查看次数