Skip to content

Instantly share code, notes, and snippets.

View 3014zhangshuo's full-sized avatar
🎯
Coding

张硕 3014zhangshuo

🎯
Coding
View GitHub Profile
@3014zhangshuo
3014zhangshuo / rubocop.yml
Created October 30, 2019 03:18
my rubocop config
AllCops:
Exclude:
- db/schema.rb
Style/Documentation:
Description: 'Missing top-level class documentation comment.'
Enabled: false
# confict IfUnlessModifier https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/IfUnlessModifier
Style/GuardClause:
const wechatBrowser = () => {
return navigator.userAgent.toLowerCase().includes('micromessenger')
}
export { wechatBrowser }
@3014zhangshuo
3014zhangshuo / rails_webpacker_bootstrap_expose_jquery.md
Created September 26, 2019 04:51 — forked from andyyou/rails_webpacker_bootstrap_expose_jquery.md
Rails 5.2 with webpacker, bootstrap, stimulus starter

Rails 5.2 with webpacker, bootstrap, stimulus starter

This gist will collects all issues we solved with Rails 5.2 and Webpacker

Create Project

# Last few parameters(--skip-* part) is only my habbit not actully required
$ rails new <project_name> --webpack=stimulus --database=postgresql --skip-coffee --skip-test
@3014zhangshuo
3014zhangshuo / arel_any_predicate.rb
Created September 20, 2019 12:26 — forked from annikoff/arel_any_predicate.rb
An example of how to add a custom predicate to Arel
module Arel::Predications
def any(right)
Arel::Nodes::Any.new(self, quoted_node(right))
end
end
class Arel::Nodes::Any < Arel::Nodes::Binary
def operator
:'ANY'
end
@3014zhangshuo
3014zhangshuo / arel.rb
Created September 20, 2019 12:24 — forked from iloveivyxuan/arel.rb
Define Area Nodes -- Add a contain operator to Arel Nodes
# app/config/initializers/arel.rb
require 'arel/nodes/binary'
require 'arel/predications'
require 'arel/visitors/postgresql'
module Arel
class Nodes::ContainsArray < Arel::Nodes::Binary
def operator
:"@>"
@3014zhangshuo
3014zhangshuo / 01_Annotated_Source.md
Created September 20, 2019 12:21 — forked from alassek/01_Annotated_Source.md
Extending Arel to support @> operator

I've been doing some work lately with JSON documents in PostgreSQL using jsonb columns. You can query these documents using a GIN index in PG, but the syntax can be a little cumbersome

SELECT "events".* FROM "events" WHERE "events"."body" @> '{"shift":{"user_id":2}}'

You have to construct the right side of the query as a JSON string, which is a bit annoying. So I wondered if I could adapt Arel to do the tedious stuff for me.

@3014zhangshuo
3014zhangshuo / event_sourcing_intro.rb
Created September 4, 2019 13:38 — forked from mottalrd/event_sourcing_intro.rb
An introduction to event sourcing, London Ruby User Group, 9th May 2018
module Commands
module Meeting
AcceptSchema = Dry::Validation.Schema do
required(:user_id).filled
required(:status).value(eql?: :scheduled)
end
class Accept < Command
def call
return validate if validate.failure?
@3014zhangshuo
3014zhangshuo / nginx.conf
Created May 13, 2019 07:44
nginx puma websocket config
upstream rails_servers {
server unix:///opt/app/www.yoursite.com/shared/sockets/puma.sock fail_timeout=0;
}
server {
server_name www.yoursite.com;
location /cable {
proxy_redirect off;
proxy_set_header Host $host;
@3014zhangshuo
3014zhangshuo / command
Created May 13, 2019 07:13
puma config
bundle exec puma start -C config/puma.rb