This file contains hidden or 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
["橙子", "小蜜蜂", "旅行德意义", "琳子想要跑着玩", "June", "闻香识你", "李晨曦", "浪迹", "宋先森", "Rachael", "MrZhang", "di请你吃小火锅", "二毛", "Brey陌上花开", "白白vip001", "凤凰大掌柜", "午后时光", "西西风情驿站"] |
This file contains hidden or 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
a = ["广州","长沙","福州","北京","南京","厦门","南昌","西安","武汉","天津","太原","沈阳","大连","长春","哈尔滨","上海","杭州","宁波","合肥","济南","青岛","郑州","深圳","南宁","海口","重庆","成都","贵阳","乌鲁木齐","香港","台北","三亚","丽江","拉萨","桂林"] | |
total_count = [] | |
a.each do |c| | |
u = User.within_circle('location.loc' => City.where(name_chn: c).first.to_a).desc(:referring_count).first | |
total_count << { city: c, nickname: u.nickname, count: u.referring_count } | |
end | |
a = [] | |
total_count.each do |u| | |
user = User.where(nickname: u[:nickname]).first |
This file contains hidden or 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
l=Leaderboard.find('530fe34025d9803aa5001a68') | |
l.users.each do |uid, u| | |
user = {} | |
referring = {} | |
user[:nickname] = u[:nickname] | |
user[:avatar_url] = User.find(uid).avatar.url('58x58') | |
user[:city] = u[:city] | |
user[:referred_at] = u[:referred_at] | |
u[:referring].each do |k, v| |
This file contains hidden or 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
a = ["哈尔滨","广州", "拉萨", "天津", "成都", "郑州", "沈阳", "宁波"] | |
b = [] | |
cities = City.where(:name_chn.in => a).each do |c| | |
hash = {} | |
user = User.within_circle('location.loc' => c.to_a).desc(:referring_count).first | |
if user.nil? | |
hash[:error] = nil | |
b << hash | |
return | |
end |
This file contains hidden or 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
data = [] | |
a = ["橙子","1circle","jensen鑫","柏图卡","琳子想要跑着玩","老猴走四方","神叨M","June","田田兔","di请你吃小火锅","小蜜蜂","陈麒元","李晨曦","闻香识你","lemon","大坤儿","星子来啦","Rachael","汤团","天臣","二毛","朵miao喵","Brey陌上花开","大草原MemoShen","白白vip001","木子"] | |
users = User.in(nickname: a) | |
users.each do |u| | |
hash = {} | |
count = 0 | |
u.referring.each do |r| | |
if r.created_at >= "2014-03-08 00:00:00" && r.created_at <= "2014-03-31 23:59:59" | |
if r.avatar? && r.verifies_count > 0 | |
if r.referrer_id.to_s != r.id.to_s |
This file contains hidden or 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
String to Boolean in Ruby | |
When parsing data you may end up with string representations of various data types. For example, Boolean value might be represented as "true", "t", "yes", "y" or "1". | |
In order to resolve that problem with Ruby I chosed to do a quick hack. The following code adds new behaviour to String class. Such approach is called Monkey Patching. It should be used with caution as it can result in hard to track down errors. | |
class String | |
def to_bool | |
return true if self =~ (/^(true|t|yes|y|1)$/i) | |
return false if self.empty? || self =~ (/^(false|f|no|n|0)$/i) |
This file contains hidden or 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 cp_files | |
dirs=Dir.glob('/home/ubuntu/shou65/public/uploads/media/*') | |
dirs.each do |dir| | |
src_dir = dir.split("/").last | |
mv_base_dir = "/data/tmp/uploads/media/#{src_dir}" | |
Dir.mkdir(mv_base_dir) unless Dir.exist?(mv_base_dir) | |
Dir.glob("#{dir}/*").each do |file| | |
FileUtils.cp file, mv_base_dir | |
end | |
end |
This file contains hidden or 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
photo_size = 0 | |
dirs = Dir.glob('/home/star/Documents/shou65/public/uploads/*') | |
f = File.new('/home/star/public/photo.rb', 'w') | |
Dir.glob("#{dirs.first}/*/*").each do |i| | |
unless i.include?('_') | |
f.puts "#{i} -> #{f.size}" | |
photo_size += f.size | |
end | |
end | |
f.puts "total_size => #{photo_size}" |
This file contains hidden or 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
Dir.glob("/home/ubuntu/cities/*").each do |f| | |
city_id = File.basename(f, ".png") | |
c = City.find_by_id(city_id) | |
if c.nil? | |
puts "-"*80 | |
puts city_id | |
puts "-"*80 | |
else | |
if c.cover.nil? | |
c.create_cover(image: File.open(f)) if c.cover.try(:image).nil? |
This file contains hidden or 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
users = User.where(:nickname.in => ["橙子","柏图卡","1circle","jensen鑫","老猴走四方","琳子想要跑着玩","神叨M"]) | |
a = [] | |
users.each do |user| | |
b = 0 | |
user.referring.each do |r| | |
if ("2014-01-01 00:00:00".to_datetime.."2014-01-31 23:59:59".to_datetime).cover?(r.created_at) | |
if r.referred? | |
b += 1 | |
end | |
end |