Mac 装R LaTex knit全过程

      No Comments on Mac 装R LaTex knit全过程

 
从OSX 10.11后 Apple有了新的安全设定 所以knit不能使用正常方法安装。
以下操作需要网络。
下载并安装:
R:cran.r-project.org/
RStudio: www.rstudio.com/products/rstudio/download/
MacTex: www.tug.org/mactex/mactex-download.html
下载并全部安装。需要很好的网络:加起来3.5个G以上。
设置:
1. 设置-安全性和隐私-任何来源。
2. Launchpad(四指并拢)-其他-终端(terminal)
输入 dsenableroot
输入登陆(开机)密码 3次
输入 sudo ln -s /Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin/pdflatex /usr/texbin/pdflatex
输入登陆密码
3. 打开RStudio-新建RMarkdown文件-点knit-提示要安装一大堆-点OK
会安装很多包。
现在应该可以正常knit了。

onedrivecmd: Yet another Onedrive command-line client for Linux and OSX / Onedrive的命令行工具

github.com/cnbeining/onedrivecmd
 
又撸了一个东西玩。
MS经常给EDU邮箱,但是Linux下没有工具,也就是说有巨大备份需求的大户反而跑不了。
按megacmd,照猫画虎,撸一个这玩意。
MS的SDK挺难用的,文档挺语焉不详的。但是幸好没遇到什么很大的需要debug的东西。
老样子,欢迎PR。
AGPL,麻烦想偷的自己琢磨琢磨先。

Things to read in the free time

      No Comments on Things to read in the free time

Speech side:
Audio Segmenting:
journals.plos.org/plosone/article?id=10.1371/journal.pone.0144610#sec008
Then run FFMpeg with -s and -t with subprocess
Google Speech API: https://cloud.google.com/speech/reference/rest/v1beta1/speech/syncrecognize
curl 'https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=AIzaSyBmmqjUsStJat65IP7KgKuH2cz6rRvlIr8' -H 'Referer: cloud.google.com/' -H 'Origin: cloud.google.com' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.75 Safari/537.36' -H 'Content-Type: text/plain;charset=UTF-8' --data-binary '{"config":{"encoding":"LINEAR16","sampleRate":44100,"languageCode":"en-US","maxAlternatives":1},"audio":{"content":"BASE64_BINARY"}}' --compressed
Less than 1 min inline, better if under 30s
 
Video Side:
Thumbnail: https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
Vision API:
curl 'https://vision.googleapis.com/v1/images:annotate?key=AIzaSyBzeghi0W7mGczap8SC8AmNudYOlwfU-KE' -H 'Referer: cloud.google.com/' -H 'Origin: cloud.google.com' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.75 Safari/537.36' -H 'Content-Type: text/plain;charset=UTF-8' --data-binary '{"requests":[{"image":{"content":"BASE64"},"features":[{"type":"TYPE_UNSPECIFIED","maxResults":50},{"type":"TEXT_DETECTION","maxResults":50}]}]}' --compressed
 
CC:
Question: How to difference the zone of CC?
ASS: Put them there.
 
Style:
ASS: {\pos(369.675,206)} with response, 1s
 
Translation:
Toolkit+API+CAT
 
Transcode:
Release:
 

备忘:逼站个人中心的隐藏API

      3 Comments on 备忘:逼站个人中心的隐藏API

curl 'http://space.bilibili.com/ajax/settings/setPrivacy' -H 'Cookie: f******' -H 'Origin: space.bilibili.com' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-CA,en;q=0.8,en-US;q=0.6,zh-CN;q=0.4,zh;q=0.2' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: space.bilibili.com/******/' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'DNT: 1' --data
'looking_video=0&submited_video=1&fav_video=0&coins_video=0&bangumi=0&played_game=0&groups=0&tags=0' --compressed
 
如果submited_video变成0 那么连过往投稿都不会出现。一键大小姐。

Acfun自动老司机:自动按正则回复私信

有人提议,我就写个。
老规矩,GPLv2,自己测试,风险自担。
 
gist.github.com/cnbeining/b77a4f5762a78fb3878c
 

