我正在最终确定一个列出目录中文件的代码段.我没有问题列出目录中的文件,但由于某种原因,我可以让isDot()方法工作,以确保该文件不是"." 要么 ".." .以下结果导致此错误:
Fatal error: Call to undefined method SplFileInfo::isDot() in ....
Run Code Online (Sandbox Code Playgroud)
在我切换到使用Recursive Iterator之前,我正在使用Directory Iterator,它工作正常.下面的代码有什么问题吗?它应该工作.
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pathToFolder));
//if there is a subdirectory it makes sure the proper extension is passed
foreach($files as $name => $file){
if (!$file->isDot()) { //this is where it shuts me down
$realfile = str_replace($pathToFolder, "", $file);
$url = getDownloadLink($folderID, $realfile);
$fileArray[] = $url;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用GitPython库进行一些简单的 Git 操作,我想签出一个分支,进行提交,然后签出前一个分支。文档对如何执行此操作有些困惑。到目前为止,我有这个:
import git
repo = git.Repo()
previous_branch = repo.active_branch
new_branch_name = "foo"
new_branch = repo.create_head(new_branch_name)
new_branch.checkout()
repo.index.commit("my commit message") # this seems wrong
## ?????
Run Code Online (Sandbox Code Playgroud)
我可以通过 git 命令验证它来判断它是否有效,但我觉得我这样做不正确。我不知道如何使用原始 git 命令(直接从库中)安全地切换回前一个分支。
我一直在为类实现选择排序问题,其中一个任务是使用最小堆找到数组中的第k个最小元素.我知道程序是:
创建最小堆我没有任何问题.我只是不确定如何正确删除最小k次并成功返回组中的第k个最小元素.这是我到目前为止所拥有的:
bool Example::min_heap_select(long k, long & kth_smallest) const {
//duplicate test group (thanks, const!)
Example test = Example(*this);
//variable delcaration and initlization
int n = test._total ;
int i;
//Heapifying stage (THIS WORKS CORRECTLY)
for (i = n/2; i >= 0; i--) {
//allows for heap construction
test.percolate_down_protected(i, n);
}//for
//Delete min phase (THIS DOESN'T WORK)
for(i = n-1; i >= (n-k+1); i--) {
//deletes the min by swapping elements
int tmp = test._group[0];
test._group[0] = …Run Code Online (Sandbox Code Playgroud) 我想知道如何手动计算给定字符串的哈希码.我知道在Java中,你可以这样做:
String me = "What you say what you say what?";
long whatever = me.hashCode();
Run Code Online (Sandbox Code Playgroud)
这都是好事和花花公子,但我想知道如何手工完成.我知道计算字符串哈希码的给定公式是这样的:
S0 X 31 ^ (n-1) + S1 X 31 ^ (n-2) + .... + S(n-2) X 31 + S(n-1)
Run Code Online (Sandbox Code Playgroud)
其中S表示字符串中的字符,n表示字符串的长度.然后使用16位unicode,字符串me中的第一个字符将被计算为:
87 X (31 ^ 34)
Run Code Online (Sandbox Code Playgroud)
然而,这创造了一个疯狂的大数字.我无法想象像这样将所有角色加在一起.那么,为了计算最低阶32位的结果,我该怎么办?从上面的长度等于-957986661并且我不是如何计算的?
我一直在用C调试,我发现能够直接操作位是令人着迷和强大的(我认为这很危险).我很好奇比较C中不同位的最佳方法是什么.例如,数字15以二进制表示为:
00001111
Run Code Online (Sandbox Code Playgroud)
数字13表示为:
00001101
Run Code Online (Sandbox Code Playgroud)
如何在不计算它们的情况下比较哪些位是不同的?使用移位很容易确定15包含4个1并且13包含3个1,但是如何输出两者之间的差异(例如2 ^ 1点在两者之间是不同的)?我想不出一个简单的方法来做到这一点.任何指针将非常感谢!
编辑:我应该澄清,我知道XOR是解决这个问题的正确方法,但我遇到了实施问题.我想我的问题是一次比较一点(而不是产生差异).我想出的解决方案是:
void compare(int vector1, int vector2) {
int count = 0;
unsigned int xor = vector1 ^ vector2;
while (count < bit_length) {
if (xor % 2 == 1) { //would indicicate a difference
printf("%d ", count);
}
xor >>= 1;
count++;
}
}
Run Code Online (Sandbox Code Playgroud) 我在使用Java调用Oracle存储过程时遇到问题.我向数据库添加了一个存储过程,如下所示:
String SQL = "CREATE OR REPLACE PROCEDURE LIVERESULTS() " +
"IS " +
"BEGIN" +
" SELECT POOL_ID, POOL_MBR_ID, BSLN_CD, PGE_TYP_NM, SERV_NM, CL_FILE_NM" +
" FROM LBMADM.TPPO_MSTR_MAP " +
" ORDER BY SERV_NM" +
" WHERE PGE_TYP_NM = 'live' ; " +
"END";
stmtLIVE = con.createStatement();
stmtLIVE.executeUpdate(SQL);
Run Code Online (Sandbox Code Playgroud)
而现在我试着这样称呼它:
CallableStatement cs;
try {
cs = con.prepareCall("{call LIVERESULTS() }");
rs = cs.executeQuery();
while (rs.next()) {
.....
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误:
java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00905: object UT9J.GENERATE_SQL_FOR_LIVE is invalid
ORA-06550: line 1, …Run Code Online (Sandbox Code Playgroud) 我有这样的东西:
func (client *MyCustomClient) CheckURL(url string, json_response *MyCustomResponseStruct) bool {
r, err = http.Get(url)
if err != nil {
return false
}
defer r.Body.Close()
.... do stuff with json_response
Run Code Online (Sandbox Code Playgroud)
在测试中,我具有以下几点:
func TestCheckURL(t *test.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=UTF-8")
fmt.Fprintln(w, `{"status": "success"}`)
}))
defer ts.Close()
json_response := new(MyCustomResponseStruct)
client := NewMyCustomClient() // returns instance of MyCustomClient
done := client.CheckURL("test.com", json_response)
Run Code Online (Sandbox Code Playgroud)
但是,从日志输出中可以看出,它似乎并没有显示HTTP测试服务器正在运行并且实际上已经进入了test.com。
Get http:/test.com: dial tcp X.Y.Z.A: i/o timeout
Run Code Online (Sandbox Code Playgroud)