我有一些内容(html)由于这个javascript(来自此页面)而被编码并发送到我的rails应用程序:
function encode_utf8_b64(string) {
return window.btoa(unescape(encodeURIComponent(string)));
}
Run Code Online (Sandbox Code Playgroud)
对应的js代码将其恢复原状是这样的:
function decode_utf8_b64(string) {
return decodeURIComponent(escape(window.atob(string)));
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,在decodeURIComponent()的ruby中是否有相应的东西?到目前为止,我有这个让它成为出路的一部分,但我错过了decodeURIComponent的最后一步:
CGI::escape(Base64.decode64(string))
Run Code Online (Sandbox Code Playgroud) 我有一组原点和目标坐标,我在它们之间绘制线段.问题是,我想用颜色而不是geom_segment()提供的箭头来指示线的方向.像蓝色过渡到红色,以指示方向.
使用ggplot2有一种简单的方法吗?
示例数据:
points <- data.frame(long=runif(100,-122.4154,-122.3491))
points$lat <- runif(100,37.5976,37.6425)
points$long2 <- runif(100,-122.4154,-122.3491)
points$lat2 <- runif(100,37.5976,37.6425)
# add distance
library(geosphere)
points$miles <- apply(points, 1,
function(x) distHaversine(p1=c(x["long"],x["lat"]),p2=c(x["long2"],x["lat2"]),r=3959))
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经能够以不同的方式对线条进行着色,但是我没有找到一种方法在同一线段上有两种颜色并在两者之间转换,当我只有一个起点和终点时,两者之间没有点:
ggplot(points,aes(x=long,xend=long2,y=lat,yend=lat2,color=miles)) +
geom_segment() +
scale_color_gradient2(low="red",high="blue",midpoint=median(points$miles))
Run Code Online (Sandbox Code Playgroud) 对于工头,我正在尝试使用两个.env文件启动我的rails应用程序.
一个是常规.env文件,但是第二个文件有额外的变量要加载.我正在尝试使用本指南中提到的方法来保持配置变量的代码:https://devcenter.heroku.com/articles/config-vars
这是我的Procfile:
web: bundle exec rails server thin -p $PORT --env $RACK_ENV,var.env
Run Code Online (Sandbox Code Playgroud)
我的问题是,即使文档说它应该是可能的,工头似乎也不想为-env采用这两个参数:
-e, - env
指定备用环境文件.您可以使用以下命令指定多个文件: - env file1,file2.
当我尝试用"foreman start"运行它时,我收到错误:
06:22:46 web.1 | You did not specify how you would like Rails to report deprecation notices for your development,var.env environment, please set config.active_support.deprecation to :log, :notify or :stderr at config/environments/development,var.env.rb
Run Code Online (Sandbox Code Playgroud)
它似乎并不想分割"development,var.env"并单独处理它们.当我查看工头代码时,看起来它应该只是对逗号做一个简单的拆分,所以我不知道我做错了什么或者它是一个错误.
我想用R生成一个随机的20位数字.
我的第一次尝试就是这样做
runif(1,10000000000000000000,9999999999999999999)
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用,因为R将9999999999999999999四舍五入到10000000000000000000.它似乎不接受"9999"数字,直到我下降到15位数:
> 9999999999999999999
[1] 10000000000000000000
> 999999999999999999
[1] 1000000000000000000
> 99999999999999999
[1] 100000000000000000
> 9999999999999999
[1] 10000000000000000
> 999999999999999
[1] 999999999999999
> 99999999999999
[1] 99999999999999
> 9999999999999
[1] 9999999999999
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来解决这个问题?