Skip to content

Instantly share code, notes, and snippets.

View flyerhzm's full-sized avatar
🏠
Working from home

Richard Huang flyerhzm

🏠
Working from home
View GitHub Profile
@flyerhzm
flyerhzm / fetch_gem_changelogs.rb
Last active August 14, 2024 11:07
Fetch gem changelogs based on Gemfile.lock diff, you can update gems in Gemfile.lock, then run `bundle exec ruby fetch_gem_changelogs.rb | more`
require 'bundler'
require 'net/http'
require 'json'
require 'uri'
# Function to fetch gem information from RubyGems.org
def fetch_gem_info(gem_name)
url = URI("https://rubygems.org/api/v1/gems/#{gem_name}.json")
response = Net::HTTP.get_response(url)
@flyerhzm
flyerhzm / syntax-tree-query-mutation-ruby.rb
Last active May 18, 2023 12:29
Use node-query and node-mutation via syntax-tree
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'syntax_tree'
gem 'syntax_tree_ext'
gem 'node_query'
gem 'node_mutation'
end
const snippet = "react/html-elements-to-react-bootstrap-components"
require(`../../lib/${snippet}`);
const dedent = require('dedent');
const { assertConvert } = require("../utils");
describe(snippet, () => {
describe("simple", () => {
const input = dedent(`
import React from 'react';
@flyerhzm
flyerhzm / html-elements-to-react-bootstrap-components.js
Last active March 6, 2022 04:45
convert html elements to react bootstrap components
const Synvert = require("synvert-core");
new Synvert.Rewriter("react", "html-elements-to-react-bootstrap-components", () => {
description("convert html elements to react bootstrap components");
withinFiles(Synvert.ALL_FILES, function () {
let needImport = false
withNode({ type: "JSXElement", openingElement: { name: { name: "div" } } }, () => {
let matched = false;
gotoNode("openingElement", () => {
-['.']
+%w[.]
-included do
- has_many :build_items, dependent: :destroy
-end
+included { has_many :build_items, dependent: :destroy }
-array.each { |element| element.to_s }
+array.each(&:to_s)
Jekyll.logger.error "Dependency Error:", <<~MSG
- Yikes! It looks like you don't have #{name} or one of its dependencies installed.
+ Yikes! It looks like you don't have #{name} or one of its dependencies installed.
In order to use Jekyll as currently configured, you'll need to install this gem.
If you've run Jekyll with `bundle exec`, ensure that you have included the #{name}
- gem in your Gemfile as well.
+ gem in your Gemfile as well.
- The full error message from Ruby is: '#{e.message}'
- args = args.strip.split(" ") # Shellwords?
+ args = args.strip.split(" ")
- args = args.strip.split(" ") # Shellwords?
+ args = args.strip.split(" ")
def title
- Utils.slugify(@obj.data["slug"], :mode => "pretty", :cased => true) ||
- Utils.slugify(@obj.basename_without_ext, :mode => "pretty", :cased => true)
+ Utils.slugify(@obj.data["slug"], :mode => "pretty", :cased => true) || Utils.slugify(@obj.basename_without_ext, :mode => "pretty", :cased => true)
end
-drive = Dir.pwd.sub(%r!^([^\/]+).*!, '\1')
+drive = Dir.pwd.sub(%r!^([^\/]+).*!, "\\1")
-require_relative "liquid_renderer/file"
+require_relative("liquid_renderer/file")