This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
txt.size | |
=> 99607 | |
puts txt | |
<html> | |
<head> | |
<title>ocr</title> | |
<link rel="stylesheet" type="text/css" href="../style.css"> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connection = Faraday::Connection.new('http://example.com') do |builder| | |
builder.request :url_encoded # for POST/PUT params | |
builder.adapter :net_http | |
end | |
# same as above, short form: | |
connection = Faraday.new 'http://example.com' | |
# GET | |
connection.get '/posts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'http://ruby.taobao.org' | |
gem 'sinatra', :require => 'sinatra/base' | |
gem 'sinatra-reloader', :require => 'sinatra/reloader' | |
gem 'oauth2' | |
gem 'thin' | |
gem 'rake' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Amadeusz Juskowiak <amadeusz@amanointeractive.com> 2012 - MIT License | |
# 1. Put inside helpers do .. end | |
# 2. Set CACHE_DIR to somewhere writable and private (like CACHE_DIR=File.dirname(__FILE__) + '/tmp' | |
# 3. Use it! You can use fragment_expire to remove cache with given name. | |
# | |
# Example: | |
# %h1 foo | |
# = cache_fragment(:report, 300) do | |
# - data = get_data_slowly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
class CacheHelper | |
module Sinatra | |
module Helpers | |
def cache(name, options = {}, &block) | |
if cache = read_fragment(name, options) | |
@_out_buf << cache | |
else | |
pos = @_out_buf.length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
require 'memcached' | |
module Sinatra | |
module Memcacher | |
module Helpers | |
def cache(key, &block) | |
return block.call unless options.memcacher_enabled | |
begin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def resize_and_crop(image, size) | |
if image.width < image.height | |
remove = ((image.height - image.width)/2).round | |
image.shave("0x#{remove}") | |
elsif image.width > image.height | |
remove = ((image.width - image.height)/2).round | |
image.shave("#{remove}x0") | |
end | |
image.resize("#{size}x#{size}") | |
return image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def crop_image_fixed_size(file, file_width, file_height) | |
begin | |
image = MiniMagick::Image.new(file) | |
original_width,original_height = image[:width],image[:height] | |
if original_width*file_height != original_height*file_width | |
if original_width*file_height >= original_height*file_width | |
original_height_clone = original_height | |
original_width_clone = original_height_clone * (file_width.to_f / file_height) | |
elsif original_width*file_height <= original_height * file_width | |
original_width_clone = original_width |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mini_magick 裁切正方形图片 sinatra | |
def crop_thumb_image(file) | |
begin | |
image = MiniMagick::Image.new(file) | |
image_width,image_height = image[:width],image[:height] | |
if image_width > image_height | |
shaved = (image_width-image_height).abs / 2 | |
image.shave("#{shaved}x0") | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# categorization.rb | |
class Categorization < ActiveRecord::Base | |
attr_accessible :category_id, :post_id | |
belongs_to :category | |
belongs_to :post | |
end | |
# category.rb |