试图用PIL 创建一个透明的gif.到目前为止我有这个:
from PIL import Image
img = Image.new('RGBA', (100, 100), (255, 0, 0, 0))
img.save("test.gif", "GIF", transparency=0)
Run Code Online (Sandbox Code Playgroud)
到目前为止,我发现的一切都是指操纵现有图像来调整透明度设置或将透明图像叠加到另一个上.我只想创建一个透明的GIF(然后绘制).
考虑以下C程序(test.c):
#include <stdio.h>
int main() {
printf("string out 1\n");
fprintf(stderr, "string err 1\n");
getchar();
printf("string out 2\n");
fprintf(stderr, "string err 2\n");
fclose(stdout);
}
Run Code Online (Sandbox Code Playgroud)
哪个应该打印一行到stdout,一行到stderr,然后等待用户输入,然后另一行到stdout,另一行到stderr.非常基本!在编译并在命令行上运行时,程序的输出完成(收到getchar()的用户输入):
$ ./test
string out 1
string err 1
string out 2
string err 2
Run Code Online (Sandbox Code Playgroud)
尝试使用带有以下代码的nodejs将此程序生成为子进程时:
var TEST_EXEC = './test';
var spawn = require('child_process').spawn;
var test = spawn(TEST_EXEC);
test.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
test.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
// Simulate entering data for getchar() after 1 second
setTimeout(function() { …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用mongoose的内置继承功能(而不是扩展插件)但到目前为止还没有太多运气.这是我尝试使用的代码的简化示例,它表现出相同的问题.这是基于使用鉴别器的模式继承的mongoose文档的扩展版本 - http://mongoosejs.com/docs/api.html#model_Model.discriminator
var util = require('util');
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/problem');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
function BaseSchema() {
Schema.apply(this, arguments);
this.add({
name: String,
createdAt: Date
});
}
util.inherits(BaseSchema, Schema);
var BossStatusSchema = new Schema({
status: String
});
var BossStatus = mongoose.model('BossStatus', BossStatusSchema);
var PersonSchema = new BaseSchema();
var Person = mongoose.model('Person', PersonSchema);
var BossSchema = new BaseSchema({
department: String,
bossStatus: {
type: ObjectId,
ref: 'BossStatus'
}
});
var Boss = Person.discriminator('Boss', BossSchema);
Run Code Online (Sandbox Code Playgroud)
添加文档的示例代码:
var superBoss …Run Code Online (Sandbox Code Playgroud) 使用节点但在JavaScript中寻找钻石继承的方法:
var util = require('util');
function Base(example_value) {
console.log(example_value);
this.example_property = example_value;
this.example_method = function() { ... };
}
function Foo(settings) {
var f = settings.f;
Base.call(x);
this.settings = settings;
}
util.inherits(Foo, Base);
function Bar(settings) {
var b = settings.b;
Base.call(b);
this.settings = settings;
}
util.inherits(Bar, Base);
var foo = new Foo({f: 'bar'});
// 'bar' gets printed and I can call methods from Base..
foo.example_method();
var bar = new Bar({b: 'foo'});
// 'foo' gets printed and I can call methods …Run Code Online (Sandbox Code Playgroud) 想知道是否有办法编写if语句的三元或更短形式,当满足if时,将'a'元素添加到表格单元格.
我试过这个,但它不起作用:
td= foo.x ? a(href="/#{foo.x}/foobar") View : '-'
Run Code Online (Sandbox Code Playgroud)
以下确实有效,但是很长很啰嗦和不整洁.
tbody
each foo in bar
tr
td= foo.name
if foo.x
td
a(href="/#{foo.x}/foobar") View
else
td -
if foo.y
td
a(href="/#{foo.y}/hello") Hello
else
td -
Run Code Online (Sandbox Code Playgroud)
谢谢
我只是试图在帮助器中按名称引用铁路由器路由,而不是硬编码URL.因此,当用户单击按钮时,它们将被重定向到具有来自按钮的data-id属性的id的项路由.
items.html
<button class="btn btn-default btn-xs pull-right" data-id={{_id}}>View</button>
Run Code Online (Sandbox Code Playgroud)
items.js
Template.items.events({
'click button': function(e) {
// This works but is hard coding the path
Router.go("/item/" + ($(e.currentTarget).data('id')));
// This doesn't work but is there an alternative method of doing this
Router.go(pathFor('item' id=_id))
}
});
Run Code Online (Sandbox Code Playgroud)
router.js
Router.route('/item/:_id', {
name: 'item'
});
Run Code Online (Sandbox Code Playgroud)
我当然可以在这样的模板中使用pathFor:
<a href="{{pathFor 'item' id=_id}}">View</a>
Run Code Online (Sandbox Code Playgroud)
或者指定数据属性:
<button class="btn btn-default btn-xs pull-right" data-path={{pathFor 'item' id=_id}}>View</button>
Run Code Online (Sandbox Code Playgroud)
但是想知道是否有替代/更简洁的方法来做到这一点?如果不是,我可能会恢复使用标签.
inheritance ×2
node.js ×2
gif ×1
imaging ×1
iron-router ×1
javascript ×1
meteor ×1
mongoose ×1
populate ×1
pug ×1
python ×1
spawn ×1
stdout ×1
transparency ×1
unbuffered ×1