我正在构建一个Web应用程序,它应该从服务器http://lscube.org/projects/feng回放RTSP/RTP流.
HTML5视频/音频标签是否支持rtsp或rtp?如果没有,最简单的解决方案是什么?也许下载到VLC插件或类似的东西.
这是php手册中的一小段代码片段:
putenv('LC_ALL=zh_CN');
setlocale(LC_ALL, 'zh_CN');
bindtextdomain('domain', './locale');
textdomain('domain');
echo gettext('Hello');
Run Code Online (Sandbox Code Playgroud)
哪个会输出你在domain.mo文件中定义的,但问题是只要Apache正在运行,gettext()总是返回缓存的结果.
如果我改变的翻译你好到您好的domain.mo,它仍将输出你好.
但是,通过更改和新名称的domain参数可以解决此问题.像到.但是每次更新文件时编辑php文件真的很痛苦.bindtextdomain()textdomain()"domain""domain2".mo
有没有更好的方法来做这个,比如删除一些文件夹或调用一些PHP函数来完成这项工作?这样我就可以为此编写一个小脚本.
在JavaScript中,对象的字段始终是"公共的":
function Test() {
this.x_ = 15;
}
Test.prototype = {
getPublicX: function() {
return this.x_;
}
};
new Test().getPublicX(); // using the getter
new Test().x_; // bypassing the getter
Run Code Online (Sandbox Code Playgroud)
但您可以使用局部变量并使用闭包作为getter来模拟"私有"字段:
function Test() {
var x = 15;
this.getPrivateX = function() {
return x;
};
}
new Test().getPrivateX(); // using the getter
// ... no way to access x directly: it's a local variable out of scope
Run Code Online (Sandbox Code Playgroud)
一个区别是,使用"公共"方法,每个实例的getter都是相同的函数对象:
console.assert(t1.getPublicX === t2.getPublicX);
Run Code Online (Sandbox Code Playgroud)
而使用"私有"方法,每个实例的getter都是一个独特的函数对象:
console.assert(t1.getPrivateX != t2.getPrivateX);
Run Code Online (Sandbox Code Playgroud)
我很好奇这种方法的内存使用情况.由于每个实例都有一个单独的getPrivateX,如果我创建10k个实例,这会导致巨大的内存开销吗?
使用私有和公共成员创建类实例的性能测试:
它似乎与平台相关(在我的笔记本电脑上与Ubuntu 12.04一起使用,不能在我的工作站上使用另一个Ubuntu 12.04).
这是关于我用两个线程做什么的示例代码.
#include <iostream>
#include <thread>
#include <chrono>
#include <atomic>
#include <GL/glfw.h>
using namespace std;
int main() {
atomic_bool g_run(true);
string s;
thread t([&]() {
cout << "init" << endl;
if (!glfwInit()) {
cerr << "Failed to initialize GLFW." << endl;
abort();
}
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
if(!glfwOpenWindow(640, 480, 8, 8, 8, 0, 24, 0, GLFW_WINDOW)) {
glfwTerminate();
cerr << "Cannot open OpenGL 2.1 render context." << endl;
abort();
}
cout << "inited" << endl;
while (g_run) { …Run Code Online (Sandbox Code Playgroud) 我在socket编程中遇到过这个:
struct sockaddr {
sa_family_t sa_family;
char sa_data[14];
}
struct sockaddr_in {
sa_family_t sin_family; /* address family: AF_INET */
in_port_t sin_port; /* port in network byte order */
struct in_addr sin_addr; /* internet address */
};
Run Code Online (Sandbox Code Playgroud)
这是两种不同类型的结构,这就是我如何使用它们
客户端:
connect(sfd,(struct sockaddr *)&caddr,clen; //type casted one
Run Code Online (Sandbox Code Playgroud)
服务器端:
bind(sfd,(struct sockaddr *)&saddr,slen);
accept(sfd,(struct sockaddr *)&caddr,&clen);
Run Code Online (Sandbox Code Playgroud)
这里有不同定义的结构正在被类型化,这是如何影响变量的?
即使我是类型转换,我可以访问这样的变量:
printf("File Descriptor : %d\n", fd);
char *p = inet_ntoa(caddr.sin_addr);
unsigned short port_no = ntohs(caddr.sin_port);
printf("Ip address : %s\n", p);
printf("Ephimeral port : %d\n", port_no);
Run Code Online (Sandbox Code Playgroud)
这种类型转换有什么用?即使我已经使用了类型,我如何访问其他结构的成员(这里是addr_in)?我想知道这些操作是如何发生的,并且理解对类型化不同结构的需求.
我正在尝试让类运行一个线程,它将在循环中调用名为Tick()的虚拟成员函数.然后我尝试派生一个类并覆盖base :: Tick().
但是在执行时,程序只调用基类的Tick而不是覆盖它.任何解决方案
#include <iostream>
#include <atomic>
#include <thread>
#include <chrono>
using namespace std;
class Runnable {
public:
Runnable() : running_(ATOMIC_VAR_INIT(false)) {
}
~Runnable() {
if (running_)
thread_.join();
}
void Stop() {
if (std::atomic_exchange(&running_, false))
thread_.join();
}
void Start() {
if (!std::atomic_exchange(&running_, true)) {
thread_ = std::thread(&Runnable::Thread, this);
}
}
virtual void Tick() {
cout << "parent" << endl;
};
std::atomic<bool> running_;
private:
std::thread thread_;
static void Thread(Runnable *self) {
while(self->running_) {
self->Tick();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
};
class Fn …Run Code Online (Sandbox Code Playgroud) 我已经使用 node.js 有一段时间了,现在当我更深入地研究它时,对于聊天应用程序而不是作为客户端 - 服务器 - 客户端发送消息,必须有一些可能的方法来直接客户端到客户端消息发送?
在webapp中,我使用的yepnope.js是加载器(主要是因为它能够加载CSS以及JS).
但是,对于yepnope加载的任何内容,Chrome都会发出警告:
资源解释为图像但使用MIME类型text/javascript传输:
<some js file>
要么
资源解释为Image但使用MIME类型text/css传输:
<some css file>
就执行而言,这不会产生任何问题,但我不明白的是Chrome如何将纯JS或CSS文件解释为IMAGE.
以及如何解决这个问题?
此外,无论从YepNope外部加载什么,都可以完美地加载而不会发出任何警告.
PS ::我没有启用任何扩展.唯一启用的是PageSpeed.
我有这个小代码来演示它:
#include "stdio.h"
int main() {
int a = testfunc(); // declared later
printf("%d", a);
return 0;
}
int testfunc() {
return 1;
}
Run Code Online (Sandbox Code Playgroud)
它编译时没有错误,输出1正如预期的那样.
请参阅操作:http://ideone.com/WRF94E
为什么没有错误?它是C规范的一部分还是编译器相关的东西?
我有一个简短的bash脚本来获取源代码的依赖文件.
#!/bin/sh
rule=$(cpp -P -w -undef -nostdinc -C -M file.cc)
rule=${rule##*:}
#echo $rule
echo ${rule//\\}
Run Code Online (Sandbox Code Playgroud)
不幸的是,它输出./findDep.sh: 5: ./findDep.sh: Bad substitution.但如果我取消注释echo $rule,脚本将执行没有任何问题:
lib.h macro.inc fundamental.h lib/fs.h lib/net.h \ lib/net/fetch.h
lib.h macro.inc fundamental.h lib/fs.h lib/net.h lib/net/fetch.h
Run Code Online (Sandbox Code Playgroud)
谁知道为什么?
提前致谢.