Skip to content

Instantly share code, notes, and snippets.

View mimosa's full-sized avatar
🏔️

Howl王 mimosa

🏔️
View GitHub Profile
@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
@mimosa
mimosa / voice.rb
Created May 7, 2014 10:08
语音验证码
gem 'cloopen_rest', github: '9577/cloopen_rest', require: false
# -*- encoding: utf-8 -*-
require 'cloopen_rest'
def auth
{
uid: 'aaf98fda45d5903f0145d5e642590064',
tid: 'f3cb84d5e3a74f2e82ab3bca39d3160a',
aid: 'aaf98fda45d5903f0145d5ecaace0077'
geocoder = Baidu::Geocoder.new

geocoder.lookup(ip: '221.131.192.80')

geocoder.lookup(address: '杭州长江南路336')

geocoder.lookup(lng: 120.208955, lat: 30.16512)
@mimosa
mimosa / gist:3ed7d3c72c166089f10e
Last active August 29, 2015 14:08
元编程,数据库多语言方案

新增方法

class ActiveRecord::Base
  def self.has_translation(*attributes)    
    attributes.each do |attribute|
      define_method "#{attribute}" do
        self.send "#{attribute}_#{I18n.locale.to_s.downcase.sub('-','_')}"
      end
 end
@mimosa
mimosa / activerecord_utils.rb
Last active August 29, 2015 14:10
MySQL 去重
# -*- encoding: utf-8 -*-
class ActiveRecord::Base
class << self
# 去重
def divorce_by(field_name, id = :id)
ids = twin_ids_by(field_name, id)
self.where(id: ids).delete_all unless ids.empty?
end
# 找出重复的 ids