Skip to content

Instantly share code, notes, and snippets.

View 3014zhangshuo's full-sized avatar
🎯
Coding

张硕 3014zhangshuo

🎯
Coding
View GitHub Profile
@3014zhangshuo
3014zhangshuo / mysql_downgrade.txt
Created April 16, 2020 09:33 — forked from 6temes/mysql_downgrade.txt
Downgrade MySQL version with brew
# Kill rails server and guard
bin/spring stop
brew services stop mysql
brew uninstall mysql
brew install [email protected]
brew link [email protected] --force
brew services start [email protected]
rbenv uninstall 2.3.3
rbenv install 2.3.3
gem install bundle
@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 / curl.md
Created April 15, 2019 09:21 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@3014zhangshuo
3014zhangshuo / async-await.js
Created December 21, 2018 07:56 — forked from wesbos/async-await.js
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
@3014zhangshuo
3014zhangshuo / branch-count.sh
Created November 7, 2018 04:16 — forked from rwaldron/branch-count.sh
Count number of branches in a repo
git branch | wc -l