Skip to content

Instantly share code, notes, and snippets.

View mimosa's full-sized avatar
🏔️

Howl王 mimosa

🏔️
View GitHub Profile
@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
@mimosa
mimosa / _filter_form.html.erb
Last active August 29, 2015 14:10
Rails View 中 多语言的实践。
<% # app/views/orders/_filter_form.html.erb %>
<%= t '.provider' %>
<%= t '.start_at' %>
<%= t '.end_at' %>
<%= t '.no' %>
<%= t '.mobile' %>
<a href="javascript:location.href=document.referrer;">支持 target=' _blank' </a>
<a href="javascript:history.back();">不支持</a>
gem 'faraday', require: false
gem 'typhoeus', require: 'typhoeus/adapters/faraday' # Faraday adapter
gem 'oj', require: false # MultiJson adapter
gem 'multi_json'
@mimosa
mimosa / README.md
Last active January 11, 2017 07:49
Rails + JWT
  • 使用前:
    • �使用�前
  • 使用后:
    • 正确回传:
    • 使用后
    • 验证 (客户端)
    • 验证成功
    • 提交错误:
    • 验证错误
@mimosa
mimosa / README.md
Last active November 4, 2015 07:48
Qiniu Ruby 视频转码
  1. 在七牛后台建立私有队列: 2015-11-04 3 01 53
  2. 如何使用七牛SDK这里跳过
  3. 通过七牛后台或任意方式上传原视频文件到前缀 origin/ 下。
  4. 通过提交 key 进行视频编码(详见 av.rb 代码)
prefix = 'origin/' # 前缀(可看做目录/路径)
resp = Qiniu::Fop::Av.convert_to(prefix + 'n03-0620.mp4')
resp = Qiniu::Fop::Av.convert_to(prefix + 'Robi_tw.mp4')
resp = Qiniu::Fop::Av.convert_to(prefix + 'Robi_vs_jp.mp4')
@mimosa
mimosa / README.md
Last active November 28, 2015 11:45
YunPian + SendCloud
  • 模板创建:
  • 测试代码:
# 测试数据
def example
  {
    "mimosa@aliyun.com" => {
      user_id: 1,
      username: 'Mimosa',