阿里云oss 批量检测文件是否存在

虽然阿里云oss的sdk提供了检测文件是否存在,但是在批量处理的时候你就会发现检测一次需要联网一次,如果文件过多最后会提示你链接数超过限制,最终无法进行检测了。

下面是阿里云提供的示例代码:

# -*- coding: utf-8 -*-
import oss2

# 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
auth = oss2.Auth('', '')
# Endpoint以杭州为例,其它Region请按实际情况填写。
bucket = oss2.Bucket(auth, 'http://oss-cn-hangzhou.aliyuncs.com', '')

exist = bucket.object_exists('')
# 返回值为true表示文件存在,false表示文件不存在。
if exist:
	print('object exist')
else:
	print('object not eixst')

那么其实可以反过来想,直接拉文件目录落下来进行比较,列举文件的代码如下:

# -*- coding: utf-8 -*-

# 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
auth = oss2.Auth('api-key', 'api-secret')
# Endpoint以杭州为例,其它Region请按实际情况填写。
bucket = oss2.Bucket(auth, 'https://oss-cn-beijing.aliyuncs.com', 'bucket-name')

file_arrary = []
# 设置Delimiter参数为正斜线(/)。
for obj in oss2.ObjectIterator(bucket, delimiter='/'):
    # 通过is_prefix方法判断obj是否为文件夹。s
    if obj.is_prefix():  # 文件夹
        #print('directory: ' + obj.key)
        for obj2 in oss2.ObjectIterator(bucket, prefix='%s' % obj.key):
            #print('file: ' + obj2.key)
            file_arrary.append(obj2.key)
    else:  # 文件
        file_arrary.append(obj.key)

如果要判断文件是否存在,只需要在数组中进行比较就可以了

file_arr = []
for file in file_arr:
    if file in file_arrary :
           print('esixts')
    else:
           print('not exists')

 

使用apple script管理进程

代码如下:

tell application "System Events"
	set listOfProcesses to (name of every process where background only is false)
	tell me to set selectedProcesses to choose from list listOfProcesses with multiple selections allowed
end tell
--The variable `selectedProcesses` will contain the list of selected items.
repeat with processName in selectedProcesses
	do shell script "Killall " & quoted form of processName
end repeat

和系统的活动监视器相比,好处在于只有前台进程。

xcode 9.2 集成obfuscator-llvm

Obfuscator-LLVM is a project initiated in June 2010 by the information security group of the University of Applied Sciences and Arts Western Switzerland of Yverdon-les-Bains (HEIG-VD).

The aim of this project is to provide an open-source fork of the LLVM compilation suite able to provide increased software security through code obfuscation and tamper-proofing. As we currently mostly work at the Intermediate Representation (IR) level, our tool is compatible with all programming languages (C, C++, Objective-C, Ada and Fortran) and target platforms (x86, x86-64, PowerPC, PowerPC-64, ARM, Thumb, SPARC, Alpha, CellSPU, MIPS, MSP430, SystemZ, and XCore) currently supported by LLVM.

对于这个插件,网上的安装文章相对来说还是挺多的,例如官方的文档https://github.com/obfuscator-llvm/obfuscator/wiki/Installation,再例如 http://www.exchen.net/ios-hacker-obfuscator-llvm-xcode%E9%9B%86%E6%88%90%E9%85%8D%E7%BD%AE.html。已经写的都非常详细了,按照上面的文章基本都可以配置好了,唯一需要注意的是如果xcode的版本不同,对应的里面的字符串可能不一致,例如:

<string>Apple LLVM 8.0</string> -> <string>Obfuscator 4.0</string>

如果用的是xcode9 那么应该是Apple LLVM 9.0。同时如果在编译之前没有安装cmake,可以通过homebrew来安装还是非常方便的。

brew install cmake

Homebrew installs the stuff you need that Apple didn’t.

如何安装homebrew请参考这个链接:https://brew.sh/

如果不想跳转上面的链接,直接在终端中执行下面的安装代码即可:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

这里想说的是安装完成之后,还可能会出现别的问题,例如提示编译的时候提示下面的信息:

clang-4.0: error: cannot specify -o when generating multiple output files
Continue Reading

osx cycript image not found

今天在osx上运行cycript的时候出现了如下的错误:

/Users/obaby/Desktop/小项目/keygen/cycript_0.9.594/cycript
dyld: Library not loaded: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/libruby.2.0.0.dylib
Referenced from: /Users/obaby/Desktop/小项目/keygen/cycript_0.9.594/Cycript.lib/cycript-apl
Reason: image not found
Abort trap: 6

看起来貌似是因为libruby.2.0.0.dylib文件没有找到,打开ruby目录发现果然没有2.0的文件,只有2.3的。处理方法也很简单,直接把2.3的复制一份,改为2.0即可

百度语音识别 语音唤醒失败

半夜起来给小朋友冲奶粉,于是忽然想到了那个在机柜里落灰的树莓派。当时用百度的语音识别和合成用python实现了一些功能。但是并没有实现语音唤醒,于是要想实现语音唤醒就只能不断的轮询接口,然后发送到百度云进行识别。但是觉得这种方式太坑了,什么都上传了,感觉随时在被监听一样。今天又看了下百度的sdk发现支持语音唤醒了。还能自定义唤醒词。

唤醒词规则

1 . 支持设置10个唤醒词,包含指令唤醒词和自定义唤醒词,指令唤醒词不支持自定义;10个唤醒词中,最多可以设置3个自定义唤醒词,最多可以包含3个两字指令唤醒词(如播放、暂停、拍照等)

2 . 已经支持的指令唤醒词有:
相机类:拍照、茄子
音乐类:增大音量、减小音量、播放、停止、暂停、上一首、下一首、
电灯类:打开电灯、关闭电灯、增大亮度、减小亮度
手电筒类:打开手电筒、关闭手电筒

3 . 自定义唤醒词可根据应用的个性化需求来免费定制,例如您的应用希望通过“你好百度”启动应用,则就可以设置“你好百度”为唤醒词;

4 . 建议每个自定义唤醒词在3至5个字之间(这里的1个字是指1个汉字、或1个英文字母),4个字最佳;一个唤醒词可以包含最多2个(含)英文字母;唤醒词中暂时不支持纯英文单词,如california;

5 . 唤醒词定制的温馨提示:请勿选择太常用的词作为唤醒词,例如”吃饭吧”,在生活中经常会用到,容易误唤醒;为保证唤醒效果,不同意义的唤醒词,请考虑唤醒词之间的差异,尽量保证唤醒词之间不易混淆;唤醒词过短会导致唤醒错误率较高,请不要选择太多短唤醒词(包括指令唤醒词);

6 . 唤醒词的音节覆盖尽量多,长度最少为4个音节;相邻音节请尽可能规避,字要发音清晰响度大;生僻字请尽量规避;零声母字请尽量规避;请避免使用叠词;例如:质量较高的唤醒词:“百度外卖”,音节覆盖多差异大;质量较差的唤醒词:“语音识别”,“语音”两个字均为零声母字,不是一个质量高的唤醒词;

Continue Reading