This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You can enable this feature by: LOGGER=crazy rails s | |
# File : config/initializers/logger.rb | |
if ENV["LOGGER"] == "crazy" | |
class ActiveSupport::Logger::SimpleFormatter | |
def call(severity, time, progname, msg) | |
"#{severity} #{time}: #{progname} #{caller.grep(/phoenix/)} -- : #{msg}\n" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if has("mac") | |
let g:ctrlp_user_command = 'gfind %s -type f' | |
" Sane Ignore For ctrlp | |
endif | |
if exists("g:ctrlp_user_command") | |
unlet g:ctrlp_user_command | |
endif | |
set wildignore+=*\\vendor\\** | |
set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux | |
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe " Windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def longest_common_substr(strings) | |
shortest = strings.min_by &:length | |
maxlen = shortest.length | |
maxlen.downto(0) do |len| | |
0.upto(maxlen - len) do |start| | |
substr = shortest[start,len] | |
return substr if strings.all?{|str| str.include? substr } | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def black; "\e[30m#{self}\e[0m" end | |
def red; "\e[31m#{self}\e[0m" end | |
def green; "\e[32m#{self}\e[0m" end | |
def brown; "\e[33m#{self}\e[0m" end | |
def blue; "\e[34m#{self}\e[0m" end | |
def magenta;"\e[35m#{self}\e[0m" end | |
def cyan; "\e[36m#{self}\e[0m" end | |
def gray; "\e[37m#{self}\e[0m" end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Entities::Admin | |
class OptionType < Grape::Entity | |
expose :id, documentation: {type: String, desc: 'ID'} | |
expose :name, documentation: {type: String, desc: '商品属性名称'} | |
expose :group_name, documentation: {type: String, desc: '属性群名称'} | |
expose :required, documentation: {type: Boolean, desc: '是否必填'} | |
expose :position, documentation: {type: Boolean, desc: '排序号'} | |
expose :phone_category_id, documentation: {type: String, desc: '商品类别ID'}, if: { type: :full } | |
expose :values, documentation: {type: String, desc: '商品属性值'}, if: { type: :full } | |
expose :category_names, documentation: {type: String, desc: '商品属性值'}, if: { type: :full } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Grape::Entity.format_with :utc do |date| | |
date.strftime('%Y年%m月%d日 %H:%M') if date | |
end | |
Grape::Entity.format_with :date do |date| | |
date.strftime('%Y年%m月%d日') if date | |
end | |
Grape::Entity.format_with :datetime do |date| | |
date.strftime('%Y年%m月%d日 %H:%M:%S') if date | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'get Models'do | |
headers "Authentication-Token"=>{description: 'token',required: true } | |
end | |
get 'all_models' do | |
Rails.application.eager_load! if Rails.env.development? | |
models = Mongoid::Config.models | |
#fields.values.map{|f| o = f.options;{name: f.name,type: o[:type], kclass: o[:klass].to_s }} | |
present :models, models.map{|m|{model_name: m.to_s, relations: m.relations, field_names: m.fields.keys, fields: m.fields.values.map{|f| o = f.options;{name: f.name,type: o[:type].to_s, kclass: o[:klass].to_s }}}} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
utf8_msg = msg.dup.force_encoding(Encoding::GBK).encode('utf-8') # GBK to UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddPgTrgmExtensionToDb < ActiveRecord::Migration[5.0] | |
# def change | |
# # execute "remove extension pg_trgm;" | |
# execute "create extension IF NOT EXISTS pg_trgm;" | |
# execute "CREATE EXTENSION IF NOT EXISTS btree_gin;" | |
# | |
# remove_index :words, :word | |
# add_index :words, :word, using: :btree_gin | |
# end | |
def up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select OuterWrap.* | |
from ( | |
SELECT ROWNUM as AfterOrderRowNum, Wrap.* | |
FROM ( | |
SELECT "RechargeOrder"."CREATE_TIME" AS "RechargeOrder_CREATE_TIME" , | |
ROWNUM AS "BeforeOrderRowNum" | |
FROM "T_RECHARGE_ORDER" "RechargeOrder" | |
ORDER BY "RechargeOrder"."CREATE_TIME" DESC | |
) Wrap |
OlderNewer