Skip to content

Instantly share code, notes, and snippets.

@mimosz
mimosz / gist:4058187
Created November 12, 2012 08:39
销售统计
user = User.all[1]
date = '2012-11-11'.to_date
range = date.beginning_of_day..date.end_of_day
trades = user.trades.where(created: range).sales.sold.norefund
trades = trades.only(:payment, :num)
payment = 0
num = 0
nulls = []
trades.each do |trade|
if trade.payment && trade.num
@mimosz
mimosz / gist:4053835
Created November 11, 2012 05:32
买家购买金额
user = User.all[1]
date = '2012-11-11'.to_date
range = date.beginning_of_day..Time.parse('2012-11-11 11:00') # date.end_of_day
buyers = {}
user.trades.where(created: range, :pay_time.ne => nil).each do |trade|
buyers[trade.buyer_nick] = { city: trade.receiver_city, payment: 0, items: [] } unless buyers.has_key?(trade.buyer_nick)
buyer = buyers[trade.buyer_nick]
trade.orders.each do |order|
buyer[:payment] += order.payment
buyer[:items] << order.num_iid
@mimosz
mimosz / gist:4052924
Created November 10, 2012 23:16
催付
user = User.all[1]
date = '2012-11-11'.to_date
range = date.beginning_of_day..date.end_of_day
trades = user.trades.where(created: range, status: 'WAIT_BUYER_PAY')
CSV.open("#{date.to_s}-trades.csv", "wb:GB18030", col_sep: ',') do |csv|
trades.each do |trade|
row = [
trade.tid,
trade.payment,
trade.buyer_nick,
@mimosz
mimosz / gist:4052906
Created November 10, 2012 23:12
用户购买宝贝列表
user = User.all[1]
date = '2012-11-11'.to_date
range = date.beginning_of_day..date.end_of_day
trades = user.trades.where(created: range, status: 'WAIT_SELLER_SEND_GOODS')
buyers = {}
trades.each do |trade|
buyers[trade.buyer_nick] = {} unless buyers.has_key?(trade.buyer_nick)
buyer = buyers[trade.buyer_nick]
trade.orders.each do |order|
buyer[order.num_iid] = {} unless buyer.has_key?(order.num_iid)
urls = ['http://adidas.tmall.com', 'http://asics.tmall.com', 'http://vans.tmall.com', 'http://skomart.tmall.com', 'http://lining.tmall.com']
urls.each do |url|
Seller.sync(url)
end
urls = ['http://mentholatum.tmall.com', 'http://marubi.tmall.com', 'http://loreal.tmall.com', 'http://olay.tmall.com', 'http://nivea.tmall.com', 'http://xybc.tmall.com']
urls.each do |url|
Seller.sync(url)
end
urls = ['http://jinliufu.tmall.com', 'http://jiuxian.tmall.com', 'http://jiujiajiu.tmall.com', 'http://gjwjl.tmall.com', 'http://yanghe.tmall.com', 'http://guoyujl.tmall.com', 'http://sutanjl.tmall.com']
urls.each do |url|
@mimosz
mimosz / gist:3986967
Created October 31, 2012 13:15
淘宝,批量发优惠券
<!DOCTYPE>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form action="https://login.taobao.com/member/login.jhtml" method="post" accept-charset="GBK" target="_blank">
<input type="text" name="TPL_username">
<input type="password" name="TPL_password" >
<input type="hidden" name="action" value="Authenticator">
@mimosz
mimosz / gist:3968658
Created October 28, 2012 13:54
system info
def self.get()
@diskinfo = `df | grep rootfs | awk '{print $2,$4,$5}'`
@diskinfo = @diskinfo.split(' ')
@diskinfo_size = (@diskinfo[0].to_f / 1024 / 1024).round(2)
@diskinfo_free = (@diskinfo[1].to_f / 1024 / 1024).round(2)
@diskinfo_perc = @diskinfo[2].sub('%','')
@cpu_perc = `vmstat | awk '{print $13}'`.split("\n").last
@mem = `cat /proc/meminfo | grep Mem | awk '{print $2}'`
@mimosz
mimosz / .gitignore
Last active October 14, 2022 04:28
京东商品价格解析
.DS_Store
@mimosz
mimosz / send_csv.rb
Created October 11, 2012 09:54
通过CSV群发短信~
# -*- encoding: utf-8 -*-
require 'csv'
require 'smsbao'
class SendCsv < Smsbao
def initialize(login, passwd)
@smser = Smsbao.new(login, passwd)
end
def import(csv_file, col_sep=',') # MAC下为;
@mimosz
mimosz / gist:3751211
Created September 19, 2012 18:10
Joystick Controller
// 模拟
const byte PIN_ANALOG_X = A0;
const byte PIN_ANALOG_Y = A1;
// 数字
const byte PIN_ANALOG_K = 0;
// X中轴,区间值 [515..518]
const int X_THRESHOLD_LOW = 515;
const int X_THRESHOLD_HIGH = 518;
// Y中轴,区间值 [518..520]
const int Y_THRESHOLD_LOW = 518;