Skip to content

Instantly share code, notes, and snippets.

View xiaohui-zhangxh's full-sized avatar

xiaohui xiaohui-zhangxh

  • Tanmer Inc.
  • 中国
View GitHub Profile
@xiaohui-zhangxh
xiaohui-zhangxh / liquid_template_tags_thread_safe.rb
Last active March 9, 2023 02:22
Make liquid template's tags to be thread safe
View liquid_template_tags_thread_safe.rb
# 使用方法:
#
# Liquid::Template.include Liquid::TemplateTagsThreadSafe
#
# Liquid::Template.with_thread_safe do
# Liquid::Template.register_tag('test', Liquid::Tag)
# Liquid::Template.tags['test'] # => Liquid::Tag
# end
#
# Liquid::Template.tags['test'] # => nil
@xiaohui-zhangxh
xiaohui-zhangxh / create_engine
Last active March 6, 2023 06:00
Rails 项目在 engines/ 目录下生成子模块 engine
View create_engine
#!/usr/bin/env ruby
name = ARGV[0]
if name.to_s.strip.empty?
puts "usage: bin/create_engine <name>"
exit(1)
end
cmd = <<-CMD
bin/rails plugin new engines/#{name}_engine \
@xiaohui-zhangxh
xiaohui-zhangxh / ucloud_api.rb
Created March 15, 2020 13:53
通过 UCloud API 管理资源
View ucloud_api.rb
# frozen_string_literal: true
require 'json'
require 'net/http'
require 'digest'
class UcloudAPI
API_HOST = 'https://api.ucloud.cn'
def initialize(public_key, private_key)
@xiaohui-zhangxh
xiaohui-zhangxh / capybara.md
Created November 25, 2019 16:05 — forked from steveclarke/capybara.md
RSpec Matchers
View capybara.md

Capybara

save_and_open_page

Matchers

have_button(locator)
@xiaohui-zhangxh
xiaohui-zhangxh / README.md
Created November 1, 2018 02:07 — forked from lgersman/README.md
improved state diagram editor based on https://gist.github.com/lgersman/5311202 featuring curvy connections with helper points
View README.md

new features

  • css improved
  • css transitions added

nodes

  • double click on a node to remove it
@xiaohui-zhangxh
xiaohui-zhangxh / dnspod_api.rb
Last active March 15, 2020 15:28
通过 QCloud/DnsPod API 动态更新域名解析
View dnspod_api.rb
# frozen_string_literal: true
require 'json'
require 'net/http'
class DnspodAPI
API_HOST = 'https://dnsapi.cn'
# API requires UserAgent contains app name/version and email
def initialize(token, app_name:, app_version:, email:)
@xiaohui-zhangxh
xiaohui-zhangxh / config.ru
Created June 4, 2018 02:25 — forked from cmer/config.ru
Gem In a Box basic authentication & authorization rackup file
View config.ru
#
# This is a simple rackup file for geminabox. It allows simple role-based authorization.
#
# roles:
# - developer
# - upload
# - delete
# - admin (can do anything)
#
# For example, a developer who can access the service and upload new gems would have the following roles: `%w(developer upload)
View tmux_cheatsheet.markdown

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

View ups_monitor.sh
#!/bin/bash
PING_COUNT=10
INFO_LOG=/var/log/ups_monitor.log
ERROR_LOG=/var/log/ups_monitor.err
STATUS_LOG=/tmp/ups_monitor.log
SHUTDOWN_LOG=/var/log/ups_monitor_shutdown.log
LOCKER=/tmp/ups_monitor.lock
SHUTDOWN_COUNTER=5
View multimodule_assets.rb
load 'deploy' unless defined?(_cset)
_cset :asset_env, "RAILS_GROUPS=assets"
_cset :assets_prefix, "assets"
_cset :assets_role, [:web]
_cset :normalize_asset_timestamps, false
before 'deploy:finalize_update', 'deploy:mm_assets:symlink'
after 'deploy:update_code', 'deploy:mm_assets:precompile'