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
# encoding: utf-8 | |
module Setting | |
class << self | |
@@hashes = {} | |
# environments: development, test and production. | |
def environments() | |
%w[test production development] |
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 slug(length=10) | |
chars = ('A'..'Z').to_a + ('a'..'z').to_a + (0..9).to_a | |
chars.sample(length).join | |
end | |
#usage: | |
slug | |
=> "x5ZlWb4Ymf" | |
slug(6) |
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
require 'csv' | |
task :token do | |
require "./config/boot.rb" | |
res_file = File.new("db/token.txt","w+") # create res file | |
CSV.foreach("db/token.csv") do |row| | |
access_token = row.split(';')[0] # get first element | |
oauth_token = OauthToken.first(:access_token => access_token) | |
if oauth_token | |
client_id = oauth_token.client_id |
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
#encoding: utf-8 | |
# https://github.com/tomykaira/clockwork | |
# Usage: | |
# clockwork workers/clock_worker.rb & or | |
# clockworkd -c workers/clock_worker.rb run | |
require 'clockwork' | |
require File.expand_path('../../config/boot', __FILE__) | |
ENV['RACK_ENV'] = 'test' |
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
# encoding: utf-8 | |
require 'csv' | |
desc 'Get all user email' | |
task :send_coupon do | |
date = Time.now.strftime("%Y%m%d%H%M%S") | |
path = "tmp/send_coupon_emails_#{date}.csv" | |
CSV.open(path, "wb") do |csv| | |
header = ["email","created_at","survey_count","passport_id"] |
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
#flatten.uniq 去数组中的重复元素 | |
@my_orgunits = (current_user.orgunits + current_user.groups+ current_user.watch_open_groups).flatten.uniq | |
# use db | |
ActiveRecord::Base.connection.execute("use db") | |
# gsub | |
Mblog.find_each do |mblog| | |
unless mblog.content.nil? | |
mblog.content=mblog.content.gsub(/\[(\w+)\]/) do |c| |
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
attached: -> | |
$subQuestion = @$("input[name='question_ids[]']") | |
checkedLengh = @$("input[name='question_ids[]']:checked").length | |
allChecked = checkedLengh > 0 and $subQuestion.length is checkedLengh | |
@$(".question-check-all").prop("checked", allChecked) | |
checkAll: (e) -> | |
checkboxes = $('input[name="question_ids[]"]') | |
_.each checkboxes, (box) => |
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
comparator: (prev,next) -> | |
return 1 if prev.get('page_number') > next.get('page_number') | |
return -1 if prev.get('page_number') < next.get('page_number') | |
if prev.get('page_number') is next.get('page_number') | |
return prev.get('number') - next.get('number') | |
return 0 |
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
@keyframes spin { | |
0% { | |
transform:rotate(0deg); | |
} | |
100% { | |
transform:rotate(360deg); | |
} | |
} | |
.animate-spin { |
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
## Gem part | |
remove_file 'Gemfile' | |
run 'touch Gemfile' | |
add_source 'https://gems.ruby-china.org' | |
gem 'rails', '~> 5.0.0', '>= 5.0.0.1' | |
gem 'puma', '~> 3.0' | |
gem 'sass-rails', '~> 5.0' | |
gem 'uglifier', '>= 1.3.0' |