Skip to content

Instantly share code, notes, and snippets.

View badbye's full-sized avatar
Dreaming

yalei badbye

Dreaming
  • China
View GitHub Profile
@badbye
badbye / rmd-translate.R
Last active July 7, 2023 11:01
translate Rmd files
library(httr2)
library(knitr)
AZURE_API_URL = "https://xxx.openai.azure.com/openai/deployments/davinci-003/completions?api-version=2022-12-01"
AZURE_API_KEY = "xxx"
PROMPT = "你是一个优秀的文学家和工程师。你将逐行翻译 Human 给定的 markdown 格式的文本,返回流畅易懂的中文。如果给定的内容中某一行以`<--`开头,以`-->`结尾,则忽略该行不翻译。\n行内的文本遇到以下规则时,... 所表示的内容也不翻译:\n1. `r ...`\n2. \\ref(...)\n\nHuman: China is the greatest country in the world. ^[You have to admit it.]\n<-- The US may disagree -->\nsee table \\ref(tb), its population is `r 10**8`.\nAI: 中国是世界上最伟大的国家。 ^[你必须承认这个事实。]\n<-- The US may disagree -->\n见表 \\ref(tb), 它的人口数量是 `r 10**8`。\n\nHuman: %s\nAI: "
commented = function(line) {
if (is_commented(line)) line else paste0('<!-- ', line, ' -->')
@badbye
badbye / kyuubi_adb_spark.md
Last active March 31, 2023 03:39
Use Kyuubi with Aliyun's Analytic Spark

Kyuubi & Aliyun ADB Spark

AnalyticDB MySQL Spark 是阿里云 AnalyticDB 产品中的 Serverless Spark 服务, 取代了之前的 DLA Serverless Spark。产品内部已经集成了交互式查询、Notebook 等服务,也提供 API 调用,但仍旧不够灵活。如果能够与 Kyuubi 结合,就可以有更丰富的 JDBC、REST API 连接方式。

Kyuubi 与 Spark 的连接大致分三步:

  1. 通过 spark-submit 启动一个 SparkSQLEngine,启动后 Spark Server 会把自己注册到 Zookeeper 服务中
  2. Kyuubi Server 通过 Zookeeper 查到到 Spark Server 的地址
  3. Kyuubi Server 连接 Spark Server,为客户端提供交互式查询服务
@badbye
badbye / free_doc88.js
Created February 8, 2022 04:39
免费下载道客巴巴的文档. download file from doc88.com without paying
$('#continueButton').click()
var keeps = $("#pageContainer").parentsUntil('body').toArray().concat($("#pageContainer").children().toArray())
var divs = $("div:not(#pageContainer)").toArray()
divs.filter(x => keeps.indexOf(x) < 0).forEach(x => x.remove())
window.print()
@badbye
badbye / gradio_example.py
Created July 14, 2019 09:43
Example of customized model
# encoding: utf8
import gradio
import re
import numpy as np
# A very simplistic function that capitalizes each letter in the given string
def big(x):
if re.match('^[a-zA-Z]+$', x):
@badbye
badbye / header.js
Created March 22, 2019 08:55
为xaringan的图片添加zoom效果
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-zoom/1.7.21/jquery.zoom.min.js'></script>
<script>
(function () {
$('.hover_large img')
.wrap('<span style="display:inline-block"></span>')
.css('display', 'block')
.parent()
.zoom();
@badbye
badbye / mapReduce.QR.R
Created November 25, 2018 10:03
solve OLS in linear regression using map reduce
# referenece: https://ieeexplore.ieee.org/document/7345473/
# 验证该论文的分布式计算结果
#' 准备数据
X = matrix(rnorm(400), 20, 20)
Y = rnorm(20)
#' 计算分隔数据的 index
splitByRowIndex = function(nrows, size){
@badbye
badbye / mapReduce.QR.R
Created November 25, 2018 10:03
solve OLS in linear regression using map reduce
# referenece: https://ieeexplore.ieee.org/document/7345473/
# 验证该论文的分布式计算结果
#' 准备数据
X = matrix(rnorm(400), 20, 20)
Y = rnorm(20)
#' 计算分隔数据的 index
splitByRowIndex = function(nrows, size){
@badbye
badbye / baseFont.R
Last active June 17, 2019 06:32
为不同系统设置不同的字体,保证R语言画出的图可以正常显示中文
Sys.setlocale("LC_CTYPE", "UTF-8")
.setDefaultFont = function(windowsFont = 'song', linuxFont = 'monaco', macOSFont = 'STHeiti'){
# set base font for different system
osType = as.character(Sys.info()["sysname"])
baseFont = ifelse(osType == 'Darwin', macOSFont,
ifelse(osType == 'Linux', linuxFont, windowsFont))
message(sprintf('System: %s; base font: %s', osType, baseFont))
# for base plot
@badbye
badbye / py_str_format.py
Created December 5, 2017 07:43
Compare `%s` with the `format` method in python
import time
# python3.6.1: `%s` is 10 tiems faster than `format`
>>> t1=time.time();c=['%s %s' %(1, 2) for i in range(10000)];time.time()-t1
0.0005083084106445312
>>> t1=time.time();c=['{0} {1}'.format(1, 2) for i in range(10000)];time.time()-t1
0.005129098892211914
# python2.7.10 `%s` is 2 tiems faster than `format`
>>> t1=time.time();c=['{0} {1}'.format(1, 2) for i in range(10000)];time.time()-t1
# encoding: utf8
"""
Created on 2017.10.24
@author: yalei
"""
import numpy as np