小编Cla*_*lay的帖子

将Python客户端用于Google服务帐户file_cache时,"ImportError:file_cache不可用"

我正在使用G Suite的服务帐户进行完整的域名授权.我有一个只读访问Google日历的脚本.该脚本工作正常,但在"构建"服务时抛出错误(在后台线程上?).这是代码:

from oauth2client.service_account import ServiceAccountCredentials
from httplib2 import Http
import urllib
import requests
from apiclient.discovery import build

cal_id = "my_calendar_id@group.calendar.google.com"

scopes                = ['https://www.googleapis.com/auth/calendar.readonly']
credentials           = ServiceAccountCredentials.from_json_keyfile_name('my_cal_key.json', scopes=scopes)
delegated_credentials = credentials.create_delegated('me@mydomain.com')
http_auth             = delegated_credentials.authorize(Http())

# This is the line that throws the error
cal_service  = build('calendar','v3',http=http_auth)

#Then everything continues to work normally
request = cal_service.events().list(calendarId=cal_id)
response = request.execute()

# etc...
Run Code Online (Sandbox Code Playgroud)

抛出的错误是:

WARNING:googleapiclient.discovery_cache:file_cache is unavailable when using oauth2client >= 4.0.0
Traceback (most recent call last):
  File "/Users/myuseraccount/anaconda3/lib/python3.5/site-packages/googleapiclient/discovery_cache/__init__.py", line 36, in autodetect …
Run Code Online (Sandbox Code Playgroud)

python google-calendar-api

39
推荐指数
2
解决办法
1万
查看次数

如何在Rails 3.1资产管道中正确使用jQuery?

我正在开发一个爱好应用程序并使用一些jQuery.结果很好,但我是一个jQuery noob,我认为我可以对代码结构做一些重大改进.暂且不考虑Coffescript,我一直想知道的一件事是如何.js在资产管道中正确使用特定于模型的文件.

例如,在使用我的用户模型时,我可能会在文档准备好时运行一些我想要运行的代码.假设我把它放在Rails 3.1生成$(document).ready(function() {...});users.js文件中.

第二天,我正在使用Pet模型,我想要在文档准备好的情况下运行代码.我把它放在Rails准备$(document).ready(function() {...});pets.js文件的另一个内部.

这是我的问题出现的地方:

  1. 应用程序运行时如何编译?
  2. 我用上面的例子实例化了两个jQuery实例吗?
  3. 我应该只$(document).ready(function() {...});在应用程序中使用一次,还是Rails将我的代码编译成单个调用?
  4. 什么属于特定于模型的.js文件?
  5. 它在开发和生产模式中的执行方式是否存在差异?

jquery ruby-on-rails ruby-on-rails-3.1 asset-pipeline

16
推荐指数
1
解决办法
2863
查看次数

Rails gem rails3-jquery-autocomplete:如何查询多个字段

我正在使用rails3-jquery-autocomplete这里找到的宝石:http://github.com/crowdint/rails3-jquery-autocomplete

有关如何查询模型的单个属性的说明很明确,我可以毫无问题地完成这项工作.

但是,我的Person模型有两个属性,我想要组合和查询.他们是first_namelast_name.我想将它们组合成一个名为的伪属性full_name.目前,我收到此错误:

ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: full_name: SELECT     "people".* FROM       "people"  WHERE     (LOWER(full_name) LIKE 'cla%') ORDER BY  full_name ASC LIMIT 10):
Run Code Online (Sandbox Code Playgroud)

full_name虽然我在Person模型文件中有以下方法,但是没有Person模型的属性:

def full_name
  "#{self.first_name} #{self.last_name}"
end
Run Code Online (Sandbox Code Playgroud)

如何修改Person模型文件以便调用full_name查询数据库以匹配first_namelast_name?的组合?

activerecord model autocomplete ruby-on-rails

14
推荐指数
2
解决办法
7871
查看次数

在Ruby on Rails中将纯文本URL转换为HTML超链接?

我有一个文本区域,用户可以在其中输入大量可能包含超链接的文本.如何显示文本并使URL自动显示为超链接?是否有宝石,插件或现有方法来做到这一点?我希望能够做到这样的事情:
<%=h @my_object.description.with_links %>在我看来.

ruby-on-rails

12
推荐指数
1
解决办法
6049
查看次数

Obj-C:计算NSNumber对象的NSArray的标准偏差?

