Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
jhjguxin / before-start.markdown
Created October 24, 2012 12:14
capistrano 2.x Multistage demo collected by francis

Capistrano's multistage extension provides an easy way to use a different deployment strategy for different scenarios. For instance, for your application, you might have two servers: one for production, where the "live" code is, and one for staging, where you can test features out without risk of affecting anything critical. Certain deployment values, such as the application name, UNIX user and group, and application environment might be the same, but other values might be different, such as the location of the server itself or the SCM repository branch.- Instead of repeating code in your Capfile, you can use multistage to set the values which are different in separate files, and only load those files at runtime.

This article will walk you through installing and using the multistage extension. We're going to use the example we mentioned earlier, where we have a production server and a staging server. So naturally, we would like two deployment stages, production and staging. We also assume you're

@jhjguxin
jhjguxin / count-down-javascript.html
Created October 25, 2012 03:15
倒计时demo time_count_down
<html>
<head>
<title>Rita's CountDown JavaScript</title>
</head>
<script language="JavaScript">
<!--
function countDown(year, month, day)
{
//Rita Garcia [email protected]
@jhjguxin
jhjguxin / oauth_worker.rb
Created October 31, 2012 09:49
oauth user stauts update with queue 微博队列发送机制 relation gist is gist: 3865157 , gist: 2934805
#lib/jobs/oauth_worker.rb
class OauthWorker
@queue = Rails.application.class.parent_name.downcase
def self.perform(param)
puts "get param[:auth_id]: #{param[:auth_id]}, param['auth_id']#{param['auth_id']}, param[:message]: #{param[:message]}, param['message']#{param['message']}"
auth_id = param.delete('auth_id')
auth = Authorization.find auth_id if auth_id.present? and Authorization.exists? auth_id
message = param.delete('message')
@jhjguxin
jhjguxin / _profile_edit_avatar.html.erb
Created November 6, 2012 10:06
the jQuery Validation demo, when image file upload
<div class="ps_ct_con" id = "profile_edit_avatar_<%= @profile.id%>" style=<%= (params[:action].eql? "edit_avatar") ? "display:block;" : "display:none;"%> >
<%= form_for @profile, :url => post_avatar_profiles_path, :method => :post, :html => { :multipart => true,:class => "upload_photos" } do |f| %>
<h3>让交流更真实</h3>
<div class="up_pt_info">
<div class="avatar_pic"> <%= image_tag get_face_url(@profile, :size => :s120), :size=>"132x132", :title=>"", :alt=>""%>
</div>
<div class="upload_info">
<p>从电脑中选择你喜欢的照片</p>
<p>你可以上传JPG、GIF、PNG、BMP图片文件,且文件小于2M</p>
<%= f.label "上传头像:" %>
@jhjguxin
jhjguxin / active_record_associations.rb
Created November 9, 2012 05:38 — forked from karmi/active_record_associations.rb
An example of elasticsearch & Tire setup for ActiveRecord associations
# An example of elasticsearch & Tire setup for ActiveRecord associations.
#
# A `Book has_many :chapters` scenario, with mapping and JSON serialization
# for indexing associated models.
#
# Demonstrates three important caveats as of now:
#
# 1. You you have to use `touch: true` in the `belongs_to` declaration,
# to automatically notify the parent model about the update.
#
@jhjguxin
jhjguxin / _sync_setting_form.html.erb
Created November 10, 2012 17:55
store the config as json data in db
<%= form_tag(update_sync_setting_profiles_path) do -%>
<%= hidden_field_tag 'authorization_id', authorization.id%>
<ul class="l_share_set">
<li><%= I18n.t("#{authorization.provider}")%>账号同步设置:</li>
<% {note: true, question: true, answer: true, quiz: true}.each do |k,v| %>
<li class="mt20">
<%= label_tag "authorization[sync_setting][#{k.to_s}]", I18n.t("sync_setting_hash.#{k}")%>
<%= hidden_field_tag "authorization[sync_setting][#{k.to_s}]", false%>
<%= check_box_tag "authorization[sync_setting][#{k.to_s}]", true , authorization.can_sync?(k)%>
@jhjguxin
jhjguxin / string_ext_lib.js
Created November 26, 2012 03:33
js字符串函数
/*JS自带函数
concat
将两个或多个字符的文本组合起来,返回一个新的字符串。
var a = "hello";
var b = ",world";
var c = a.concat(b);
alert(c);
//c = "hello,world"
indexOf
返回字符串中一个子串第一处出现的索引(从左到右搜索)。如果没有匹配项,返回 -1 。
@jhjguxin
jhjguxin / Gemfile
Created November 28, 2012 12:26
paperclip Cropper 一次性 传入Cropper相关参数 和文件来裁剪 Base on BBTang compatible with IE
gem "paperclip", "~> 3.0"
#http://stackoverflow.com/questions/12793158/paperclip-error-notidentifiedbyimagemagickerror
gem "cocaine", "= 0.3.2"
@jhjguxin
jhjguxin / extra_query.rake
Created December 6, 2012 09:50
extra_query base on BBTangCMS some sql and rake demo
include ActionView::Helpers::DateHelper
def notes_from_level(level_id = level_id)
level_id = level_id.to_i
if level_id.eql? 1
notes = (Profile.level(1) + Profile.level(nil)).collect{|p| ["#{p}",Note.where(created_by: p.user_id).count]}.delete_if{|item| item.last.eql? 0}
else
notes = Profile.level(level_id.to_i).collect{|p| ["#{p}",Note.where(created_by: p.user_id).count]}
end
end