Hegwin.Me

In silence I feel full; With speech I sense emptiness.

Takeaways from Ruby Conf China 2023 Day 2

Ruby Conf China 2023 参会笔记 Day 2

This year, AI is really a hot topic, from EverythingGPT to LLM, everyone is talking about this new technological change. At the two-day Ruby Conf China 2023, there were also three topics focusing on AI and LLM, which was very exciting. This post records what I learned on the second day of Ruby Conf. There were two speakers talking about...

Takeaways from Ruby Conf China 2023 Day 1

Ruby Conf China 2023 参会笔记 Day 1

Last weekend (August 19-20, 2023), Ruby Conf China was successfully held in Shanghai. This was the first time since COVID-19 that Ruby Conf was held offline - we've been waiting for it for three years. It's amazing that the venue was the same one we booked for Ruby Conf 2021 three years ago (JW Marriott at Tomorrow Square); Due to...

Format Your Output in Terminal with Ruby

Ruby命令行格式化输出

If we want to output content in the command line, generally speaking, Ruby basic methods are enough, such as `puts`, `print`, and `sprintf`; but if we want to output color in the terminal, table, and progress bar, etc., it will be more difficult to achieve. Here, I want to share gems that I feel good using in this situation: -...

Execute System Commands in Ruby

在Ruby中运行系统命令

There are several ways to invoke system commands in Ruby: 1. Backquotes `` or `%x()`, 2. The `system` method, 3. The `File` class, 4. The Open3 lib. The difference between backquotes and `%x()` and `system` is that: `system` only returns true/false; while `%x` returns the stdout of the command when the command execution succeeds, and an empty string `""` when...

Different methods in Ruby to manipulate directories and files

Ruby中目录和文件操作的几种方式

Creating a directory: Method 1: You can create a directory using Dir.mkdir with an optional parameter to mark the permissions of the directory. For example, if I want to create a `ruby` subdirectory in the /Users/hegwin/Workspace directory, I can do this Dir.mkdir('/Users/hegwin/Workspace/ruby') After normal creation, Dir.mkdir will return the integer 0. This method is similar to the Linux command `mkdir`,...

Ruby 2.5 allows rescue/ensure inside do/end blocks

Ruby 2.5 允许在do/end代码块中使用rescue

This article introduces a new feature of Ruby 2.5: in previous versions of Ruby if you needed to use rescue to catch and handle exceptions, you had to put the `rescue` in to the codes that might throw an exception in the "begin end" block. Since Ruby 2.5, you can use rescue in a normal "do end" block. Note that...

Tools to Help to Improve SQL in Rails

Rails优化SQL可能用到的工具

Have you ever encountered a Rails app that is slow in rendering pages? Are you trying to find out what's causing it to be "slow"? Where is the performance bottleneck? Is it the slow execution of SQL queries (maybe N+1, or not having the right indexes), or is it something else, like the view being too big? Performance optimization has...

How to handle javascript confirm with selennium webdriver

Selenium driver 对 JS Confirm 的处理

JS popup confirmation box is often used in web development, how does the feature test script handle this popup box? page.driver.browser.switch_to.alert.accept # => click OK page.driver.browser.switch_to.alert.dismiss # => click Cancel page.driver.browser.switch_to.alert.text #=> return popup text

Invoke System TTS in Ruby

利用Ruby调用TTS进行文本发声阅读

I want to make a small app where I give him a set of English words and he can randomly read out the words inside. The reason why I have such an idea is that when I was learning English, I wanted to find a word dictation app, but I couldn't find the right one, so I might as well...

How to develop Sinatra project

如何Sinatra部署项目

Sinatra, like Rails, is a rack-based application. Before deployment, add a config.ru file to the root of the sinatra project with the following contents require "myapp" # the main project file run Sinatra::Application # If it is a defined subclass, use the name of the class you defined directly. After this, the process is basically the same as deploying rails,...