如果我有一个NSArrayNSNumber对象,我怎么计算数组中的数字的标准偏差?

cocoa objective-c

11
推荐指数
2
解决办法
8209
查看次数

如何在python ggplot中创建条形图?

我正在使用yhat的ggplot库.我有以下pandas DataFrame:

   degree  observed  percent observed  expected  percent expected
0       0         0               0.0         0          0.044551
1       1         1               0.1         1          0.138604
2       2         3               0.3         2          0.215607
3       3         4               0.4         2          0.223592
4       4         1               0.1         2          0.173905
5       5         1               0.1         1          0.108208
Run Code Online (Sandbox Code Playgroud)

目前,我正在执行以下操作(在df函数的第一行的第一行中返回的是上面的DataFrame):

def chartObservedExpected(graph):
    df = observedExpected(graph)
    return ggplot(aes(x='degree', y='percent observed'), data=df) + \
           geom_point() + \
           ylim(-0.015,1.015) + \
           xlim(-0.05,max(df['degree']) + 0.25) + \
           labs("Degree","Proportion of Total") + \
           ggtitle("Observed Node …
Run Code Online (Sandbox Code Playgroud)

python pandas python-ggplot

11
推荐指数
1
解决办法
1万
查看次数

SAS是否具有内联函数或三元运算符?

我正在尝试在SAS中连接一个长字符串,如果函数或三元运算符有内联函数,那么我可以在串联中嵌套IF语句.我在文档中找不到这一点.在DATA步骤中,我想做类似的事情:

myString = "some words " || dead == 1 ? 't' : 'f' || " some more words" ....

基本上,我正在尝试为演示Rails应用程序生成一些种子,以便我可以快速将一些SAS数据转储到SQLite数据库中.

如果在SAS中有任何内联吗?

sas

8
推荐指数
1
解决办法
1939
查看次数

为什么一段时间后此python多处理脚本速度变慢?

基于此答案脚本,我有以下情况:一个包含2500个大文本文件的文件夹(每个〜55Mb),所有制表符分隔。基本上是Web日志。

我需要对每个文件的每一行md5哈希第二个“列”,将修改后的文件保存到其他位置。源文件位于机械磁盘上​​,目标文件位于SSD上。

该脚本可以非常快速地处理前25个(或大约25个)文件。然后,它会减慢WAY的速度。根据前25个文件,它应在2分钟左右的时间内完成所有文件。但是,根据此后的性能,将需要15分钟(或大约15分钟)来完成所有操作。

它运行在具有32 Gb RAM的服务器上,任务管理器很少显示超过6 Gb的使用情况。我将其设置为启动6个进程,但是内核上的CPU使用率很低,很少超过15%。

为什么会变慢?读/写磁盘问题?垃圾收集器?错误的代码?关于如何加快速度的任何想法?

这是剧本

import os

import multiprocessing
from multiprocessing import Process
import threading
import hashlib

class ThreadRunner(threading.Thread):
    """ This class represents a single instance of a running thread"""
    def __init__(self, fileset, filedirectory):
        threading.Thread.__init__(self)
        self.files_to_process = fileset
        self.filedir          = filedirectory

    def run(self):
        for current_file in self.files_to_process:

            # Open the current file as read only
            active_file_name = self.filedir + "/" + current_file
            output_file_name = "D:/hashed_data/" + "hashed_" + current_file

            active_file = open(active_file_name, …
Run Code Online (Sandbox Code Playgroud)

python performance multiprocessing

8
推荐指数
1
解决办法
2642
查看次数

Rails Globalize3 gem:如何使用迁移向转换表添加其他字段?

Globalize3 gem的文档清楚地说明了如何创建转换表,但是我没有看到有关如何在以后的迁移过程中向转换表添加字段的任何信息.例如,我最初包括Category.create_translation_table! :name => :string在创建Category模型时.但是,现在我需要将一个已翻译的字段添加到模型中.

如何使用Rails迁移执行此操作?我没有看到任何alter_translation_table!方法或任何类似的文档...

globalization ruby-on-rails

7
推荐指数
2
解决办法
4225
查看次数

什么是用于创建子类模型/脚手架的Rails(> = 3.1)生成器语法?

在Rails中生成子类模型或脚手架的命令行语法是什么?

rails g model Mysubclass my_field:string ....

如何指定父类?

ruby-on-rails generator subclass ruby-on-rails-3

7
推荐指数
1
解决办法
3246
查看次数