Get it from the App Store.
In XCode's Preferences > Downloads you can install command line tools.
require "open-uri" | |
require 'tempfile' | |
def image_from_url(url) | |
ext = File.extname(url) | |
filename = File.basename(url, ext) | |
temp = Tempfile.new([filename, ext]) | |
str = open(url).read | |
temp.write(str) |
set :rails_env, :production | |
set :unicorn_binary, "/usr/bin/unicorn" | |
# NOTICE: 不可在此外部使用 current_path,否则将会使用固定此文件下的 deploy_to 或默认的 deploy_to | |
# set :unicorn_config, "#{current_path}/config/unicorn.rb" | |
# set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid" | |
namespace :deploy do | |
task :start, :roles => :app, :except => { :no_release => true } do | |
unicorn_config = "#{current_path}/config/unicorn.rb" | |
unicorn_pid = "#{current_path}/tmp/pids/unicorn.pid" |
batch = [{:name => "mongodb"}, {:name => "mongoid"}] | |
Article.collection.insert(batch) | |
# my example | |
batch = [{ :name => '最高权限管理员', :level => DbRole::SuperAdmin }, { :name => '内容管理员', :level => DbRole::ContentAdmin }, { :name => '普通用户', :level => DbRole::NormalUser }] | |
DbRole.collection.insert(batch) |
# css|js|ico|gif|jpg|jpeg|png|txt|html|htm|xml|swf|wav这些都是静态文件,但应分辨,js、css可能经常会变,过期时间应小一些,图片、html基本不变,过期时间可以设长一些 | |
location ~* ^.+\.(gif|jpg|jpeg|png|txt|html)$ { | |
root /www/data/project/current/public; | |
access_log off; | |
expires 30d; | |
} |
class PictureFile < ActiveRecord::Base | |
attr_accessor :delete_file | |
after_destroy do |picture_file| | |
picture_file.delete_file = picture_file.filepath | |
end | |
after_commit do |picture_file| | |
if picture_file.delete_file && File.exist?(picture_file.delete_file) | |
File.delete(picture_file.delete_file) |
Some brief instructions on how to use Sprocket 2 in Rails to get CoffeeScript | |
powered JS and SASS powered CSS with YUI compression all via the magic of rack. | |
This stuff will be native in Rails 3.1 and the layout of the files on the | |
filesystem will be different but this guide will get you working with it | |
while we wait for all that to finalize. | |
Ignore the number prefixes on each file. This is just to ensure proper order in the Gist. | |
It's based on eric1234 gist https://gist.github.com/911003. ijust made it 3.1 compliant in terms of convention |
# reference: | |
# - https://github.com/nov/fb_graph | |
# - https://gist.github.com/752914 | |
# - http://developers.facebook.com/docs/reference/fql/ | |
# - http://stackoverflow.com/questions/7352296/facebook-fql-search-page-with-strpos-doesnt-work | |
require 'fb_graph' | |
user_access_token = 'USER_ACCESS_TOKEN' | |
fb_user = FbGraph::User.me(user_access_token) | |
FbGraph::Query.new("SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND strpos(lower(name),'hen') > 0").fetch(user_access_token) |
// 测试: | |
// http://localhost:8888/?short_url=http://t.cn/zjUg9kQ(正确解析) | |
// http://localhost:8888/?short_url=http://t.cn/zj4SIjW (有https请求,会报错) | |
var http = require('http'); | |
var url = require('url'); | |
function myParse(short_url, callback){ | |
var result = ''; | |
try{ |
# first scheme | |
before_filter :default_format_xml | |
# Set format to xml unless client requires a specific format | |
# Works on Rails 3.0.9 | |
def default_format_xml | |
request.format = "xml" unless params[:format] | |
end | |
# second scheme |