我正在尝试使用pdf.js从pdf渲染页面
通常,使用网址,我可以这样做:
PDFJS.getDocument("http://www.server.com/file.pdf").then(function getPdfHelloWorld(pdf) {
//
// Fetch the first page
//
pdf.getPage(1).then(function getPageHelloWorld(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
//
// Prepare canvas using PDF page dimensions
//
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
//
// Render PDF page into canvas context
//
page.render({canvasContext: context, viewport: viewport});
});
});
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,我将文件放在base64而不是url:
data:application/pdf;base64,JVBERi0xLjUKJdDUxdgKNSAwIG9iaiA8PAovTGVuZ3RoIDE2NjUgICAgICAKL0ZpbHRlciAvRmxhdGVEZWNvZGUKPj4Kc3RyZWFtCnjarVhLc9s2...
Run Code Online (Sandbox Code Playgroud)
怎么做到这一点?
我需要获取所有current_user.friends状态,然后按created_at对它们进行排序.
class User < ActiveRecord::Base
has_many :statuses
end
class Status < ActiveRecord::Base
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
在控制器中:
def index
@statuses = []
current_user.friends.map{ |friend| friend.statuses.each { |status| @statuses << status } }
current_user.statuses.each { |status| @statuses << status }
@statuses.sort! { |a,b| b.created_at <=> a.created_at }
end
Run Code Online (Sandbox Code Playgroud)
current_user.friends 返回一个对象数组 User
friend.statuses 返回一个对象数组 Status
错误:
comparison of Status with Status failed
app/controllers/welcome_controller.rb:10:in `sort!'
app/controllers/welcome_controller.rb:10:in `index'
Run Code Online (Sandbox Code Playgroud) 可能重复:
java继承 - 请解释
我正在学习Java,我有两个问题:
有什么区别:
A x = new A();
Run Code Online (Sandbox Code Playgroud)
和
A x = new B();
Run Code Online (Sandbox Code Playgroud)
考虑到:
class A
class B extends A
Run Code Online (Sandbox Code Playgroud)有什么区别:
A x = new B();
(A)x.run_function();
Run Code Online (Sandbox Code Playgroud)
假设A和B都有这个功能run_function,哪一个会被执行?
我有一个像这样过滤的列表:
ng-repeat="item in items | filter:query | limitTo:10"
Run Code Online (Sandbox Code Playgroud)
和搜索输入
ng-model="search.name"
Run Code Online (Sandbox Code Playgroud)
它有效,但我想在结果中使查询部分变为粗体.
例:
query = zza
Run Code Online (Sandbox Code Playgroud)
结果:
我正在尝试创建一个方法,使两个数组交叉重复.
例: {1,2,5,4,1,3} and {1,2,1} -> {1,1,2}.
我有一个交叉但不重复的方法.
public int[] findSameElements(int[] p1, int[] p2) {
int count = 0;
for (int i = 0; i < p1.length; i++) {
for (int j = 0; j < p2.length; j++) {
if (p1[i] == p2[j]) {
count++;
break;
}
}
}
int[] result = new int[count];
count = 0;
for (int i = 0; i < p1.length; i++) {
for (int j = 0; j < p2.length; j++) {
if (p1[i] == …Run Code Online (Sandbox Code Playgroud) 我有一个控制器:
$scope.timeAgoCreation = function(order) {
return moment(order.createdAt).fromNow();
};
Run Code Online (Sandbox Code Playgroud)
在一个视图中:
{{timeAgoCreation(order)}}
Run Code Online (Sandbox Code Playgroud)
它返回正确的值:9分钟前.但是这个值不是实时更新的.我必须刷新页面.
是否有可能让它实时更新?
我有一个像这样组织的照片库:
.container
%li
%a{src: image.src}
%li
%a{src: image.src}
%li
%a{src: image.src}
.container
%li
%a{src: image.src}
%li
%a{src: image.src}
%li
%a{src: image.src}
Run Code Online (Sandbox Code Playgroud)
每个容器最多应为3个%li.
假设我在@images哪里@images.count => 4.
.container
- for image in @images do
%li
%a{src: image.src}
Run Code Online (Sandbox Code Playgroud)
此代码将破坏页面,因为在这种情况下.container有4 %li.
我怎么能这样做.container每隔3加一次%li?
我正在使用这种方法:
def self.lines_price_report(n)
Income.group('date(filled_at)').having("date(filled_at) > ?", Date.today - n).sum(:lines_price)
end
Run Code Online (Sandbox Code Playgroud)
我在Heroku中收到此错误:
PG::Error: ERROR: column "incomes.filled_at" must appear in the GROUP BY clause
or be used in an aggregate function
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?谢谢.
执行查询:
SELECT SUM("incomes"."lines_price") AS sum_lines_price, date(filled_at)
AS date_filled_at FROM "incomes"
HAVING (date(filled_at) > '2012-12-04')
GROUP BY date(filled_at) ORDER BY filled_at ASC
Run Code Online (Sandbox Code Playgroud)
预期结果
[["2012-12-04", SUM_FOR_DATE], ["2012-12-05", SUM_FOR_DATE], ...]
Run Code Online (Sandbox Code Playgroud) 让o1, o2, o3, o4activerecord对象使用
o1.kind = "att2"o2.kind = "att3"o3.kind = "att4"o4.kind = "att1"让 a = [o1, o2, o3, o4]
让 b = ['att1', 'att3', 'att4', 'att2']
我需要排序a,b以便新订单a成为:
a = [o4, o2, o3, o1]
Run Code Online (Sandbox Code Playgroud)
我试过了
a.sort_by do |element|
b.index(element)
end
Run Code Online (Sandbox Code Playgroud)
但是如何排序 kind?
(C 程序)我正在尝试编译一个使用标头的 main.c,但出现以下错误。\n当我不使用标头(主文件中的所有方法)时,一切正常。
\n\n在字符串 S 中,程序查找所有出现的单词并返回出现次数最多的单词。
\n\n我正在编译使用:gcc main.c
谢谢。
\n\n错误
\n\nIn file included from main.c:9:0:\nfrequence.h:4:16: warning: useless storage class specifier in empty declaration [enabled by default]\nmain.c: In function \xe2\x80\x98main\xe2\x80\x99:\nmain.c:15:10: error: variable \xe2\x80\x98word\xe2\x80\x99 has initializer but incomplete type\nmain.c:15:10: warning: passing argument 1 of \xe2\x80\x98show_all_words\xe2\x80\x99 from incompatible pointer type [enabled by default]\nfrequence.h:6:17: note: expected \xe2\x80\x98char *\xe2\x80\x99 but argument is of type \xe2\x80\x98char (*)[34]\xe2\x80\x99\nmain.c:15:10: error: invalid use of undefined type \xe2\x80\x98struct stat_mot\xe2\x80\x99\nmain.c:15:19: error: storage size of \xe2\x80\x98word\xe2\x80\x99 …Run Code Online (Sandbox Code Playgroud)