Skip to content

Instantly share code, notes, and snippets.

# -*- encoding: utf-8 -*-
require 'typhoeus'
def hydra(concurrency=5)
@hydra ||= Typhoeus::Hydra.new(max_concurrency: concurrency)
end
def download(urls, concurrency=5)
urls.each_with_index do |url, idx|
request = Typhoeus::Request.new(url)
<% prop = @prop || @photo.face_prop %>
<% unless prop.blank? %>
<svg height='<%= @photo.img_height %>' width='<%= @photo.img_width %>' version='1.1'
xmlns='http://www.w3.org/2000/svg' xmlns:xlink= 'http://www.w3.org/1999/xlink'>
<style type='text/css'>
<![CDATA[
polyline {
fill: none;
stroke: #00C4FF;
stroke-opacity: 0.8;
@mimosa
mimosa / README.md
Last active November 28, 2015 11:45
YunPian + SendCloud
  • 模板创建:
  • 测试代码:
# 测试数据
def example
  {
    "[email protected]" => {
      user_id: 1,
      username: 'Mimosa',
@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 January 11, 2017 07:49
Rails + JWT
  • 使用前:
    • �使用�前
  • 使用后:
    • 正确回传:
    • 使用后
    • 验证 (客户端)
    • 验证成功
    • 提交错误:
    • 验证错误
gem 'faraday', require: false
gem 'typhoeus', require: 'typhoeus/adapters/faraday' # Faraday adapter
gem 'oj', require: false # MultiJson adapter
gem 'multi_json'
<a href="javascript:location.href=document.referrer;">支持 target=' _blank' </a>
<a href="javascript:history.back();">不支持</a>
@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' %>
@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 / 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