Skip to content

Instantly share code, notes, and snippets.

View mimosa's full-sized avatar
🏔️

Howl王 mimosa

🏔️
View GitHub Profile
@mimosa
mimosa / multi_part.rb
Created July 19, 2013 05:52
```ruby multi_part = nil File.open('/Users/howl/Downloads/babyhead.gif', 'rb') { |photo| multi_part = Nestful::MultiPart.new 'https://open.t.qq.com/api/t/add', { content: 'helloworld', longitude: 113.421234, latitude: 22.354231, syncflag: 0, compatibleflag: 0, format: 'json', access_token: '9895a065c73a06a6d43d9491cc7cfea7', oauth_consumer_key: …
# -*- encoding: utf-8 -*-
require 'mime/types'
require 'nestful'
require 'uri'
module Nestful
class MultiPart
def initialize(url, parts, crlf = nil)
@crlf = crlf || "\r\n"
@mimosa
mimosa / nb.rb
Last active December 20, 2015 15:19
seller = User.all[11]
trades = seller.trades.where(:pay_time.ne => nil).only(:tid, :pay_time, :payment, :total_fee, 'orders.oid', 'orders.total_fee', 'orders.outer_sku_id', 'orders.num', 'orders.price')
require 'csv'
header_row = ['交易ID', '订单ID', 'SKU编码', '数量', '价格', '数量', '实付价', '支付时间']
CSV.open('tttttttt.csv', "wb:GB18030", col_sep: ',') do |csv|
csv << header_row
trades.each do |trade|
row = {}
puts "#{trade.payment} / #{trade.total_fee}"
@mimosa
mimosa / export_by_cities.rb
Last active January 2, 2016 04:29
按城市导出用户联系信息。
# -*- encoding: utf-8 -*-
require 'csv'
cities = {}
# 有联系方式的用户
users = User.any_of(:mobile.ne =>nil, :email.ne => nil).desc(:rank).only(:nickname, :name, :email, :mobile, :location)
# 指定城市
keys = "北京、天津、石家庄、太原、呼和浩特、沈阳、大连、长春、哈尔滨、上海、南京、杭州、宁波、合肥、福州、厦门、南昌、济南、青岛、郑州、武汉、长沙、广州、深圳、南宁、海口、重庆、成都、贵阳、昆明、西安、兰州、西宁、银川、乌鲁木齐"
users = users.in( 'location.city' => keys.split('、') )
# 构造
def leaderboards_check(board_id, top=3, num=5)
board = Leaderboard.find_by_id(board_id)
return false if board.nil?
user_ids = board.rank.members.reverse[0, top] # 排名
user_ids.each do |uid|
u = board.users[uid]
unless u.nil?
puts "#{uid}, #{u[:nickname]}, #{u[:city]}" # 推荐人
puts '_'*88
referring_ids = u[:referring].keys.sample(num) # 随机取下线ID
@mimosa
mimosa / coupon.md
Created March 16, 2014 15:42
红美店铺,优惠卷领取代码。
  • 领取链接填写规则:
<a href="javascript:onGetCoupon(8);">1100</a>
<a href="javascript:onGetCoupon(7);">510</a>
<a href="javascript:onGetCoupon(6);">300</a>
<a href="javascript:onGetCoupon(5);">99</a>
  • 代码+到页面最后。
@mimosa
mimosa / emoji.json
Last active August 29, 2015 13:57
表情库
[
{
"unicode": "😄",
"name": "smile",
"category": "people"
},
{
"unicode": "😃",
"name": "smiley",
"category": "people"
@mimosa
mimosa / README.md
Last active August 29, 2015 13:58
服务器监控
# 数组
req_list = %w( http://10.4.2.86:9292/sessions/new http://10.4.1.177:9292/sessions/new http://10.4.10.139:9292/sessions/new http://10.4.6.221:9292/sessions/new )

# 哈希
req_hash = {
  'task-server' => 'http://10.4.2.86:9292/sessions/new',
   'web-server' => 'http://10.4.10.139:9292/sessions/new',
   'app-server' => 'http://10.4.6.221:9292/sessions/new',
  'back-server' => 'http://10.4.1.177:9292/sessions/new',
@mimosa
mimosa / gist:11077136
Created April 19, 2014 07:44
发送邀请码。
# user_id = '522d3cf8a57cbb890f000005'
# send_invites(user_id, secret: 'android', desc: '郑州见面会专用。', welcome: '感谢您使用收留我App。')
# send_invites(user_id, { secret: 'android', limit: 50 }, 2)
def send_invites(user_id, opts={}, num=1)
u = User.find(user_id)
return false if u.nil?
opts.symbolize_keys!
return false if opts[:secret].nil?
1.upto(num) { |i|
u.invites.create(
@mimosa
mimosa / README.rb
Last active August 29, 2015 14:00
新京东爬虫
# -*- encoding: utf-8 -*-
require './jd'
url = 'http://search.jd.com/search?keyword=%E5%B7%B4%E9%BB%8E%E6%AC%A7%E8%8E%B1%E9%9B%85&enc=utf-8&qr=&qrst=UNEXPAND&et=&rt=1&bs=no&stop=1&area=15&wtype=1&ev=&uc=0#select'
jd = JD.new(url)
items = jd.parse
require 'formula'
class Libxslt < Formula
homepage 'http://xmlsoft.org/XSLT/'
url 'ftp://xmlsoft.org/libxml2/libxslt-1.1.28.tar.gz'
mirror 'http://xmlsoft.org/sources/libxslt-1.1.28.tar.gz'
sha1 '4df177de629b2653db322bfb891afa3c0d1fa221'
keg_only :provided_by_osx