我想在我的小应用程序中捕获关键事件.
我做了什么:
class ViewController : NSViewController {
...
override func keyDown(theEvent: NSEvent) {
if theEvent.keyCode == 124 {
println("abc")
} else {
println("abcd")
}
}
override var acceptsFirstResponder: Bool {
return true
}
override func becomeFirstResponder() -> Bool {
return true
}
override func resignFirstResponder() -> Bool {
return true
}
...
}
Run Code Online (Sandbox Code Playgroud)
怎么了:
按下某个键时,会播放Funk声音效果.
我看过很多帖子都在谈论这是一个属于哪个代表NSView,NSViewController也没有访问权限.但是keydown函数overrideauto在一类类型中完成,NSViewController导致我认为这是错误的.
所以,我有以下结构:
.
..
a.png
b.png
c.png
Run Code Online (Sandbox Code Playgroud)
我跑了一个命令来调整它们的大小
ls | xargs -I xx convert xx -resize xx.jpg
Run Code Online (Sandbox Code Playgroud)
现在我的目录看起来像这样
.
..
a.png.jpg
a.png
b.png.jpg
b.png
c.png.jpg
c.png
Run Code Online (Sandbox Code Playgroud)
第一个问题是,我如何重命名文件,以便我可以只有一个扩展名.不是两个.(基本上,我该如何清理原来的错误)?
第二个问题是,在将来,使用xargs,如何将文件的扩展名更改为第二个命令?
我有以下python脚本,它工作得很漂亮.
import urllib2
url = 'http://abc.com' # write the url here
usock = urllib2.urlopen(url)
data = usock.read()
usock.close()
print data
Run Code Online (Sandbox Code Playgroud)
但是,我给它的一些URL可能会重定向它2次或更多次.在加载数据之前,如何让python等待重定向完成.例如,使用上面的代码时
http://www.google.com/search?hl=en&q=KEYWORD&btnI=1
Run Code Online (Sandbox Code Playgroud)
这是在谷歌搜索上点击我的幸运按钮的等价物,我得到:
>>> url = 'http://www.google.com/search?hl=en&q=KEYWORD&btnI=1'
>>> usick = urllib2.urlopen(url)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 400, in open
response = meth(req, response)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 513, in http_response
'http', request, response, code, msg, hdrs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 438, in error …Run Code Online (Sandbox Code Playgroud) 我对开源github克隆感兴趣.我知道我可以托管我自己的git存储库并推送它.我想要一个网络界面.github或bit bucket提供的很多功能.
为什么不使用github?除了玩新技术之外别无他法.
简而言之,我希望在我拥有的服务器上拥有自己的github.
那里有这样的东西吗?
不幸的是,谷歌搜索github clone或open source github返回实际的github页面,因为这些都是与github本身关系的关键术语.
所以,我想编写一个bash脚本,这是一系列步骤,并将其识别为"任务#".但是,每个步骤仅完成,并且只要用户需要就可以运行.
Do task1
if keypressed stop task1 and move on #this is the part I need help with. There can be up to 10 of these move on steps.
Do task2
...
Run Code Online (Sandbox Code Playgroud)
kina喜欢上衣; 它一直在做东西,直到你完全达到q,然而,我想继续下一件事
我的linux盒子上有一个名为images的文件夹.此文件夹已连接到网站,网站管理员可以将图片添加到此网站.但是,当添加图片时,我想要一个命令来运行调整目录中所有图片的大小.
简而言之,我想知道在将新文件添加到特定位置时,如何使服务器运行特定命令.
我有一个使用selenium的webdriver,它为我打开一个浏览器,将它指向一个IP地址,做一堆东西并关闭.
我想知道在此期间访问的所有网址.也就是说,任何已加载的广告,任何对任何网址发出的css调用等等.
这是我正在使用的代码
from selenium import webdriver
browser = webdriver.Firefox(profile) # Get local session of firefox
browser.get(url) # Open a url and wait for it to finish
Run Code Online (Sandbox Code Playgroud) 有办法吗?
tcpdump -i lo -A
Run Code Online (Sandbox Code Playgroud)
并打印所有网址,任何连接?
我已经做好了:
sudo tcpdump -i lo -A | grep Host:
Run Code Online (Sandbox Code Playgroud)
这很棒.但我想知道是否有选项可以在tcpdump中做同样的事情
最后,有没有办法在python中执行此操作而不使用sys命令或Popen/subprocess
我正在写一些需要经常运行具有root权限的命令的软件.
现在,我这样做是通过向用户询问他们的密码一次,保存它,然后提供该密码NSAppleScript作为参数with administrator privileges.
这显然对用户来说是不安全的,因为有人可以访问他们的密码.
我一直在寻找更好的一周时间,但无法找到解决方案.
SMJobBless似乎允许您以更高的权限安装您的应用程序.
我已经关注了应用程序的示例,我从他们的SMJobBlessUtil脚本中收到错误.
这是错误:
SMJobBlessUtil.py: tool designated requirement (identifier "com.domain.AppName.SampleService" and anchor apple generic and certificate leaf[subject.CN] = "Mac Developer: firstName lastName (XXXXXXXXXX)" and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */) doesn't match entry in 'SMPrivilegedExecutables' (anchor apple generic and identifier "com.domain.AppName.SampleService" and (certificate leaf[field.1.2.840.113635.100.6.1.9] /* exists */ or certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and certificate leaf[subject.CN] = "Mac Developer: firstName lastName (XXXXXXXXXX)")
Run Code Online (Sandbox Code Playgroud)
显然,出了点问题.这是各自的plists
服务信息plist
<?xml …Run Code Online (Sandbox Code Playgroud) 我想知道如何处理来自具有多个属性的表单的多个输入.此代码生成我的字段:
<form method="POST" action="test5.php" id="1">
<?
if($_SESSION["peoplecount"] != 0){
for ($i = 0; $i <= $_SESSION["peoplecount"]; $i++) {
echo ' Name<input type="text" name="'.$i.'"> Adult<input type="radio" name="'.$i.'" value="adult" /> Minor<input type="radio" name="'.$i.'" value="minor" /> <br/>';
} }
?>
<input class="button" type="submit" value="I/We Agree" style="width:200px;"/>
</form>
Run Code Online (Sandbox Code Playgroud)
一旦提交 - 或者在"行动"部分中提到的test5.php,
foreach ($_POST as $key => $value) {
print "{$key}: {$value}<br />";
}
Run Code Online (Sandbox Code Playgroud)
而输出是
0: adult
1: adult
2: adult
3: adult
Run Code Online (Sandbox Code Playgroud)
注意它有0,1,2 ......然后是成人.它甚至没有提到文本输入中的人的名字.我可以将表格改为:
</blockquote>
<form method="POST" action="test5.php" id="1">
<?
if($_SESSION["peoplecount"] != 0){
for …Run Code Online (Sandbox Code Playgroud)