#!/usr/bin/env python
#coding:utf-8
# Author: Beining  --<i@cnbeining.com>
# Purpose: Auto reply Acfun's msg
# Created: 01/05/2016
# License: GPLv2
import sys
import unittest
import requests
import json
import urllib.parse
import time
cookiepath = ''
VER = '0.01'
global cookiepath
global HEADER
global UA
import re
global regex_expression_list
regex_expression_list = [
        ('ACICFG', 'Hi!')
    ]
#----------------------------------------------------------------------
def read_cookie(cookiepath):
    """str->list
    Original target: set the cookie
    Target now: Set the global header"""
    #print(cookiepath)
    try:
        cookies_file = open(cookiepath, 'r')
        cookies = cookies_file.readlines()
        cookies_file.close()
        # print(cookies)
        return cookies
    except Exception:
        print('Cannot read cookie, may affect some videos...')
        return ['']
#----------------------------------------------------------------------
def get_unread_list():
    """"""
    req = requests.get('http://www.acfun.tv/api/mail.aspx?name=getGroups&page=1', headers = HEADER)
    content = json.loads(req.content)
    return [str(i) for i in b['unReadList']]
#----------------------------------------------------------------------
def get_last_msg_by_p2p(p2p):
    """"""
    req = requests.get('http://www.acfun.tv/api/mail.aspx?name=getMails&page=1&p2p={p2p}'.format(p2p = p2p), headers = HEADER)
    content = json.loads(req.content)
    return json.loads(content['mailList'][0])
#----------------------------------------------------------------------
def get_regex_object_list(regex_list):
    """"""
    list_this = []
    for i in regex_list:
        list_this.append(((eval('re.compile(r"{regex}")'.format(regex = i[0]))), i[1]))
    return list_this
#----------------------------------------------------------------------
def get_reply_by_text(text):
    """"""
    for i in regex_object_list:
        if i[0].match(mail):
            return i[1]
#----------------------------------------------------------------------
def send_reply(userId, content):
    """"""
    content = urllib.parse.quote(content)
    data = 'userId={userId}&content={content}'.format(userId = userId, content = content)
    requests.post('http://www.acfun.tv/api/mail.aspx?name=newMail', headers=HEADER, data=data)
#----------------------------------------------------------------------
def main():
    """"""
    unReadList = get_unread_list()
    for p2p in unReadList:
        mail = get_last_msg_by_p2p(p2p)
        reply = get_reply_by_text(mail['text'])
        fromuId = mail['fromuId']
        fromusername = mail['fromusername']
        send_reply(fromuId, reply)
        print('Received: {mail} from {fromusername}, Sent: {reply}')
#----------------------------------------------------------------------
def usage():
    """"""
    pass
if __name__=='__main__':
    argv_list = []
    argv_list = sys.argv[1:]
    cookiepath,wait_time = '', 5
    try:
        opts, args = getopt.getopt(argv_list, "hc:t:",
                                   ['help', "cookie=", 'time='])
    except getopt.GetoptError:
        usage()
        exit()
    for o, a in opts:
        if o in ('-h', '--help'):
            usage()
            exit()
        if o in ('-c', '--cookie'):
            cookiepath = a
        if o in ('-t', '--time'):
            wait_time = a
    if cookiepath == '':
        cookiepath = './accookies'
    if not os.path.exists(cookiepath):
        print('Unable to open the cookie\'s file!')
        print('Please put your cookie in the file \"bilicookies\" or set a path yourself')
        exit()
    cookies = read_cookie(cookiepath)[0]
    UA = 'Acfun Auto Msg/{VER} (cnbeining@gmail.com) (Python-urllib/{python_ver_str}, like libcurl/1.0 NSS-Mozilla/2.0)'.format(VER = VER, python_ver_str = python_ver_str)
    HEADER = {'User-Agent': UA, 'Cache-Control': 'no-cache', 'Pragma': 'no-cache', 'Cookie': cookies[0]}
    regex_object_list = get_regex_object_list(regex_expression_list)
    global regex_object_list
    while 1:
        main()
        time.sleep(wait_time)