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 / 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
@flyerhzm
flyerhzm / image.rb
Last active August 22, 2022 11:37 — forked from basgys/simple_paperclip.rb
paperclip without activerecord
class Image
extend ActiveModel::Naming
extend ActiveModel::Callbacks
include ActiveModel::Validations
include Paperclip::Glue
define_model_callbacks :save, only: [:after]
define_model_callbacks :destroy, only: [:before, :after]
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", () => {
# it is forked from https://github.com/xijo/reverse-markdown/blob/master/reverse_markdown.rb
require 'rexml/document'
require 'benchmark'
include REXML
include Benchmark
class ReverseMarkdown
# set basic variables:
# - @li_counter: numbering list item (li) tags in an ordered list (ol)
-['.']
+%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