好的 - 我正在Objective C中编写一个守护进程,它每5秒检查一次连接的路由器mac地址.
我对目标C完全不熟悉,我正在寻找一种更好的方法来做我已经在做的事情.
我正在调用"arp -a"并通过"Task"解析结果:
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/sbin/arp"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"-a", nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
Run Code Online (Sandbox Code Playgroud)
我担心这不是很有效率.
有什么建议?我每5秒运行一次这个代码块.
在Objective-C中,为什么[object doSomething]?不是[*object doSomething]因为你在对象上调用一个方法吗?这意味着你应该取消引用指针?
我在http://alpha.spherecat1.com/上的jQuery代码有问题,但本地副本工作正常.正如您所看到的,如果您现在访问该站点,则ajax调用会出现以下错误:
"TypeError:无法读取属性'documentElement'的null"
我已经检查并重新检查并重新上载了我能想到的一切.该文档说,以确保我发送正确的MIME类型,我做了无济于事.这是有问题的代码:
function changePageAJAX(newPage, method)
{
if (method != "replace")
{
window.location.hash = newPage;
}
newPage = newPage.substring(1); // Remove the hash symbol.
title = "SphereCat1.com | " + fixCase(newPage.replace(/\//g, " > ")); // Set the window title.
newPage = "ajax/" + newPage + ".html"; // Add path.
if (newPage == currentPage)
{
return; // Don't let them load the current page again.
}
$.ajax({ // jQuery makes me feel like a code ninja.
url: newPage,
dataType: …Run Code Online (Sandbox Code Playgroud) 我有一个公共库,我使用几个解析命令行选项的脚本,但是我也希望我的个人脚本能够处理参数...例如
common.sh:
function get_options {
echo -e "in getoptions"
echo $OPTIND
while getopts ":ab:" optionName; do
[ ... processing code ... ]
done
}
Run Code Online (Sandbox Code Playgroud)
灰
. ./common.sh
function get_local_options {
echo -e "in getoptions"
echo $OPTIND
while getopts ":xy:" optionName; do
[ ... processing code ... ]
done
}
get_local_options $*
OPTIND=1
get_options $*
Run Code Online (Sandbox Code Playgroud)
问题是,如果我用a调用a.sh:
a.sh -x -y foo -a -b bar
Run Code Online (Sandbox Code Playgroud)
get_options停止在"foo"处理,因为它停在第一个"非选项"
没有改写自己的东西吗?
我正在使用ConfigParser从配置文件加载数据,如下所示:
test.conf:
[myfiles]
fileone: %(datadir)s/somefile.foo
filetwo: %(datadir)s/nudderfile.foo
Run Code Online (Sandbox Code Playgroud)
load.py:
import ConfigParser
config = ConfigParser.ConfigParser({'datadir': '/tmp'})
config.read('test.conf')
print config.items('myfiles')
print config.get('myfiles', 'datadir')
Run Code Online (Sandbox Code Playgroud)
输出:
$ python load.py
[('datadir', '/tmp'), ('filetwo', '/tmp/nudderfile.foo'), ('fileone', '/tmp/somefile.foo')]
/tmp
Run Code Online (Sandbox Code Playgroud)
我很惊讶变量替换的默认值('datadir', '/tmp')是作为一部分出现的.items()并.get()返回,就像它们是配置文件中的值一样.这种行为有望吗?任何解决方法,以便我可以简单地迭代.items()而不获取那里的默认字典值,但仍然使用魔术插值?
参考:http://docs.python.org/library/configparser.html
谢谢!
更新:已经指出这是预期的行为:默认值与配置文件中的任何其他名称/值对一样.同样,配置文件中的名称/值对也可用于"魔术插值",所以如果我定义:
foo: bar
zap: %(foo)snowl
Run Code Online (Sandbox Code Playgroud)
我去拿 [... ('zap': 'barnowl')]
这非常简洁,但我仍然想知道我是否能完成我想要完成的任务:迭代我的配置文件中的名称/值对,插入变量,没有默认值.
我的具体情况是:我想用类似的东西初始化配置对象{basedir: '/foo/bar'},因为某些文件的绝对路径因安装而异.然后我需要传递该配置对象并让各种其他类遍历文件.我不希望每个读取配置的类都必须知道它是使用某些默认值初始化的,并且它应该忽略它们,因为它们不是实际文件.这可能吗?有什么方法可以隐藏.item()和.get()的默认值但仍有插值?谢谢!
我所有的MooTools类都是这样的:
myClass = new Class({
initialize: function(options) {
if (optionsType === 'object') {
for (var key in options) {
this[key] = options[key];
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
这有必要吗?MooTools是否有内置的功能可以执行此操作?
或者我需要创建一个超类?
我正在学习yii框架并阅读了他们的文档.
但我仍然不明白这些组件.这些是什么.他们谈论组件事件和行为.
有人可以为我解释这些条款,并给我一个组件,其事件和行为可能是什么的真实应用示例?
会有帮助的!
在Aaron Hillegass的" Mac OS X可可编程"第9章"插入时开始编辑"一节中,他解释了如何做到这一点.这让我感到困惑,虽然事情是,他做了一堆其他的东西.这是完整的代码清单:
- (IBAction)createEmployee:(id)sender
{
NSWindow *w = [tableView window];
// Try to end any editing that is taking place
BOOL editingEnded = [w makeFirstResponder:w];
if (!editingEnded) {
NSLog(@"Unable to end editing");
return;
}
NSUndoManager *undo = [self undoManager];
// Has an edit occurred already in this event?
if ([undo groupingLevel]) {
// Close the last group
[undo endUndoGrouping];
// Open a new group
[undo beginUndoGrouping];
}
// Create the object
Person *p = …Run Code Online (Sandbox Code Playgroud)