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 / dynamic_cookie_store.rb
Created December 31, 2023 10:49
Make dymanic session store key for Rails on Multi-Tenant Arch
@xiaohui-zhangxh
xiaohui-zhangxh / application_controller.rb
Last active January 6, 2024 11:20
Make active_model_serializers render Pagy result as jsonapi response, with pagination meta and links
class Api::ApplicationController < ActionController::API
include Pagy::Backend
include PagyCollectionSerializer::ControllerMixin
end
@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
# 使用方法:
#
# 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
#!/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 管理资源
# 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

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

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 动态更新域名解析
# 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
#
# 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)

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name: