用ruby执行系统命令

反引号 返回标准输出 output = `ls` puts "output is #{output}" Result of above code is $ ruby main.rb output is lab.rb 反引号执行系统命令时,会把异常抛给主线程 反引号会从主进程新开一个进程执行命令,如果子进程发生异常,会传递给主进程,如果主进程没有对异常进行处理,主

xpath用法

整理自https://devhints.io/xpath#prefixes Descendant selectors h1 //h1 div p //div//p ul > li //ul/li ul > li > a //ul/li/a div > * //div/* :root / :root > body /body Attribute selectors #id //*[@id="id"] .class //*[@class="class"] …kinda input[type="submit"] //input[@type="submit"] a#abc[for="xyz"] //a[@id="abc"][@for="xyz"] a[rel] //a[@rel] a[href^='/'] //a[starts-with(@href, '/')] a[href$='pdf'] //a[ends-with(@href, '.pdf')] a[href*='://'] //a[contains(@href, '://')] a[rel~='help'] //a[contains(@rel, 'help')] …kinda

yakuake配置color-theme

打开管理配置, –> appearance –> new 给新的 color theme 命名(gruvbox),然后点击应用,保存。 打开 .kde/share/apps/konsole/gruvbox.colortheme,清空文件内容 在 manjaro 中, 该文件位于 ~/.local/share/konsole/ 目

rails发送qq邮件的配置

rails 中使用邮件服务是非常方便的,直接加配置文件就可以,参考指南 qq 邮箱正确的配置如下 production.rb / development.rb ActionMailer::Base.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.default :charset => "utf-8" ActionMailer::Base.smtp_settings = { :address => 'smtp.qq.com', :port => 465, :domain => 'qq.com', :user_name => ENV['qq_mail_address'] # 授权码 :password => ENV['qq_mail_address'] :authentication => 'plain', :ssl => true, :enable_starttls_auto => true } 切记,qq 邮箱后台要开启

postgres系列之用户及权限管理

在初始化数据库系统时,有一个预定义的超级用户,这用户的名称与初始化该数据库的操作系统用户名相同,默认是 postgres,在这个超级用户连接数据库,然后创建出更多的用户。 创建用户和角色 创建用户与角色的语

ruby_heredoc的用法

整理自ruby-china 基础的用法 def print_heredoc puts <<EOF this is the first line this is the second line EOF end print_heredoc 输出: this is the first line this is the second line 如果你觉得代码太难看(这根本不符合 Ruby 的风格),你可能会这样写: def print_heredoc puts <<EOF this is the first line this is the second line EOF end print_heredoc 你会发现

rails_多态关联

什么是多态关联 假如有三个模型,分别是 用户, 产品, 图片。图片为用户所有,也为产品所有。我们可以创建两个 picture 的模型,如下 rails g modle picture_user user_id:integer name:string url:string rails g modle picture_product product_id:integer name:string url:string class PictureUser < ApplicationRecord belongs_to :user end class PictureProduct < ApplicationRecord belongs_to :product end 这样我们就可以使用user.p

rails_action_cable使用

安装 redis gem redis bundle install 修改 cable.yml development: adapter: redis 生成订阅 rails g channel block speak 连接设置 连接是客户端-服务器通信的基础。每当服务器接受一个 WebSocket,就会实例化一个连接对象。所有频道订阅(channel subscription)

vim脚本插件化

日积月累,自己写的 vim 脚本越来越多,大大的方便了日常编写任务,但是这些脚本没有做成插件的形式,导致换一台新机器时,不方便下载使用,下面就介绍一下如何把 自己写的脚本做成一个插件,可以在vimrc中使用Pl

vim自定义命令

本文章为转载内容,点击查看原文章https://zhuanlan.zhihu.com/p/27389503 使用脚本语言,可以更灵活地定制编辑器以完成复杂的任务。 自定义命令 Vim 编辑器允许定义自己的命令,我

自动添加序号

需求 给一段文字自动添加序号,要求本行的序号可以根据上一行的序号自动增一,若上一行没有序号,则从 1 开始 实现 用 ruby 编写 vim 脚本非常容易实现 " 每行的前面添加序号,根据上一行序号自动递增,若上一行没有序号,则从1

自定义range对象

ruby 中有个 range 对象,可以自动推测范围内的数据,比如: (1..100).each do |i| puts i end 会输出 1 到 100 内的所有数字 自定义 如果我们有一个自定义的对象,假如名字为Ym class Ym attr_accessor :year, :month def initialize @year, @month = year, month end end 若是想在Ym上使用((Ym.new(20

vim中的正则表达式

首先,在哪些情况下会用到正则表达式? 使用正则表达式的命令最常见的就是 / 和 ? 命令。其格式如下: /正则表达式 ?正则表达式 另一个很有用的命令就是 :s(替换)命令,将第一个//之间的正则表达式替换成第二个//

rack-cors解决Ajax跨域问题-CORS

什么是跨域 理解跨域首先必须要了解同源策略。同源策略是浏览器上为安全性考虑实施的非常重要的安全策略。 那么什么是同源?我们知道,URL 由协议、域名、端口和路径组成,如果两个 URL 的协议、域名和端口相同,则表示

用ruby编写vim脚本

在开始编写插件之前,你需要确认 Vim 是否支持 Ruby,通过以下命令来判别: $ vim --version | grep +ruby 如果输出为空,则表示你当前的 vim 不支持 Ruby,需要重新编译一下,并启用对 Ruby 的支持。 如果没有问题那就开始吧! 下面的示例是