什么是正确的使用方式,@font-face以便浏览器不会下载字体,如果用户已经拥有它?
我正在使用@ font-face来定义DejaVu,它已经安装在我的系统(linux)上.Firefox没有下载字体,但Chromium每次都下载它!
@font-face {
font-family: 'DejaVu Serif';
src: url('DejaVuSerif-webfont.eot');
src: local('DejaVu Serif'), url('DejaVuSerif-webfont.woff') format('woff'), url('DejaVuSerif-webfont.ttf') format('truetype'), url('DejaVuSerif-webfont.svg#webfontCFu7RF0I') format('svg');
font-weight: normal;
font-style: normal;
}
/* ... @font-face definitions for italic and bold omitted ... */
@font-face {
font-family: 'DejaVu Serif';
src: url('DejaVuSerif-BoldItalic-webfont.eot');
src: local('DejaVu Serif Bold Italic'), url('DejaVuSerif-BoldItalic-webfont.woff') format('woff'), url('DejaVuSerif-BoldItalic-webfont.ttf') format('truetype'), url('DejaVuSerif-BoldItalic-webfont.svg#webfontQAewh7pf') format('svg');
font-weight: bold;
font-style: italic;
}
Run Code Online (Sandbox Code Playgroud) 我有两个分支,A和B.科A有一个目录examples与被跟踪的git一些文件,这些文件应该不会出现分支B.在我的工作流程,我不合并作出改变A成B经常,每次这是一个问题,有一些变化examples.目前我手动执行此操作:在合并后删除文件或解决当我已经删除的文件发生更改时的冲突.
合并期间是否可以忽略这些文件?(或者是否可以将某些文件限制为一个分支(A)或远离一个分支(B)?)
让我试着解释一下为什么我这样做:
A是博客的骨架(模板,脚本等),B是我的博客(A充满了我自己的帖子,图片,草稿等).A是公共的,我试图让它通用给别人看,并使用它,但因此我需要一些帖子作为展示/测试(examples目录).每次更改A并稍后合并到B我的博客实例上进行此更改 - 这样所有新示例都会出现,B并且所有已删除的示例B都已更改,A因为上次合并导致冲突.
当我open()用来打开文件时,我无法编写unicode字符串.我了解到我需要使用codecs并使用Unicode编码打开文件(请参阅http://docs.python.org/howto/unicode.html#reading-and-writing-unicode-data).
现在我需要创建一些临时文件.我试图使用该tempfile库,但它没有任何编码选项.当我尝试在临时文件中写入任何unicode字符串时tempfile,它会失败:
#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
import tempfile
with tempfile.TemporaryFile() as fh:
fh.write(u"Hello World: ä")
fh.seek(0)
for line in fh:
print line
Run Code Online (Sandbox Code Playgroud)
如何在Python中使用Unicode编码创建临时文件?
编辑:
我正在使用Linux,我得到的错误消息是:
Traceback (most recent call last):
File "tmp_file.py", line 5, in <module>
fh.write(u"Hello World: ä")
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 13: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)我正在尝试根据所选内容在Chrome上下文菜单中创建条目.我在Stackoverflow上发现了几个关于此的问题,对于所有这些问题,答案是:使用带有"mousedown"监听器的内容脚本,该监听器查看当前选择并创建上下文菜单.
我实现了这个,但它并不总是有效.有时所有日志消息都表示上下文菜单已按我的意愿修改,但出现的上下文菜单未更新.
基于此,我怀疑这是一个竞争条件:有时chrome会在代码完全运行之前开始渲染上下文菜单.
我尝试将eventListener添加到"contextmenu"和"mouseup".当用户使用鼠标选择文本时,后者会触发,因此它会在出现之前更改上下文菜单(甚至是秒).即使使用这种技术,我仍然会看到同样的错误!
这种情况在Chrome 22.0.1229.94(Mac)中经常发生,有时在Chromium 20.0.1132.47(linux)中发生,并且在2分钟内尝试在Windows(Chrome 22.0.1229.94)上没有发生.
到底发生了什么?我该如何解决这个问题?还有其他解决方法吗?
这是我的代码的简化版本(不是那么简单,因为我保留了日志消息):
{
"name": "Test",
"version": "0.1",
"permissions": ["contextMenus"],
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["content_script.js"]
}],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}
Run Code Online (Sandbox Code Playgroud)
function loadContextMenu() {
var selection = window.getSelection().toString().trim();
chrome.extension.sendMessage({request: 'loadContextMenu', selection: selection}, function (response) {
console.log('sendMessage callback');
});
}
document.addEventListener('mousedown', function(event){
if (event.button == 2) {
loadContextMenu();
}
}, true);
Run Code Online (Sandbox Code Playgroud)
function SelectionType(str) {
if (str.match("^[0-9]+$"))
return "number";
else if (str.match("^[a-z]+$"))
return "lowercase string";
else
return …Run Code Online (Sandbox Code Playgroud) 我是入门编程课程的助教,有些学生犯了这种错误:
char name[20];
scanf("%s",&name);
Run Code Online (Sandbox Code Playgroud)
这并不奇怪,因为他们正在学习......令人惊讶的是,除了gcc警告之外,代码也起作用(至少这部分).我一直在努力理解并编写了以下代码:
void foo(int *v1, int *v2) {
if (v1 == v2)
printf("Both pointers are the same\n");
else
printf("They are not the same\n");
}
int main() {
int test[50];
foo(&test, test);
if (&test == test)
printf("Both pointers are the same\n");
else
printf("They are not the same\n");
}
Run Code Online (Sandbox Code Playgroud)
编译和执行:
$ gcc test.c -g
test.c: In function ‘main’:
test.c:12: warning: passing argument 1 of ‘foo’ from incompatible pointer type
test.c:13: warning: comparison of distinct pointer types lacks a cast …Run Code Online (Sandbox Code Playgroud) 我试图在一个文件中编写一个Ruby脚本.
我想知道是否可以在开头编写"main"函数,具有main使用的其他函数,在它之后定义.换句话说,我想调用一个尚未定义的函数,这样它们就不依赖于定义顺序.只是更改顺序是不可能的,因为它给出了"未定义的方法"错误.在C/C++中我们使用前向声明...在Ruby中有类似的东西或其他解决方案吗?
首先,我是R的新手(我昨天开始).
我有两个组的点,data和centers,大小中的第一个n和大小的第二K(例如,n = 3823和K = 10),并为每个i在第一盘,我需要找到j在第二位的最小距离.
我的想法很简单:对于每一个i,让我们dist[j]之间的距离i和j,我只需要which.min(dist)用来找到我要找的东西.
每个点都是一个64双打数组,所以
> dim(data)
[1] 3823 64
> dim(centers)
[1] 10 64
Run Code Online (Sandbox Code Playgroud)
我试过了
for (i in 1:n) {
for (j in 1:K) {
d[j] <- sqrt(sum((centers[j,] - data[i,])^2))
}
S[i] <- which.min(d)
}
Run Code Online (Sandbox Code Playgroud)
这是非常慢的(n = 200需要超过40秒!!).我写的最快的解决方案是
distance <- function(point, group) {
return(dist(t(array(c(point, t(group)), dim=c(ncol(group), …Run Code Online (Sandbox Code Playgroud) 来自man gets:
永远不要使用gets().因为在不事先知道数据的情况下无法判断get()将读取多少个字符,并且因为gets()将继续存储超出缓冲区末尾的字符,所以使用它是非常危险的.它已被用来打破计算机安全.请改用fgets().
几乎无处不在我看到scanf的应该有同样的问题(一个方式使用缓冲区溢出/缓冲区溢出)scanf("%s",string).这种情况存在这个问题吗?为什么scanf手册页中没有关于它的引用?为什么gcc在编译时不会发出警告-Wall?
ps:我知道有一种方法可以在格式字符串中指定字符串的最大长度scanf:
char str[10];
scanf("%9s",str);
Run Code Online (Sandbox Code Playgroud)
编辑:我不是要求确定前面的代码是否正确.我的问题是:如果scanf("%s",string)总是错的,为什么没有警告,手册页中没有任何关于它的内容?
我是Nokogiri和XPath的新手,我试图访问HTML或XML片段中的所有注释.我没有使用该函数时,XPath .//comment()和//comment()工作fragment,但他们找不到任何片段.使用标记而不是注释,它适用于第一个XPath.
通过反复试验,我意识到在这种情况下comment()只能找到顶级评论,.//comment()而其他一些评论只能找到内部评论.难道我做错了什么?我错过了什么?任何人都可以解释发生了什么?
我应该使用什么XPath来获取Nokogiri解析的HTML片段中的所有注释?
这个例子可以帮助理解问题:
str = "<!-- one --><p><!-- two --></p>"
# this works:
Nokogiri::HTML(str).xpath("//comment()")
=> [#<Nokogiri::XML::Comment:0x3f8535d71d5c " one ">, #<Nokogiri::XML::Comment:0x3f8535d71cf8 " two ">]
Nokogiri::HTML(str).xpath(".//comment()")
=> [#<Nokogiri::XML::Comment:0x3f8535cc7974 " one ">, #<Nokogiri::XML::Comment:0x3f8535cc7884 " two ">]
# with fragment, it does not work:
Nokogiri::HTML.fragment(str).xpath("//comment()")
=> []
Nokogiri::HTML.fragment(str).xpath("comment()")
=> [#<Nokogiri::XML::Comment:0x3f8535d681a8 " one ">]
Nokogiri::HTML.fragment(str).xpath(".//comment()")
=> [#<Nokogiri::XML::Comment:0x3f8535d624d8 " two ">]
Nokogiri::HTML.fragment(str).xpath("*//comment()")
=> [#<Nokogiri::XML::Comment:0x3f8535d5cb8c " two ">]
Nokogiri::HTML.fragment(str).xpath("*/comment()")
=> [#<Nokogiri::XML::Comment:0x3f8535d4e104 " two ">]
# however …Run Code Online (Sandbox Code Playgroud)