有一个非常类似的问题.其中一个解决方案使用如下代码:
string.mb_chars.normalize(:kd).gsub(/[^x00-\x7F]/n, '').to_s
Run Code Online (Sandbox Code Playgroud)
这会产生奇迹,直到你注意到它还会移除空格,圆点,破折号以及谁知道还有什么.
我不是很确定第一个代码是如何工作的,但它是否可以仅剥离重音符号?或至少给出一个保留的字符列表?我对regexps的了解很少,但我尝试过(无济于事):
/[^\-x00-\x7F]/n # So it would leave the dash alone
Run Code Online (Sandbox Code Playgroud)
我要做这样的事情:
string.mb_chars.normalize(:kd).gsub('-', '__DASH__').gsub
(/[^x00-\x7F]/n, '').gsub('__DASH__', '-').to_s
Run Code Online (Sandbox Code Playgroud)
残暴?是...
我也尝试过:
iconv = Iconv.new('UTF-8', 'US-ASCII//TRANSLIT') # Also tried ISO-8859-1
iconv.iconv 'Café' # Throws an error: Iconv::IllegalSequence: "é"
Run Code Online (Sandbox Code Playgroud)
请帮忙?
我想知道,如果我有,让我们说6个javascripts包含在一个页面上,4-5 css包含在同一页面上,如果我创建一个文件或者两个文件,它实际上是否最适合页面加载将它们全部加在一起而不是一堆它们?
我试图用Ruby搞得一团糟.因此,我尝试从"Programming Collective Intelligence"Ruby书中实现算法(在Python中给出).
在第8章中,作者将方法a作为参数传递.这似乎适用于Python,但不适用于Ruby.
我有这个方法
def gaussian(dist, sigma=10.0)
foo
end
Run Code Online (Sandbox Code Playgroud)
并希望用另一种方法调用它
def weightedknn(data, vec1, k = 5, weightf = gaussian)
foo
weight = weightf(dist)
foo
end
Run Code Online (Sandbox Code Playgroud)
我得到的只是一个错误
ArgumentError: wrong number of arguments (0 for 1)
Run Code Online (Sandbox Code Playgroud) 我如何"内置"此脚本的自动登录?
if (isset($_POST['login'])) {
$query = mysql_query("
SELECT * FROM users
WHERE user_name = '".mysql_real_escape_string($_POST['username'])."'
AND user_password = '".mysql_real_escape_string($_POST['password'])."'
");
/* wrong login information? terminate the script */
if (!mysql_num_rows($query)){
header("Location: ./");
exit();
}
/* set session with unique index */
$_SESSION['id'] = mysql_result($query, 0, 'user_id');
mysql_query("UPDATE users SET user_online = '1' WHERE user_id = '{$_SESSION['id']}'");
header("Location: ./");
exit;
}
我正在尝试我的第一个Spring项目,并且必须做一些非常愚蠢的事情,因为我无法弄清楚如何使以下简单的代码片段工作:
这是我的定义文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="AWSProperties" class="com.addy.server.queue.AWSProperties" scope="singleton">
<property name="awsAccessKey" value="test1"/>
<property name="awsSecretKey" value="test2"/>
<property name="awsSQSQueueName" value="testqueue"/>
</bean>
<bean id="QueueService" class="com.addy.server.queue.QueueService">
<constructor-arg ref="AWSProperties"/>
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
还有我的两个简单豆子:
public class AWSProperties {
private String awsAccessKey;
private String awsSecretKey;
private String awsSQSQueueName;
public void setAwsAccessKey(String awsAccessKey) {
awsAccessKey = awsAccessKey;
}
public String getAwsAccessKey() {
return awsAccessKey;
}
public void setAwsSecretKey(String awsSecretKey) {
awsSecretKey = awsSecretKey;
}
public String getAwsSecretKey() {
return awsSecretKey;
}
public void setAwsSQSQueueName(String …Run Code Online (Sandbox Code Playgroud) 今天我在想一个我在一年前写的Python项目,我用logging得非常广泛.我记得由于开销(hotshot表明它是我最大的瓶颈之一),必须在类似内循环的场景(90%代码)中注释掉大量的日志调用.
我现在想知道是否有一些规范的方法可以在Python应用程序中以编程方式去除日志记录调用,而无需一直注释和取消注释.我认为您可以使用检查/重新编译或字节码操作来执行此类操作,并仅针对导致瓶颈的代码对象.这样,您可以添加操纵器作为后编译步骤并使用集中配置文件,如下所示:
[Leave ERROR and above]
my_module.SomeClass.method_with_lots_of_warn_calls
[Leave WARN and above]
my_module.SomeOtherClass.method_with_lots_of_info_calls
[Leave INFO and above]
my_module.SomeWeirdClass.method_with_lots_of_debug_calls
Run Code Online (Sandbox Code Playgroud)
当然,您希望谨慎使用它,并且可能只使用每个函数的粒度 - 仅适用于已显示logging为瓶颈的代码对象.有人知道这样的事吗?
注意:由于动态类型和后期绑定,有一些因素使性能更难以执行.例如,对命名方法的任何调用都debug可能必须用if not isinstance(log, Logger).在任何情况下,我都假设所有的细节都可以通过绅士的协议或一些运行时检查来克服.:-)
我是Gnuplot的忠实粉丝,我在各个项目的研究中都使用它.
最近我想用Gnuplot绘制一些时间序列,如减肥,锻炼结果,气体消耗等.
因此我像x轴一样缩放
set xdata time
set timefmt "%d.%m %Y"
set format x "%d.%m"
Run Code Online (Sandbox Code Playgroud)
现在我想使用fit-function来给我一个线性拟合.我的问题是,如果x轴与时间有关,我就无法工作.
首先,我进入C++课程已有四周时间,我甚至还不知道循环,所以请说说话宝贝?
好的,所以我应该从文件中读取十二个字符串(加上NULL使得十三个),然后将字母向后移三个,然后将结果打印到屏幕和文件.除了换字母之外,我还好.我不想写几英里的代码来单独取每个字符,减去三个,然后重新组合字符串,但我不确定如何一次处理整个字符串.有人可以推荐一种非常简单的方法吗?
对于我的Android应用程序,有一个计时器可以测量已经过了多长时间.在100毫秒内,我用一些文本更新了我的TextView,例如"得分:10时间:100.10秒".但是,我发现TextView仅在前几次更新.该应用程序仍然非常敏感,但标签不会更新.我试图调用.invalidate(),但它仍然无效.我不知道是否有某种方法可以解决这个问题,或者使用更好的小部件.
以下是我的代码示例:
float seconds;
java.util.Timer gametimer;
void updatecount() { TextView t = (TextView)findViewById(R.id.topscore);
t.setText("Score: 10 - Time: "+seconds+" seconds");
t.postInvalidate();
}
public void onCreate(Bundle sis) {
... Load the UI, etc...
gametimer.schedule(new TimerTask() { public void run() {
seconds+=0.1; updatecount();
} }, 100, 100);
}
Run Code Online (Sandbox Code Playgroud) java ×2
ruby ×2
string ×2
android ×1
browser ×1
bytecode ×1
c++ ×1
cookies ×1
css ×1
diacritics ×1
encryption ×1
gnuplot ×1
javascript ×1
latex ×1
logging ×1
methods ×1
optimization ×1
parameters ×1
performance ×1
php ×1
python ×1
spring ×1
textview ×1
time-series ×1
timer ×1