Skip to content

Instantly share code, notes, and snippets.

View songjiz's full-sized avatar
🧑‍💻

songji zeng songjiz

🧑‍💻
View GitHub Profile
@songjiz
songjiz / resque.rake
Last active August 29, 2015 14:23 — forked from denmarkin/resque.rake
# see http://stackoverflow.com/questions/5880962/how-to-destroy-jobs-enqueued-by-resque-workers - old version
# see https://github.com/defunkt/resque/issues/49
# see http://redis.io/commands - new commands
namespace :resque do
desc "Clear pending tasks"
task :clear => :environment do
queues = Resque.queues
queues.each do |queue_name|
puts "Clearing #{queue_name}..."
@songjiz
songjiz / install_arch.sh
Last active June 7, 2016 09:09
Install Arch linux
# Arch UEFI With USTC Mirror
# Use fdisk to create disk partitions
fdisk /dev/sdb
# sdb
# |-- sdb1 (as boot,EFI)
# |-- sdb2 (as root)
# |-- sdb3 (as home)
# Format
mkfs.vfat -F32 -n EFI /dev/sdb1
@songjiz
songjiz / mirrors
Last active October 18, 2015 11:34
ruby-build mirrors
# ruby-build 有时候在国内无法访问,可以修改其配置
# ~/.rbenv/plugins/ruby-build/share/ruby-build/2.2.3
# 修改对应的版本号中的配置,将链接改为淘宝的源就可以了
https://ruby.taobao.org/mirrors/ruby/
@songjiz
songjiz / rails http status codes
Created February 22, 2016 02:52 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@songjiz
songjiz / rails-jsonb-queries
Created March 7, 2019 05:32 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")

Implementing rich-text mentions with Action Text

  1. Mix ActionText::Attachable into your mentionable person model:

    class Person < ApplicationRecord
      include ActionText::Attachable
    
      # ...

end

Trix.config.textAttributes.red = {
style: { backgroundColor: "red" }
}
element.editor.activateAttribute("red")
// See available attribute options in:
// https://github.com/basecamp/trix/blob/master/src/trix/config/text_attributes.coffee
// https://github.com/basecamp/trix/blob/master/src/trix/config/block_attributes.coffee
@songjiz
songjiz / reset_password_support.rb
Last active April 13, 2020 14:35
stateless token base on ActiveSupport::MessageEncryptor
module ResetPasswordSupport
extend ActiveSupport::Concern
class ResetPasswordToken
include StatelessToken
def self.purpose
:reset_password
end
end