Laravel文档给出了这个例子:
$value = Cache::remember('users', $minutes, function() {
return DB::table('users')->get();
});
Run Code Online (Sandbox Code Playgroud)
就我而言,我有
public function thumb($hash, $extension)
{
Cache::remember('thumb-'.$hash, 15, function() {
$image = Image::where('hash', $hash)->first();
});
Run Code Online (Sandbox Code Playgroud)
如果我跑了,我得到ErrorException in ImageController.php line 69: Undefined variable: hash.我试图将$ hash传递给函数,如下所示:
Cache::remember('thumb-'.$hash, 15, function($hash)
Run Code Online (Sandbox Code Playgroud)
但后来又出现了另一个错误:
缺少App\Http\Controllers\ImageController :: App\Http\Controllers {closure}()的参数1,在C:\ xampp\htdocs\imagesharing\vendor\laravel\framework\src\Illuminate\Cache\Repository.php中调用在316行并定义
如何传递参数,以便在查询中使用它?
这是一个函数还是一个闭包?
let triple: Int -> Int = {
(number: Int) in // What is this?
let result = 3 * number
number
return result
}
triple(1)
Run Code Online (Sandbox Code Playgroud) 由于软件限制,我们目前在所有机器上运行Windows.
但是,在此范围内,我们需要将进入IP和端口的某些数据包重定向到不同的端口(相同的IP).我们有软件监听"代理端口".
这可以通过类似于以下内容的方式在Linux上使用IPTables实现:
iptables -t nat -I PREROUTING -p udp -d <DSTIP> --dport <DSTPORT> -m u32 --u32 '0>>22&0x3C@8=0xFFFFFFFF && 0>>22&0x3C@12=0x54536F75 && 0>>22&0x3C@16=0x72636520 && 0>>22&0x3C@20=0x456E6769 && 0>>22&0x3C@24=0x6E652051 && 0>>22&0x3C@28=0x75657279' -j REDIRECT --to-port <REDIRECT PORT>
Run Code Online (Sandbox Code Playgroud)
这在linux上工作得很好,并且会将某些数据包重定向到我们的代理软件,但是它是否可以在Windows上执行此类操作而无需在我们的Windows机器前面获得专用机器?
我在考虑用pcap.net写一些东西,但我猜这将不得不直接从NIC读取而不是Windows?
routing network-programming iptables windows-firewall pcap.net
我正在尝试通过内核模块读取和写入proc文件
但是当我运行此命令时:
echo "hello" >> /proc/hello && cat /proc/hello
当我通过文本编辑器打开文件时,它不会打印任何内容.我发现了这样的神秘符号
^@^@^@^@^@^@^@^@^@^@
Run Code Online (Sandbox Code Playgroud)
任何帮助将提前感谢
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include<linux/sched.h>
#include <asm/uaccess.h>
#include <linux/slab.h>
int len,temp;
char *msg;
int read_proc(struct file *filp,char *buf,size_t count,loff_t *offp ){
if(count>temp){count=temp;}
temp=temp-count;
copy_to_user(buf,msg, count);
if(count==0)temp=len;
return count;
}
int write_proc(struct file *filp,const char *buf,size_t count,loff_t *offp){
copy_from_user(msg,buf,count);
len=count;
temp=len;
return count;
}
struct file_operations proc_fops = {
read: read_proc,
write: write_proc
};
void create_new_proc_entry(void){
proc_create("hello",0,NULL,&proc_fops);
msg=kmalloc(GFP_KERNEL,10*sizeof(char));
}
int proc_init (void){
create_new_proc_entry();
return 0;
}
void …Run Code Online (Sandbox Code Playgroud) 我正在使用win32com.client,python 2.7.x并outlook 2013在windows平台上.
我需要将HTML文件的内容发布到outlook消息正文.
我按照这里的帖子,这里和这里关于如何保存excel HTML和粘贴数据outlook.
但是,当我通过win32com.client.Dispatch而不是看到消息来阅读文件时,我看到的是HTML代码.
以下是将已处理xlsx文件转换为html使用格式的代码win32.com.
#Section to convert excel workbook to html
myfile = os.getcwd()+ "\\" + outfile
newfile = os.getcwd()+ "\\" + "emailData.html"
xl = EnsureDispatch('Excel.Application')
#xl.Visible = True
wb3 = xl.Workbooks.Open(myfile)
wb3WorkSheet = wb3.Worksheets(1)
wb3WorkSheet.Activate()
wb3.SaveAs(newfile, constants.xlHtml)
wb3.Close(True)
xl.Workbooks.Close()
xl.Quit()
del xl
Run Code Online (Sandbox Code Playgroud)
上面的输出newfile …
我在第一个数据框中有一列,df1["ItemType"]如下所示,
Dataframe1
ItemType1
redTomato
whitePotato
yellowPotato
greenCauliflower
yellowCauliflower
yelloSquash
redOnions
YellowOnions
WhiteOnions
yellowCabbage
GreenCabbage
Run Code Online (Sandbox Code Playgroud)
我需要根据从另一个数据框创建的字典替换它.
Dataframe2
ItemType2 newType
whitePotato Potato
yellowPotato Potato
redTomato Tomato
yellowCabbage
GreenCabbage
yellowCauliflower yellowCauliflower
greenCauliflower greenCauliflower
YellowOnions Onions
WhiteOnions Onions
yelloSquash Squash
redOnions Onions
Run Code Online (Sandbox Code Playgroud)
请注意,
dataframe2一些ItemType都一样ItemType在
dataframe1. ItemType具有nullyellowCabbage等值.ItemType在dataframe2中相对于ItemTypein 而言是乱序的dataframeDataframe1 ItemType如果相应的值匹配,我需要替换列中的值,Dataframe2 ItemType同时newType保留在bullet-points中列出的上述异常.
如果没有匹配,那么值必须是[无变化].
到目前为止,我得到了.
import pandas as pd
#read second `csv-file`
df2 = …Run Code Online (Sandbox Code Playgroud) 我正在尝试提取 wav 文件的一些特征,我有这个:
我正在使用 pyAudioAnalysis 库的特征提取工具:
https://github.com/tyiannak/pyAudioAnalysis/wiki/3.-特征提取
问题是我遇到了reshape()numpy 函数的错误。我遵循 wiki 中如何使用特征提取器的指南,如下所示:
[Fs, x] = audioBasicIO.readAudioFile('13 Clock in the Morning - Waiters the Free Music Archive (No Copyright Music).wav')
F = audioFeatureExtraction.stFeatureExtraction(x, Fs, 0.050 * Fs, 0.025 * Fs)
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
1 [Fs, x] = audioBasicIO.readAudioFile("song-wavs/"+song.name)
----> 2 F = audioFeatureExtraction.stFeatureExtraction(x, Fs, 0.050 * Fs, 0.025 * Fs)
pyAudioAnalysis/audioFeatureExtraction.pyc in stFeatureExtraction(signal, Fs, Win, Step)
575 curFV[0] = stZCR(x) # zero crossing rate
576 curFV[1] = stEnergy(x) # short-term …Run Code Online (Sandbox Code Playgroud) 我正在查询PostgreSQL服务器以获取数据,并且特定json对象实际上以字符串形式返回.我试过跟随,但没有给出正确的输出:(它的ipython输出)
test
Out[103]: '{"max"=>28, "min"=>18, "custom"=>[{"id"=>"12345","name"=>"test_pur"}]}'
In[104]: test.replace("=>",":")
Out[104]: '{"max":28, "min":18, "custom":[{"id":"12345", "name":"test_pur"}]}'
In[105]: j_obj = json.dumps(test)
In[106]: j_obj
Out[106]: '"{\\"max\\"=>28, \\"min\\"=>18, \\"custom\\"=>[{\\"id\\"=>\\"12345\\", \\"name\\"=>\\"test_pur\\"}]}"'
Run Code Online (Sandbox Code Playgroud)
如何通过识别":"符号将字符串转换为json?
当我尝试"json.loads"时.以下是错误:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-12-a7562191decf>", line 1, in <module>
data = json.loads(temp)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 381, in raw_decode
obj, …Run Code Online (Sandbox Code Playgroud) 在Ubuntu 15.10上,我正在运行PyCharm Community Edition版本2016.1.我有一个调用的Python文件import tensorflow,一个依赖于CUDA库的模块libcudart.so.7.5.当我运行此文件时,我收到以下错误消息:
ImportError: libcudart.so.7.5: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
现在,该文件libcudart.so.7.5位于我的机器上/usr/local/cuda-7.5/lib64.在Pycharm中,我添加了这条路径File->Settings->Project Interpreter->Interpreter Paths.所以,我很困惑为什么PyCharm找不到libcudart.so.7.5包含它的目录被列为解释器路径.
此外,如果我从命令行运行此文件,它运行正常没有上述错误.在我的.bashrc文件中,我有一句话:
export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH
Run Code Online (Sandbox Code Playgroud)
所以这似乎是允许找到库文件.但是我怎样才能让PyCharm找到这个库?我的理解是,添加解释路径的路径是解决方案,但似乎这可能不正确...
谢谢!
我正在尝试在 Librosa 中打开一个 AudioFile。修剪它,然后使用pydub修改它。这是我的代码:
sound = AudioSegment.from_file(filePath)
samples = sound.get_array_of_samples()
arr = np.array(samples)
print(type(arr))
print(arr)
# then modify samples...
y, index = librosa.effects.trim(arr)
Run Code Online (Sandbox Code Playgroud)
问题是,即使我遵循此处概述的解决方案:https :
//github.com/jiaaro/pydub/issues/289
我似乎无法使用 librosa 的 trim() 函数。它给了我这个错误:
librosa.util.exceptions.ParameterError: Audio data must be floating-point
这样做的原因是 Librosa 需要一个浮点 numpy 数组(并使用它们),而 pydub 导出一个整数数组(我将其转换为 np 数组)。我不知道如何在 2 之间转换 numpy 数组。
我可以从 Pydub 导出到文件,然后用 Librosa 加载它 - 但这似乎是一种非常低效的做事方式。
软件包版本:
Librosa - 0.7.1。
Pydub - 0.23.1