Hegwin.Me

The bitterest tears shed over graves are for words left unsaid and deeds left undone.

Utilizing Subscription Schedules in Stripe: A Journey of Discovery

Stripe大冒险:利用 Subscription Schedule 更新订阅

Updating subscriptions in Stripe using its API is straightforward, but there are instances where immediate updates are not feasible due to invoice dates or the nature of the subscription product. In such cases, scheduling an update is necessary. Subscription Schedule is a very powerful feature. However, in my personal development experience, I initially encountered a lot of confusion when using...

How to Deploy Ruby Code on AWS Lambda: A Brief Guide from Manual to Automated

从手动到自动,部署 Ruby 代码到 AWS Lambda

Recently, I've made some new attempts to develop and deploy some of the features that are not very relevant to the main business as separate AWS Lambda - it's also a step forward in the trend of serverless development. This post is based on what I learned from deploying Ruby code to AWS Lambda. Currently, AWS Lambda supports languages such...

Upgrade Ruby from 3.0 to 3.2

升级 Ruby 到 3.2

Now that Ruby 3.3 preview 2 has been released, I've been working on upgrading a 3.0 project to 3.2. I've encountered a few problems with upgrading from 3.0 to 3.2, so I'm going to try to organize them here, and hopefully they'll help. ## Bundled gems In Ruby 3.1, some libs went from being standard libraries to bundled gems, such...

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...