Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
jhjguxin / application.rb
Created September 14, 2012 03:08
rails IE, IFRAME, P3P, COOKIES
#userful gem [rack-p3p](https://github.com/hoopla/rack-p3p)
# [ie_iframe_cookies](https://github.com/grosser/ie_iframe_cookies)
# encoding: utf-8
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_p3p
def set_p3p
headers['P3P'] = "policyref=\"/w3c/p3p.xml\", CP=\"ALL DSP COR CURa ADMa DEVa TAIa OUR BUS IND UNI COM NAV INT\""
end
@jhjguxin
jhjguxin / notify.rb
Created September 19, 2012 10:24
mongo notifies demo base on bbtang.com
=begin
notify = {}
notify[:item_id][email protected]
notify[:item_type]='Note'
notify[:create_user_id] = message_box[sender_id]
notify[:event]='新站内信'
notify[:relate_user_id]=message_box[recipient_id]
notify[:read]= true || false
notify[:content][email protected]_s
notify[:content_path] = Time.now
@jhjguxin
jhjguxin / _form.html.erb
Created September 20, 2012 12:38
mongoid dynamic_fields demo base on bbtangcms(recommend_other depend on other_column)
<%= simple_form_for(@recommend_recommend_other, :html => {id: "recommend_recommend_other"}) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :_id, as: :hidden %>
<%= f.input :recommend_other_type, as: :select, collection: Recommend::OtherColumn.all.map(&:recommend_type) %>
<%# f.input :created_at %>
<%# f.input :updated_at %>
<% dynamic_feilds = @recommend_recommend_other.dynamic_attribute_names %>
<% if dynamic_feilds.present? %>
@jhjguxin
jhjguxin / deploy.rb
Created September 28, 2012 06:19 — forked from agaidot/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:create_symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
@jhjguxin
jhjguxin / auth_code.rb
Created October 10, 2012 09:22
sina authorize_url with with_offical_account params
Weibo2::Strategy::AuthCode.class_eval do
# place inside initializers
# The Authorization Code Strategy
# setting on yml
# with_offical_account: "1"
# @see http://tools.ietf.org/html/draft-ietf-oauth-v2-15#section-4.1
def authorize_url(params={})
params = {:redirect_uri => @client.redirect_uri}.merge(params)
params = params.merge({"with_offical_account" => with_offical_account}) if with_offical_account?
@jhjguxin
jhjguxin / intridea-omniauth.markdown
Created October 10, 2012 11:55
Separating Authentication and Identity with OmniAuth
@jhjguxin
jhjguxin / wordpress_octoptess_converter.rake
Created October 14, 2012 18:46
converter posts wordpress to octoptess by francis jiang
#http://www.germane-software.com/software/rexml/docs/tutorial.html
#this convter
require 'rexml/document'
require "date"
## -- Misc Configs -- ##
public_dir = "../public" # compiled site directory
source_dir = "../source" # source file directory
blog_index_dir = '../source' # directory for your blog's index page (if you put your index in source/blog/index.html, set this to 'source/blog')
@jhjguxin
jhjguxin / Gemfile
Created October 16, 2012 06:07
ResqueMailer and whenver base on BBTangCMS and large date export,witch alse a demo about mulit smtp account on rails
# Deploy with Capistrano
gem 'capistrano'
gem 'rvm-capistrano'
gem "resque", "~> 1.20.0"
gem "resque_mailer", "~> 2.1.0"
#Clean ruby syntax for writing and deploying cron jobs.
gem "whenever", "~> 0.7.3"
@jhjguxin
jhjguxin / goods.rake
Created October 17, 2012 04:59
rails csv file load rake demo
require 'csv'
#sources http://rake.rubyforge.org/doc/rakefile_rdoc.html
def load_data(param={})
file = param.delete(:file)
#file = "#{Rails.root}/tmp/goods/test.csv" unless file.present?
#csv = CSV.open(file)
#JSON.parse csv.to_json
file = "#{Rails.root}/#{file}" unless file.to_s.start_with? '/'
if File.exists? file
@jhjguxin
jhjguxin / fetch_ip.rb
Created October 18, 2012 06:23
ruby mail demo by andsen
#!/usr/bin/ruby
##ruby获得自己的外网IP地址
require "logger"
require 'open-uri'
require "mongo"
#require "net/smtp"
require "mail"
logger = Logger.new("ip.log", "monthly")
logger.level = Logger::DEBUG