使用某些第三方工具(如Terraform)时,指定AWS CLI配置文件并不容易,我更喜欢使用环境变量而不是配置文件.
我有没有办法让AWS CLI只将当前配置文件AWS_ACCESS_KEY_ID和AWS_SECRET_KEY环境变量导出到我的会话?
我目前在sqlite数据库中持久存在文件名以用于我自己的目的.每当我尝试插入具有特殊字符的文件(如é等)时,它会抛出以下错误:
pysqlite2.dbapi2.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.
Run Code Online (Sandbox Code Playgroud)
当我通过使用unicode方法将发送到pysqlite的值包装为"将我的应用程序切换到Unicode字符串"时unicode(filename),它会抛出此错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 66: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
我有什么办法可以摆脱这个吗?修改我的所有文件以符合不是一个选项.
更新
如果我通过解码文本filename.decode("utf-8"),我仍然得到上面的ProgrammingError.
我的实际代码如下所示:
cursor.execute("select * from musiclibrary where absolutepath = ?;",
[filename.decode("utf-8")])
Run Code Online (Sandbox Code Playgroud)
我的代码应该是什么样的?
我正在寻找自己编写的ExpandableListAdapter类似操作ArrayAdapter.我的数据模型是这样的:
public class Group {
private String name;
private List<Child> children;
}
public class Child {
private String name;
}
Run Code Online (Sandbox Code Playgroud)
很简单.如何将此关系映射到ExpandableListAdapter实现中?我现在正在SimpleExpandableListAdapter工作,但我需要对项目进行更多自定义控制(显示图标等).我该怎么办?
主要的是我需要一种add()方法来添加组,并在添加和从适配器中删除子项时使列表无效.我真的很惊讶SDK中没有一个实现(甚至是抽象的实现),这有助于实现这一点.
我试图简单地Site从模板中获取当前解析的电流:
<h3>{{ site.name }}</h3>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这并没有带来任何好处.
有没有办法从模板访问当前网站?
我需要在Ansible中创建一个包含单个事实内容的文件.我现在正在做这样的事情:
- template: src=templates/git_commit.j2 dest=/path/to/REVISION
Run Code Online (Sandbox Code Playgroud)
我的模板文件如下所示:
{{ git_commit }}
Run Code Online (Sandbox Code Playgroud)
显然,做这样的事情会更有意义:
- inline_template: content={{ git_revision }} dest=/path/to/REVISION
Run Code Online (Sandbox Code Playgroud)
Puppet提供类似的东西.有没有办法在Ansible中这样做?
我正在编写一个需要并行运行一系列任务的应用程序,然后运行所有任务结果的单个任务:
@celery.task
def power(value, expo):
return value ** expo
@celery.task
def amass(values):
print str(values)
Run Code Online (Sandbox Code Playgroud)
这是一个非常人为和过于简单的例子,但希望这一点很好.基本上,我有很多需要运行的项目power,但我只想运行amass所有任务的结果.所有这些都应该异步发生,我不需要从该amass方法返回任何东西.
有没有人知道如何在芹菜中设置它,以便一切都是异步执行的,并且在完成所有操作后调用带有结果列表的单个回调?
我已经设置了这个例子,以chord推荐Alexander Afanasiev:
from time import sleep
import random
tasks = []
for i in xrange(10):
tasks.append(power.s((i, 2)))
sleep(random.randint(10, 1000) / 1000.0) # sleep for 10-1000ms
callback = amass.s()
r = chord(tasks)(callback)
Run Code Online (Sandbox Code Playgroud)
不幸的是,在上面的例子中,tasks只有在chord调用方法时才会启动所有任务.有没有办法让每个任务可以单独启动,然后我可以添加一个回调到组,以便在一切都完成后运行?
我有一个AWS Auto-Scaling组,一个启动配置和一个Terraform中定义的自动扩展组策略,如下所示:
resource "aws_autoscaling_group" "default" {
name = "..."
health_check_type = "EC2"
vpc_zone_identifier = ["${...}"]
min_size = "${var.asg_capacity}"
max_size = "${var.asg_capacity * 2}"
desired_capacity = "${var.asg_capacity}"
launch_configuration = "${aws_launch_configuration.default.id}"
termination_policies = ["OldestInstance"]
}
resource "aws_autoscaling_policy" "default" {
name = "..."
autoscaling_group_name = "${aws_autoscaling_group.default.name}"
scaling_adjustment = "${var.asg_capacity}"
adjustment_type = "ChangeInCapacity"
cooldown = 300
}
resource "aws_launch_configuration" "default" {
name_prefix = "..._"
image_id = "${var.coreos_ami_id}"
instance_type = "${var.ec2_instance_type}"
iam_instance_profile = "${aws_iam_instance_profile.default.arn}"
key_name = "..."
security_groups = ["${aws_security_group.default.id}"]
user_data = "${data.template_file.cloud_init.rendered}"
lifecycle { …Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-cloudformation autoscaling terraform
我需要从许多不同来源提取银行账户报表.我希望能够以某种标准化的方式获取这些数据,无论是CSV还是OFX或XML等等.我只需要能够获得这些数据.我将使用自己的帐户来获取交易,因此不应该有太多"合法"问题.像Mint.com这样的网站如何获得银行对账单?他们只是询问您的帐户信息,URL,然后他们就会关闭并运行.我怎样才能做到这一点?
似乎有一段时间,Unix系统上的登录实用程序仅在存在有效用户名时才计算哈希值; 这打开了一个安全漏洞,允许进行定时攻击,因为用户可以通过生成散列密钥进行比较所需的时间来确定何时找到用户名.
这对桌面应用程序有意义,但它对Web应用程序也有意义吗?我倾向于这样做,但这种修复是必要的吗?
例如,在Django auth模块中:
class MyBackend(ModelBackend):
def authenticate(self, email=None, password=None):
try:
user = User.objects.get(email=email)
return user if user.check_password(password) else None
except User.DoesNotExist:
User().check_password(password) # is this line necessary?
return None
Run Code Online (Sandbox Code Playgroud)
额外的哈希计算是否适合这种情况?如果我在auth呼叫上使用速率限制,这是否会降低像这样的定时攻击的可能性?
我有一个开发服务器,我经常推动代码更改通过Git.每次推送后,我需要手动登录服务器并重新启动管理程序进程.
有没有办法让Supervisor监视文件系统目录以进行更改并重新加载更改过程?
python ×2
android ×1
ansible ×1
autoscaling ×1
aws-cli ×1
banking ×1
celery ×1
django ×1
django-sites ×1
django-views ×1
ofx ×1
pysqlite ×1
rabbitmq ×1
security ×1
sqlite ×1
supervisord ×1
terraform ×1