这个超级简单。 Rails4 中需要参考:  https://stackoverflow.com/questions/28485137/multiple-database-connection-in-rails-4/28490913 1. config/database.yml 中,增加第二个数据库配置 second_production: ... 2.  在对应的mo...
Ruby Faceplusplus识别身份证,ocr,idcard,faceid,
供以后参考。 值得一提的是,就使用curl 来提交文件即可。不要使用 restclient 等ruby第三方包。因为发现这些都对post 请求支持的不好。对添加附件支持的不好。 代码如下: def check_id_card options id_card_approval = options[:id_card_approval] type = options[:type] i...
Ruby Rails分页:willpaginate,对于大数据量,不要用@count,会引起加载缓慢,要使用without
前端erb 页面:  <%= link_to_prev_page @trades, "上一页" %><%= link_to_next_page @trades, "下一页" %> 后端controller:  调用.without_count 方法 @trades.page(params[:page]).per(1000).without_count
保证某个进程不断运行的脚本
新版本的 openethereum 经常莫名其妙的挂掉 。 非常奇怪。 没办法。所以需要使用crontab 来进行管理。 1. 写一个脚本 vim /home/ubuntu/keep_eth_running.rb , 内容如下: grep_command = "ps -ef | grep openethereum | grep -v grep" start_command = "cd ~ &...
Ruby 获得前一个周2,周三的时间点的办法:gemchronic
参考:https://github.com/mojombo/chronic/ require 'chronic' Time.now #=> Sun Aug 27 23:18:25 PDT 2006 Chronic.parse('tomorrow') #=> Mon Aug 28 12:00:00 PDT 2006 Chronic.parse('monday', :conte...
Rails Kaminari在进行大表分页的解决办法:without_count
参考:  https://github.com/amatsuda/kaminari#paginating-without-issuing-select-count-query kaminari的 paginate 方法, 会对整个 result list 进行判断, 看看它的 count是多少.  对于表的记录特别大的时候,  (例如1个亿), 很耗时,大约几...
Rails Rails中的默认嵌套transactionnestedtransaction 结论:begin界限从最外层开始。只有一层
最精准的答案见:https://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html 结论:只有一层,就是最外层,里面出错了,外面跟着一起回滚。(我最喜欢) 如果希望外面的transaction不要跟着里面回滚,就参考这个:https://stackoverflow.com/questions/3394...
Eth使用rawtransaction创建转账eth,转账token的过程,erc20归拢
参考: 这个文章有入门线索: https://ethereum.stackexchange.com/questions/3386/create-and-sign-offline-raw-transactions 确认了线索: https://ethereum.stackexchange.com/questions/43980/how-to-transfer-ethereum-f...
微信支付 总结文章
微信支付的一些坑,这个用H5做的话,必读。https://blog.niceue.com/front-end-development/wechat-h5-payment-process-as-well-as-some-pits.html 微信支付分成好几种不用的业务, 需要首先明确你用的是哪些, 例如: 普通的支付, 企业支付企业红包App支付(安卓,IOS)H5支付(脱离了微信公众号,在...
Ruby 把某个文件夹下的所有文件,名字从大写改成小写renamefilesfromuppercasetodowncase
# 把某个文件夹下的所有文件, 名字从大写改成小写.Dir.glob("./**/*").sort{|x| x.size}.each do |name| x = name.split('/') newname = (x[0..-2] + [x[-1].downcase]).join('/') File.rename(name, newname)end 方法很巧妙, 把文件全名做个排序,...
Rust 以?结尾的调用,跟rails中的try非常类似,为了更方便的处理异常
参考:https://doc.rust-lang.org/edition-guide/rust-2018/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.html 我们看到,一些方法调用,会 用?结尾。 例如:  db.execute(xx)?;  这样的作用是...
Rust Actix3application(scope路由,静态变量,全局线程共享变量,virtualhost以及配置config)
参考:https://actix.rs/docs/application/ 1. 增加 /app 这样的scope , 来访问路由 ( 等同于 rails中的 namespace route)  创建新项目, 修改src/main.rs:  use actix_web::{web, App, HttpResponse, HttpServer, Responder}; u...
Ruby 使用puma5,以及配置文件详解
前些日子被内存泄露困扰,使用了一些办法。突然发现puma的版本用的还是3.x,  果断切换到最新的5.1.1 配置具体参考: https://github.com/puma/puma/blob/master/lib/puma/dsl.rb 看的时候,直接看方法定义即可。 例如 worker 1 的意思是啥,直接看上面 dsl.rb 的 def worker 方法即可。...
Mysql 使用general Log来查看所有的sql语句
在diesel框架中, 不像rails那样会打印出所有的SQL,貌似该框架也没实现这个功能,所以在特别需要的时候,需要在本地开发环境打印SQL 1. 修改配置文件 # # * Logging and Replication # # Both location gets rotated by the cronjob. # Be aware that this log type is a ...
Rails Rails6由于gemlisten报错listenerror:unabletomonitordirectoriesforchanges
参考:  https://stackoverflow.com/questions/42225677/listen-error-unable-to-monitor-directories-for-changes echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo...
Redis 性能优化相关optimization
配置文件:   /etc/redis/redis.conf 最大连接数: maxclients  1000000 允许访问: bind 0.0.0.0 查看slow log:  showslowlog get 10 查看最近10个慢操作 查看当前连接: client list 查看链接信息: info clients 使用连接池:  http...
Ruby 一个非常专业的大神的内存调试memoryleak
参考:  http://www.be9.io/2015/09/21/memory-leak/
Mysql 分析的不准确啊
Loading development environment (Rails 4.2.10) irb(main):001:0> Order.where('created_at > ? and created_at < ? and state = 0', "2019-09-02 00:00:00", "2019-09-02 12:00:00").count => 949...
Redis 使用redis Audit来分析redis的key的情况,以及原生命令,查看redis的key的value的容量
$ info keyspace 也可以看到, 某个redis 下有多少key  0. 使用原生命令: 127.0.0.1:6xxx[1]> debug object klines:btcusdt:k:1Value at:0x7fefbd2d86e0 refcount:1 encoding:quicklist serializedlength:1527872 lru:19144...
Ruby 记一次追踪rails内存泄露
1. 采用了 oink 工具,来测量不同的action对于内存的消耗, 运行2周之后, 查看日志,发现 内容如下 ---- MEMORY THRESHOLD ---- THRESHOLD: 75 MB -- SUMMARY -- Worst Requests: 1. Dec 03 10:26:15, 19091140 KB, managers/sessions#new 2. Dec ...