我有一个脚本,当用户加载时,创建一个唯一的ID.然后将其保存localStorage
并用于跟踪交易.有点像使用cookie,除非由于浏览器生成唯一ID,因此在发送到服务器时可能会发生冲突.现在我正在使用以下代码:
function genID() {
return Math.random().toString(36).substr(2)
+ Math.random().toString(36).substr(2)
+ Math.random().toString(36).substr(2)
+ Math.random().toString(36).substr(2);
}
Run Code Online (Sandbox Code Playgroud)
我意识到这是一个超级基本的实现,并希望获得一些反馈,以更好的方法来创建一个"更随机"的ID,以防止服务器上的冲突.有任何想法吗?
我正在尝试perf probe
在我的库中添加一个C++方法,但我不断得到以下内容:
$ perf probe --exec=/path/to/file --add='my::Own::Method'
Semantic error :There is non-digit char in line number.
Run Code Online (Sandbox Code Playgroud)
我列出了可用的功能,如下所示:
$ perf probe --funcs --exec=/path/to/file
Run Code Online (Sandbox Code Playgroud)
并尝试了一些也包含在内的C函数.可以为这些添加探针就好了.所以我尝试了受损的名称(例如_ZN2my8Own16Method
)并perf probe
说它不存在.
有没有解决这个问题的方法?
我的很多调试代码都包含在页眉/页脚中.通常我运行一个脚本,在我暂存和提交更改之前从源中删除所有脚本.如果调试代码需要持久提交,我将运行git add -p
并单独分阶段.
我的问题是,是否可以根据正则表达式进行更改?例如,给定这个javascript片段:
function littleNinja( sword ) {
/* debug:start */
console.log( sword );
/* debug:stop */
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
我不想git的阶段性和其中包括的线路debug:start
和debug:stop
,我的希望是,这个过程可以实现自动化.
我正在尝试但无法创建一个计数器,该计数器将在每分钟后显示文本视图中的剩余时间.时间没有出现,也没有任何错误.
这是我的代码:
package com.timer;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
CountDownTimer timer = new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
int seconds = (int) (millisUntilFinished / 1000);
tv.setText("seconds remaining: " + String.valueOf(seconds));
}
public void onFinish() {
tv.setText("Finished!!");
}
};
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this …
Run Code Online (Sandbox Code Playgroud)